The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Update previousHotkeyScopeState to be a family state (#11270)
Raphaël Bosi352cf3d38e5d
diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuCloseAnimationCompleteCleanup.ts b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuCloseAnimationCompleteCleanup.tsindex 66fe24d2093..7c1e397c6be 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.tsindex 554e2e2f3fc..1253a1f4581 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.tsnew file mode 100644index 00000000000..6aaed6c54d0--- /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.tsindex 74884407bb7..5f18dfe60ad 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/usePreviousHimport { 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.tsxindex a3e4c1d8cec..acab2bd518c 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/usePreviousHimport { 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.tsindex d4ee63775d1..1f31fbf438b 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/useScopedHotkeyCimport { 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.tsnew file mode 100644index 00000000000..821edf41c51--- /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.tsdeleted file mode 100644index 4585d8f32be..00000000000--- 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<HotkeyScope | null>({- key: 'previousHotkeyScopeState',- defaultValue: null,-});