From 352cf3d38e5dd8072465323617910dbf41195123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bosi?= <71827178+bosiraphael@users.noreply.github.com> Date: Fri, 28 Mar 2025 17:59:05 +0100 Subject: [PATCH] Update previousHotkeyScopeState to be a family state (#11270) Fixes #11259 --- ...useCommandMenuCloseAnimationCompleteCleanup.ts | 4 +++- .../command-menu/hooks/useNavigateCommandMenu.ts | 4 +++- .../constants/InlineCellHotkeyScopeMemoizeKey.ts | 1 + .../record-inline-cell/hooks/useInlineCell.ts | 5 +++-- .../hooks/useRecordTitleCell.tsx | 4 ++-- .../hotkey/hooks/usePreviousHotkeyScope.ts | 15 ++++++++------- .../internal/previousHotkeyScopeFamilyState.ts | 11 +++++++++++ .../states/internal/previousHotkeyScopeState.ts | 8 -------- 8 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 packages/twenty-front/src/modules/object-record/record-inline-cell/constants/InlineCellHotkeyScopeMemoizeKey.ts create mode 100644 packages/twenty-front/src/modules/ui/utilities/hotkey/states/internal/previousHotkeyScopeFamilyState.ts delete mode 100644 packages/twenty-front/src/modules/ui/utilities/hotkey/states/internal/previousHotkeyScopeState.ts diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuCloseAnimationCompleteCleanup.ts b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuCloseAnimationCompleteCleanup.ts index 66fe24d20..7c1e397c6 100644 --- a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuCloseAnimationCompleteCleanup.ts +++ b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuCloseAnimationCompleteCleanup.ts @@ -28,7 +28,9 @@ import { useRecoilCallback } from 'recoil'; export const useCommandMenuCloseAnimationCompleteCleanup = () => { const { resetSelectedItem } = useSelectableList('command-menu-list'); - const { goBackToPreviousHotkeyScope } = usePreviousHotkeyScope(); + const { goBackToPreviousHotkeyScope } = usePreviousHotkeyScope( + COMMAND_MENU_COMPONENT_INSTANCE_ID, + ); const { resetContextStoreStates } = useResetContextStoreStates(); diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useNavigateCommandMenu.ts b/packages/twenty-front/src/modules/command-menu/hooks/useNavigateCommandMenu.ts index 554e2e2f3..1253a1f45 100644 --- a/packages/twenty-front/src/modules/command-menu/hooks/useNavigateCommandMenu.ts +++ b/packages/twenty-front/src/modules/command-menu/hooks/useNavigateCommandMenu.ts @@ -27,7 +27,9 @@ export type CommandMenuNavigationStackItem = { }; export const useNavigateCommandMenu = () => { - const { setHotkeyScopeAndMemorizePreviousScope } = usePreviousHotkeyScope(); + const { setHotkeyScopeAndMemorizePreviousScope } = usePreviousHotkeyScope( + COMMAND_MENU_COMPONENT_INSTANCE_ID, + ); const { copyContextStoreStates } = useCopyContextStoreStates(); diff --git a/packages/twenty-front/src/modules/object-record/record-inline-cell/constants/InlineCellHotkeyScopeMemoizeKey.ts b/packages/twenty-front/src/modules/object-record/record-inline-cell/constants/InlineCellHotkeyScopeMemoizeKey.ts new file mode 100644 index 000000000..6aaed6c54 --- /dev/null +++ b/packages/twenty-front/src/modules/object-record/record-inline-cell/constants/InlineCellHotkeyScopeMemoizeKey.ts @@ -0,0 +1 @@ +export const INLINE_CELL_HOTKEY_SCOPE_MEMOIZE_KEY = 'inline-cell'; diff --git a/packages/twenty-front/src/modules/object-record/record-inline-cell/hooks/useInlineCell.ts b/packages/twenty-front/src/modules/object-record/record-inline-cell/hooks/useInlineCell.ts index 74884407b..5f18dfe60 100644 --- a/packages/twenty-front/src/modules/object-record/record-inline-cell/hooks/useInlineCell.ts +++ b/packages/twenty-front/src/modules/object-record/record-inline-cell/hooks/useInlineCell.ts @@ -7,13 +7,14 @@ import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousH import { useInitDraftValueV2 } from '@/object-record/record-field/hooks/useInitDraftValueV2'; import { RecordFieldComponentInstanceContext } from '@/object-record/record-field/states/contexts/RecordFieldComponentInstanceContext'; import { useRecordInlineCellContext } from '@/object-record/record-inline-cell/components/RecordInlineCellContext'; +import { INLINE_CELL_HOTKEY_SCOPE_MEMOIZE_KEY } from '@/object-record/record-inline-cell/constants/InlineCellHotkeyScopeMemoizeKey'; import { getDropdownFocusIdForRecordField } from '@/object-record/utils/getDropdownFocusIdForRecordField'; import { useGoBackToPreviousDropdownFocusId } from '@/ui/layout/dropdown/hooks/useGoBackToPreviousDropdownFocusId'; import { useSetActiveDropdownFocusIdAndMemorizePrevious } from '@/ui/layout/dropdown/hooks/useSetFocusedDropdownIdAndMemorizePrevious'; import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow'; +import { isDefined } from 'twenty-shared/utils'; import { isInlineCellInEditModeScopedState } from '../states/isInlineCellInEditModeScopedState'; import { InlineCellHotkeyScope } from '../types/InlineCellHotkeyScope'; -import { isDefined } from 'twenty-shared/utils'; export const useInlineCell = ( recordFieldComponentInstanceIdFromProps?: string, @@ -39,7 +40,7 @@ export const useInlineCell = ( const { setHotkeyScopeAndMemorizePreviousScope, goBackToPreviousHotkeyScope, - } = usePreviousHotkeyScope(); + } = usePreviousHotkeyScope(INLINE_CELL_HOTKEY_SCOPE_MEMOIZE_KEY); const initFieldInputDraftValue = useInitDraftValueV2(); diff --git a/packages/twenty-front/src/modules/object-record/record-title-cell/hooks/useRecordTitleCell.tsx b/packages/twenty-front/src/modules/object-record/record-title-cell/hooks/useRecordTitleCell.tsx index a3e4c1d8c..acab2bd51 100644 --- a/packages/twenty-front/src/modules/object-record/record-title-cell/hooks/useRecordTitleCell.tsx +++ b/packages/twenty-front/src/modules/object-record/record-title-cell/hooks/useRecordTitleCell.tsx @@ -1,3 +1,4 @@ +import { INLINE_CELL_HOTKEY_SCOPE_MEMOIZE_KEY } from '@/object-record/record-inline-cell/constants/InlineCellHotkeyScopeMemoizeKey'; import { isInlineCellInEditModeScopedState } from '@/object-record/record-inline-cell/states/isInlineCellInEditModeScopedState'; import { InlineCellHotkeyScope } from '@/object-record/record-inline-cell/types/InlineCellHotkeyScope'; import { getRecordTitleCellId } from '@/object-record/record-title-cell/utils/getRecordTitleCellId'; @@ -6,7 +7,6 @@ import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousH import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope'; import { useRecoilCallback } from 'recoil'; import { isDefined } from 'twenty-shared/utils'; - export const useRecordTitleCell = () => { const { goBackToPreviousDropdownFocusId } = useGoBackToPreviousDropdownFocusId(); @@ -14,7 +14,7 @@ export const useRecordTitleCell = () => { const { setHotkeyScopeAndMemorizePreviousScope, goBackToPreviousHotkeyScope, - } = usePreviousHotkeyScope(); + } = usePreviousHotkeyScope(INLINE_CELL_HOTKEY_SCOPE_MEMOIZE_KEY); const closeRecordTitleCell = useRecoilCallback( ({ set }) => diff --git a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/usePreviousHotkeyScope.ts b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/usePreviousHotkeyScope.ts index d4ee63775..1f31fbf43 100644 --- a/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/usePreviousHotkeyScope.ts +++ b/packages/twenty-front/src/modules/ui/utilities/hotkey/hooks/usePreviousHotkeyScope.ts @@ -4,19 +4,19 @@ import { DEBUG_HOTKEY_SCOPE } from '@/ui/utilities/hotkey/hooks/useScopedHotkeyC import { logDebug } from '~/utils/logDebug'; import { currentHotkeyScopeState } from '../states/internal/currentHotkeyScopeState'; -import { previousHotkeyScopeState } from '../states/internal/previousHotkeyScopeState'; +import { previousHotkeyScopeFamilyState } from '../states/internal/previousHotkeyScopeFamilyState'; import { CustomHotkeyScopes } from '../types/CustomHotkeyScope'; import { useSetHotkeyScope } from './useSetHotkeyScope'; -export const usePreviousHotkeyScope = () => { +export const usePreviousHotkeyScope = (memoizeKey = 'global') => { const setHotkeyScope = useSetHotkeyScope(); const goBackToPreviousHotkeyScope = useRecoilCallback( ({ snapshot, set }) => () => { const previousHotkeyScope = snapshot - .getLoadable(previousHotkeyScopeState) + .getLoadable(previousHotkeyScopeFamilyState(memoizeKey)) .getValue(); if (!previousHotkeyScope) { @@ -32,9 +32,9 @@ export const usePreviousHotkeyScope = () => { previousHotkeyScope.customScopes, ); - set(previousHotkeyScopeState, null); + set(previousHotkeyScopeFamilyState(memoizeKey), null); }, - [setHotkeyScope], + [setHotkeyScope, memoizeKey], ); const setHotkeyScopeAndMemorizePreviousScope = useRecoilCallback( @@ -53,9 +53,10 @@ export const usePreviousHotkeyScope = () => { } setHotkeyScope(scope, customScopes); - set(previousHotkeyScopeState, currentHotkeyScope); + + set(previousHotkeyScopeFamilyState(memoizeKey), currentHotkeyScope); }, - [setHotkeyScope], + [setHotkeyScope, memoizeKey], ); return { diff --git a/packages/twenty-front/src/modules/ui/utilities/hotkey/states/internal/previousHotkeyScopeFamilyState.ts b/packages/twenty-front/src/modules/ui/utilities/hotkey/states/internal/previousHotkeyScopeFamilyState.ts new file mode 100644 index 000000000..821edf41c --- /dev/null +++ b/packages/twenty-front/src/modules/ui/utilities/hotkey/states/internal/previousHotkeyScopeFamilyState.ts @@ -0,0 +1,11 @@ +import { createFamilyState } from '@/ui/utilities/state/utils/createFamilyState'; + +import { HotkeyScope } from '../../types/HotkeyScope'; + +export const previousHotkeyScopeFamilyState = createFamilyState< + HotkeyScope | null, + string +>({ + key: 'previousHotkeyScopeFamilyState', + defaultValue: null, +}); diff --git a/packages/twenty-front/src/modules/ui/utilities/hotkey/states/internal/previousHotkeyScopeState.ts b/packages/twenty-front/src/modules/ui/utilities/hotkey/states/internal/previousHotkeyScopeState.ts deleted file mode 100644 index 4585d8f32..000000000 --- a/packages/twenty-front/src/modules/ui/utilities/hotkey/states/internal/previousHotkeyScopeState.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { createState } from '@ui/utilities/state/utils/createState'; - -import { HotkeyScope } from '../../types/HotkeyScope'; - -export const previousHotkeyScopeState = createState({ - key: 'previousHotkeyScopeState', - defaultValue: null, -});