Skip to content

The open alternative to Salesforce, designed for AI.

Fix unable to reopen record after going back in side panel (#12523)

Raphaël Bosi17fb47f97c7c
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 dadb04cd58f..bdae671b69b 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 5956aaa6385..ac57de41e8b 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<string | null>({
key: 'activities/viewable-record-id',
defaultValue: null,