-
Notifications
You must be signed in to change notification settings - Fork 90
feat(lightspeed): Add Escape key to cycle through display modes #2182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
its-mitesh-kumar
wants to merge
3
commits into
redhat-developer:main
Choose a base branch
from
its-mitesh-kumar:feat/lightspeed-escape-key-display-mode-cycling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+397
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@red-hat-developer-hub/backstage-plugin-lightspeed': patch | ||
| --- | ||
|
|
||
| Added Escape key support to cycle through display modes. Pressing Escape now transitions through Fullscreen → Docked → Overlay → Close. When the Display Mode settings dropdown is open, the first Escape closes the dropdown, and subsequent Escape presses cycle the display mode. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,8 @@ export const LightspeedDrawerProvider = ({ children }: PropsWithChildren) => { | |
| const [draftFileContents, setDraftFileContentsState] = useState< | ||
| FileContent[] | ||
| >([]); | ||
| const [isSettingsDropdownOpen, setIsSettingsDropdownOpen] = | ||
| useState<boolean>(false); | ||
| const openedViaFABRef = useRef<boolean>(false); | ||
|
|
||
| const isLightspeedRoute = location.pathname.startsWith('/lightspeed'); | ||
|
|
@@ -188,6 +190,57 @@ export const LightspeedDrawerProvider = ({ children }: PropsWithChildren) => { | |
| ], | ||
| ); | ||
|
|
||
| // Cycle display mode on Escape: Fullscreen → Docked → Overlay → Close | ||
| const cycleDisplayModeOnEscape = useCallback(() => { | ||
| switch (displayModeState) { | ||
| case ChatbotDisplayMode.embedded: // Fullscreen → Docked | ||
| setDisplayMode(ChatbotDisplayMode.docked); | ||
| break; | ||
| case ChatbotDisplayMode.docked: // Docked → Overlay | ||
| setDisplayMode(ChatbotDisplayMode.default); | ||
| break; | ||
| case ChatbotDisplayMode.default: // Overlay → Close | ||
| closeChatbot(); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| }, [displayModeState, setDisplayMode, closeChatbot]); | ||
|
|
||
| // Handle ChatbotModal close (overlay mode only) | ||
| // Only cycle display mode if no dropdown is open | ||
| const handleModalClose = useCallback(() => { | ||
| if (isSettingsDropdownOpen) { | ||
| // Settings dropdown is open, let it close first | ||
| // Don't cycle display mode on this Escape press | ||
| return; | ||
| } | ||
| cycleDisplayModeOnEscape(); | ||
| }, [isSettingsDropdownOpen, cycleDisplayModeOnEscape]); | ||
|
|
||
| // Global Escape key listener for display mode cycling | ||
| useEffect(() => { | ||
| const handleKeyDown = (event: KeyboardEvent) => { | ||
| if (event.key !== 'Escape' || !isOpen) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if any modal dialog is currently visible (Delete, Rename, etc.) | ||
| const hasOpenModal = document.querySelector('.MuiDialog-root'); | ||
|
|
||
| // If settings dropdown or modal is open, let those handle Escape first | ||
| if (isSettingsDropdownOpen || hasOpenModal) { | ||
| return; | ||
| } | ||
|
Comment on lines
+228
to
+234
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a brittle implementation and could break if MUI class names are changed or if we start using BUI instead of MUI. |
||
|
|
||
| event.preventDefault(); | ||
| cycleDisplayModeOnEscape(); | ||
| }; | ||
|
|
||
| document.addEventListener('keydown', handleKeyDown); | ||
| return () => document.removeEventListener('keydown', handleKeyDown); | ||
| }, [isOpen, isSettingsDropdownOpen, cycleDisplayModeOnEscape]); | ||
|
|
||
| // Only render ChatbotModal for overlay mode | ||
| // Docked mode is handled by ApplicationDrawer in Root | ||
| // Embedded mode is handled by LightspeedPage route | ||
|
|
@@ -210,6 +263,8 @@ export const LightspeedDrawerProvider = ({ children }: PropsWithChildren) => { | |
| setDraftMessage, | ||
| draftFileContents, | ||
| setDraftFileContents, | ||
| isSettingsDropdownOpen, | ||
| setIsSettingsDropdownOpen, | ||
| }), | ||
| [ | ||
| isOpen, | ||
|
|
@@ -224,6 +279,8 @@ export const LightspeedDrawerProvider = ({ children }: PropsWithChildren) => { | |
| setDraftMessage, | ||
| draftFileContents, | ||
| setDraftFileContents, | ||
| isSettingsDropdownOpen, | ||
| setIsSettingsDropdownOpen, | ||
| ], | ||
| ); | ||
|
|
||
|
|
@@ -234,7 +291,7 @@ export const LightspeedDrawerProvider = ({ children }: PropsWithChildren) => { | |
| <ChatbotModal | ||
| isOpen | ||
| displayMode={displayModeState} | ||
| onClose={closeChatbot} | ||
| onClose={handleModalClose} | ||
| ouiaId="LightspeedChatbotModal" | ||
| aria-labelledby="lightspeed-chatpopup-modal" | ||
| className={classes.chatbotModal} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to my previous comment.
Can you use similar approach to track if the rename/delete/attachment modals are open so that you can use that information to see if any modals are open, rather than relying on className
.MuiDialog-root?pseudo code:
Then context can expose method and properties like
openModal, closeModal, hasOpenModalsetc, so that you can use this to decide whether to perform any action or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above code can become complex, see my latest comment below, we dont need to maintain modalIds instead we can have a simple boolean to track if there any nestedModals Open and based on that we can avoid closing the main chatbot.