The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Set hotkey scope when navigating in side panel's history (#12634)
Raphaël Bosiefe1700cc828
diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuHistory.ts b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuHistory.tsindex c9002abd744..7f5332c99bb 100644--- a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuHistory.ts+++ b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuHistory.ts@@ -6,12 +6,15 @@ import { commandMenuNavigationStackState } from '@/command-menu/states/commandMeimport { commandMenuPageInfoState } from '@/command-menu/states/commandMenuPageInfoState';import { commandMenuPageState } from '@/command-menu/states/commandMenuPageState';import { hasUserSelectedCommandState } from '@/command-menu/states/hasUserSelectedCommandState';+import { CommandMenuHotkeyScope } from '@/command-menu/types/CommandMenuHotkeyScope';import { getShowPageTabListComponentId } from '@/ui/layout/show-page/utils/getShowPageTabListComponentId';import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';+import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';import { isDefined } from 'twenty-shared/utils';export const useCommandMenuHistory = () => {const { closeCommandMenu } = useCommandMenu();+ const setHotkeyScope = useSetHotkeyScope();const goBackFromCommandMenu = useRecoilCallback(({ snapshot, set }) => {@@ -66,64 +69,78 @@ export const useCommandMenuHistory = () => {}set(hasUserSelectedCommandState, false);++ setHotkeyScope(CommandMenuHotkeyScope.CommandMenuFocused, {+ commandMenuOpen: true,+ });};},- [closeCommandMenu],+ [closeCommandMenu, setHotkeyScope],);- const navigateCommandMenuHistory = useRecoilCallback(({ snapshot, set }) => {- return (pageIndex: number) => {- const currentNavigationStack = snapshot- .getLoadable(commandMenuNavigationStackState)- .getValue();+ const navigateCommandMenuHistory = useRecoilCallback(+ ({ snapshot, set }) => {+ return (pageIndex: number) => {+ const currentNavigationStack = snapshot+ .getLoadable(commandMenuNavigationStackState)+ .getValue();- const newNavigationStack = currentNavigationStack.slice(0, pageIndex + 1);+ const newNavigationStack = currentNavigationStack.slice(+ 0,+ pageIndex + 1,+ );- set(commandMenuNavigationStackState, newNavigationStack);+ set(commandMenuNavigationStackState, newNavigationStack);- const newNavigationStackItem = newNavigationStack.at(-1);+ const newNavigationStackItem = newNavigationStack.at(-1);- if (!isDefined(newNavigationStackItem)) {- throw new Error(- `No command menu navigation stack item found for index ${pageIndex}`,- );- }-- set(commandMenuPageState, newNavigationStackItem.page);- set(commandMenuPageInfoState, {- title: newNavigationStackItem.pageTitle,- Icon: newNavigationStackItem.pageIcon,- instanceId: newNavigationStackItem.pageId,- });- const currentMorphItems = snapshot- .getLoadable(commandMenuNavigationMorphItemByPageState)- .getValue();-- for (const [pageId, morphItem] of currentMorphItems.entries()) {- if (!newNavigationStack.some((item) => item.pageId === pageId)) {- set(- activeTabIdComponentState.atomFamily({- instanceId: getShowPageTabListComponentId({- pageId,- targetObjectId: morphItem.recordId,- }),- }),- null,+ if (!isDefined(newNavigationStackItem)) {+ throw new Error(+ `No command menu navigation stack item found for index ${pageIndex}`,);}- }- const newMorphItems = new Map(- Array.from(currentMorphItems.entries()).filter(([pageId]) =>- newNavigationStack.some((item) => item.pageId === pageId),- ),- );+ set(commandMenuPageState, newNavigationStackItem.page);+ set(commandMenuPageInfoState, {+ title: newNavigationStackItem.pageTitle,+ Icon: newNavigationStackItem.pageIcon,+ instanceId: newNavigationStackItem.pageId,+ });+ const currentMorphItems = snapshot+ .getLoadable(commandMenuNavigationMorphItemByPageState)+ .getValue();++ for (const [pageId, morphItem] of currentMorphItems.entries()) {+ if (!newNavigationStack.some((item) => item.pageId === pageId)) {+ set(+ activeTabIdComponentState.atomFamily({+ instanceId: getShowPageTabListComponentId({+ pageId,+ targetObjectId: morphItem.recordId,+ }),+ }),+ null,+ );+ }+ }++ const newMorphItems = new Map(+ Array.from(currentMorphItems.entries()).filter(([pageId]) =>+ newNavigationStack.some((item) => item.pageId === pageId),+ ),+ );++ set(commandMenuNavigationMorphItemByPageState, newMorphItems);- set(commandMenuNavigationMorphItemByPageState, newMorphItems);+ set(hasUserSelectedCommandState, false);- set(hasUserSelectedCommandState, false);- };- }, []);+ setHotkeyScope(CommandMenuHotkeyScope.CommandMenuFocused, {+ commandMenuOpen: true,+ });+ };+ },+ [setHotkeyScope],+ );return {goBackFromCommandMenu,