From 17fb47f97c7c8050fa4b100cc8d48bfefbb7f65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bosi?= <71827178+bosiraphael@users.noreply.github.com> Date: Wed, 11 Jun 2025 18:29:03 +0200 Subject: [PATCH] Fix unable to reopen record after going back in side panel (#12523) Before: https://github.com/user-attachments/assets/25ab8857-ed83-41be-9952-2108443d3e3c After: https://github.com/user-attachments/assets/c161c194-1f41-4197-8d5c-f824c6cb5e73 --- .../hooks/useOpenRecordInCommandMenu.ts | 27 ++++++++++++++----- .../states/viewableRecordIdState.ts | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useOpenRecordInCommandMenu.ts b/packages/twenty-front/src/modules/command-menu/hooks/useOpenRecordInCommandMenu.ts index dadb04cd5..bdae671b6 100644 --- a/packages/twenty-front/src/modules/command-menu/hooks/useOpenRecordInCommandMenu.ts +++ b/packages/twenty-front/src/modules/command-menu/hooks/useOpenRecordInCommandMenu.ts @@ -2,6 +2,7 @@ import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; import { viewableRecordIdComponentState } from '@/command-menu/pages/record-page/states/viewableRecordIdComponentState'; import { viewableRecordNameSingularComponentState } from '@/command-menu/pages/record-page/states/viewableRecordNameSingularComponentState'; import { commandMenuNavigationMorphItemByPageState } from '@/command-menu/states/commandMenuNavigationMorphItemsState'; +import { commandMenuNavigationStackState } from '@/command-menu/states/commandMenuNavigationStackState'; import { CommandMenuPages } from '@/command-menu/types/CommandMenuPages'; import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId'; import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState'; @@ -14,11 +15,12 @@ import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objec import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; import { getIconColorForObjectType } from '@/object-metadata/utils/getIconColorForObjectType'; import { viewableRecordIdState } from '@/object-record/record-right-drawer/states/viewableRecordIdState'; +import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue'; import { useRunWorkflowRunOpeningInCommandMenuSideEffects } from '@/workflow/hooks/useRunWorkflowRunOpeningInCommandMenuSideEffects'; import { useTheme } from '@emotion/react'; import { t } from '@lingui/core/macro'; import { useRecoilCallback } from 'recoil'; -import { capitalize } from 'twenty-shared/utils'; +import { capitalize, isDefined } from 'twenty-shared/utils'; import { useIcons } from 'twenty-ui/display'; import { v4 } from 'uuid'; @@ -41,11 +43,24 @@ export const useOpenRecordInCommandMenu = () => { objectNameSingular: string; isNewRecord?: boolean; }) => { - const lastRecordId = snapshot - .getLoadable(viewableRecordIdState) - .getValue(); - if (lastRecordId === recordId) { - return; + const navigationStack = getSnapshotValue( + snapshot, + commandMenuNavigationStackState, + ); + + const currentNavigationStackItem = navigationStack.at(-1); + + if (isDefined(currentNavigationStackItem)) { + const currentRecordId = getSnapshotValue( + snapshot, + viewableRecordIdComponentState.atomFamily({ + instanceId: currentNavigationStackItem.pageId, + }), + ); + + if (currentRecordId === recordId) { + return; + } } const pageComponentInstanceId = v4(); diff --git a/packages/twenty-front/src/modules/object-record/record-right-drawer/states/viewableRecordIdState.ts b/packages/twenty-front/src/modules/object-record/record-right-drawer/states/viewableRecordIdState.ts index 5956aaa63..ac57de41e 100644 --- a/packages/twenty-front/src/modules/object-record/record-right-drawer/states/viewableRecordIdState.ts +++ b/packages/twenty-front/src/modules/object-record/record-right-drawer/states/viewableRecordIdState.ts @@ -1,4 +1,5 @@ import { createState } from 'twenty-ui/utilities'; + export const viewableRecordIdState = createState({ key: 'activities/viewable-record-id', defaultValue: null,