The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix: clear navigation stack immediately in goBackFromSidePanel (#19153)
BugIsGod176e81cd76e5
diff --git a/packages/twenty-front/src/modules/side-panel/hooks/__tests__/useSidePanelHistory.test.tsx b/packages/twenty-front/src/modules/side-panel/hooks/__tests__/useSidePanelHistory.test.tsxindex 2a1e7238c32..470dad55f58 100644--- a/packages/twenty-front/src/modules/side-panel/hooks/__tests__/useSidePanelHistory.test.tsx+++ b/packages/twenty-front/src/modules/side-panel/hooks/__tests__/useSidePanelHistory.test.tsx@@ -100,10 +100,13 @@ describe('useSidePanelHistory', () => {act(() => {result.current.commandMenuHistory.goBackFromSidePanel();- result.current.sidePanelCloseAnimationCompleteCleanup.sidePanelCloseAnimationCompleteCleanup();});expect(jotaiStore.get(sidePanelNavigationStackState.atom)).toEqual([]);++ act(() => {+ result.current.sidePanelCloseAnimationCompleteCleanup.sidePanelCloseAnimationCompleteCleanup();+ });expect(jotaiStore.get(sidePanelPageState.atom)).toBe(SidePanelPages.CommandMenuDisplay,);@@ -115,6 +118,34 @@ describe('useSidePanelHistory', () => {expect(jotaiStore.get(isSidePanelOpenedState.atom)).toBe(false);});+ it('should clear navigation stack immediately when closeSidePanelMenu is called', () => {+ const { result } = renderHooks();++ act(() => {+ result.current.commandMenu.navigateSidePanelMenu({+ page: SidePanelPages.ViewRecord,+ pageTitle: 'Company',+ pageIcon: IconList,+ pageId: '1',+ });+ });++ expect(jotaiStore.get(sidePanelNavigationStackState.atom)).toEqual([+ {+ page: SidePanelPages.ViewRecord,+ pageTitle: 'Company',+ pageIcon: IconList,+ pageId: '1',+ },+ ]);++ act(() => {+ result.current.commandMenu.closeSidePanelMenu();+ });++ expect(jotaiStore.get(sidePanelNavigationStackState.atom)).toEqual([]);+ });+it('should navigate to a page in history', () => {const { result } = renderHooks();diff --git a/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelHistory.ts b/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelHistory.tsindex 7366c454095..233a9e11854 100644--- a/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelHistory.ts+++ b/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelHistory.ts@@ -67,6 +67,8 @@ export const useSidePanelHistory = () => {const newNavigationStack = currentNavigationStack.slice(0, -1);const lastNavigationStackItem = newNavigationStack.at(-1);+ store.set(sidePanelNavigationStackState.atom, newNavigationStack);+if (!isDefined(lastNavigationStackItem)) {closeSidePanelMenu();return;@@ -80,8 +82,6 @@ export const useSidePanelHistory = () => {instanceId: lastNavigationStackItem.pageId,});- store.set(sidePanelNavigationStackState.atom, newNavigationStack);-store.set(hasUserSelectedSidePanelListItemState.atom, false);}, [cleanupCurrentPage, closeSidePanelMenu, store]);diff --git a/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelMenu.ts b/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelMenu.tsindex fd43638e0d7..4a6ff8f544f 100644--- a/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelMenu.ts+++ b/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelMenu.ts@@ -3,6 +3,7 @@ import { selectedNavigationMenuItemIdInEditModeState } from '@/navigation-menu-iimport { SIDE_PANEL_FOCUS_ID } from '@/side-panel/constants/SidePanelFocusId';import { useNavigateSidePanel } from '@/side-panel/hooks/useNavigateSidePanel';import { isSidePanelClosingState } from '@/side-panel/states/isSidePanelClosingState';+import { sidePanelNavigationStackState } from '@/side-panel/states/sidePanelNavigationStackState';import { isSidePanelOpenedState } from '@/side-panel/states/isSidePanelOpenedState';import { sidePanelSearchObjectFilterState } from '@/side-panel/states/sidePanelSearchObjectFilterState';import { sidePanelSearchState } from '@/side-panel/states/sidePanelSearchState';@@ -28,6 +29,7 @@ export const useSidePanelMenu = () => {const isSidePanelOpened = store.get(isSidePanelOpenedState.atom);if (isSidePanelOpened) {+ store.set(sidePanelNavigationStackState.atom, []);store.set(isSidePanelOpenedState.atom, false);store.set(isSidePanelClosingState.atom, true);closeAnyOpenDropdown();