Set hotkey scope when navigating in side panel's history (#12634)
This PR fixes a bug where the side panel couldn't be closed after the execution of a workflow with a form. After the execution of the workflow, `goBackFromCommandMenu` is called to show the workflow run. The hotkey scope wasn't reset properly, and the click outside listener from the side panel is only triggered when the scope is `CommandMenuFocused`. This PR sets the hotkey scope to `CommandMenuFocused` when going back or when navigating inside the command menu history. Note: (we don't use `setHotkeyScopeAndMemorizePreviousScope` here because we don't need to memorize the active hotkey scope of the page we are leaving) Before: https://github.com/user-attachments/assets/09edf97b-7520-46ce-ade3-6bb6b15ef435 After: https://github.com/user-attachments/assets/16c288cb-1d42-4099-8925-74a673f7a479
This commit is contained in:
@ -6,12 +6,15 @@ import { commandMenuNavigationStackState } from '@/command-menu/states/commandMe
|
|||||||
import { commandMenuPageInfoState } from '@/command-menu/states/commandMenuPageInfoState';
|
import { commandMenuPageInfoState } from '@/command-menu/states/commandMenuPageInfoState';
|
||||||
import { commandMenuPageState } from '@/command-menu/states/commandMenuPageState';
|
import { commandMenuPageState } from '@/command-menu/states/commandMenuPageState';
|
||||||
import { hasUserSelectedCommandState } from '@/command-menu/states/hasUserSelectedCommandState';
|
import { hasUserSelectedCommandState } from '@/command-menu/states/hasUserSelectedCommandState';
|
||||||
|
import { CommandMenuHotkeyScope } from '@/command-menu/types/CommandMenuHotkeyScope';
|
||||||
import { getShowPageTabListComponentId } from '@/ui/layout/show-page/utils/getShowPageTabListComponentId';
|
import { getShowPageTabListComponentId } from '@/ui/layout/show-page/utils/getShowPageTabListComponentId';
|
||||||
import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';
|
import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';
|
||||||
|
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||||
import { isDefined } from 'twenty-shared/utils';
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
|
|
||||||
export const useCommandMenuHistory = () => {
|
export const useCommandMenuHistory = () => {
|
||||||
const { closeCommandMenu } = useCommandMenu();
|
const { closeCommandMenu } = useCommandMenu();
|
||||||
|
const setHotkeyScope = useSetHotkeyScope();
|
||||||
|
|
||||||
const goBackFromCommandMenu = useRecoilCallback(
|
const goBackFromCommandMenu = useRecoilCallback(
|
||||||
({ snapshot, set }) => {
|
({ snapshot, set }) => {
|
||||||
@ -66,18 +69,26 @@ export const useCommandMenuHistory = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set(hasUserSelectedCommandState, false);
|
set(hasUserSelectedCommandState, false);
|
||||||
|
|
||||||
|
setHotkeyScope(CommandMenuHotkeyScope.CommandMenuFocused, {
|
||||||
|
commandMenuOpen: true,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[closeCommandMenu],
|
[closeCommandMenu, setHotkeyScope],
|
||||||
);
|
);
|
||||||
|
|
||||||
const navigateCommandMenuHistory = useRecoilCallback(({ snapshot, set }) => {
|
const navigateCommandMenuHistory = useRecoilCallback(
|
||||||
|
({ snapshot, set }) => {
|
||||||
return (pageIndex: number) => {
|
return (pageIndex: number) => {
|
||||||
const currentNavigationStack = snapshot
|
const currentNavigationStack = snapshot
|
||||||
.getLoadable(commandMenuNavigationStackState)
|
.getLoadable(commandMenuNavigationStackState)
|
||||||
.getValue();
|
.getValue();
|
||||||
|
|
||||||
const newNavigationStack = currentNavigationStack.slice(0, pageIndex + 1);
|
const newNavigationStack = currentNavigationStack.slice(
|
||||||
|
0,
|
||||||
|
pageIndex + 1,
|
||||||
|
);
|
||||||
|
|
||||||
set(commandMenuNavigationStackState, newNavigationStack);
|
set(commandMenuNavigationStackState, newNavigationStack);
|
||||||
|
|
||||||
@ -122,8 +133,14 @@ export const useCommandMenuHistory = () => {
|
|||||||
set(commandMenuNavigationMorphItemByPageState, newMorphItems);
|
set(commandMenuNavigationMorphItemByPageState, newMorphItems);
|
||||||
|
|
||||||
set(hasUserSelectedCommandState, false);
|
set(hasUserSelectedCommandState, false);
|
||||||
|
|
||||||
|
setHotkeyScope(CommandMenuHotkeyScope.CommandMenuFocused, {
|
||||||
|
commandMenuOpen: true,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}, []);
|
},
|
||||||
|
[setHotkeyScope],
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
goBackFromCommandMenu,
|
goBackFromCommandMenu,
|
||||||
|
|||||||
Reference in New Issue
Block a user