Skip to content

Commit

Permalink
Fix hotkey scope when opening command menu (twentyhq#8258)
Browse files Browse the repository at this point in the history
Fix hotkey scope when opening command menu
  • Loading branch information
bosiraphael authored Nov 1, 2024
1 parent a71a350 commit 234a5db
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { useActionMenu } from '@/action-menu/hooks/useActionMenu';
import { ActionMenuComponentInstanceContext } from '@/action-menu/states/contexts/ActionMenuComponentInstanceContext';
import { isCommandMenuOpenedState } from '@/command-menu/states/isCommandMenuOpenedState';
import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState';
import { isBottomBarOpenedComponentState } from '@/ui/layout/bottom-bar/states/isBottomBarOpenedComponentState';
import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2';
import { extractComponentState } from '@/ui/utilities/state/component-state/utils/extractComponentState';
import { useEffect } from 'react';
import { useRecoilValue } from 'recoil';
Expand All @@ -21,6 +23,13 @@ export const RecordIndexActionMenuEffect = () => {

const { openActionBar, closeActionBar } = useActionMenu(actionMenuId);

// Using closeActionBar here was causing a bug because it goes back to the
// previous hotkey scope, and we don't want that here.
const setIsBottomBarOpened = useSetRecoilComponentStateV2(
isBottomBarOpenedComponentState,
`action-bar-${actionMenuId}`,
);

const isDropdownOpen = useRecoilValue(
extractComponentState(
isDropdownOpenComponentState,
Expand Down Expand Up @@ -50,9 +59,9 @@ export const RecordIndexActionMenuEffect = () => {

useEffect(() => {
if (isRightDrawerOpen || isCommandMenuOpened) {
closeActionBar();
setIsBottomBarOpened(false);
}
}, [closeActionBar, isRightDrawerOpen, isCommandMenuOpened]);
}, [isRightDrawerOpen, isCommandMenuOpened, setIsBottomBarOpened]);

return null;
};

0 comments on commit 234a5db

Please sign in to comment.