Skip to content

The open alternative to Salesforce, designed for AI.

fix: Edit Layout keeping the command menu open (#21161)

Parship Chowdhury4de9f45015e7
diff --git a/packages/twenty-front/src/modules/command-menu-item/engine-command/record/single-record/record-page-layout/components/EditRecordPageLayoutSingleRecordCommand.tsx b/packages/twenty-front/src/modules/command-menu-item/engine-command/record/single-record/record-page-layout/components/EditRecordPageLayoutSingleRecordCommand.tsx
index 62183861fec..3fae4b6a9eb 100644
--- a/packages/twenty-front/src/modules/command-menu-item/engine-command/record/single-record/record-page-layout/components/EditRecordPageLayoutSingleRecordCommand.tsx
+++ b/packages/twenty-front/src/modules/command-menu-item/engine-command/record/single-record/record-page-layout/components/EditRecordPageLayoutSingleRecordCommand.tsx
@@ -1,13 +1,17 @@
+import { useResetLocationHash } from 'twenty-ui/utilities';
+
import { HeadlessEngineCommandWrapperEffect } from '@/command-menu-item/engine-command/components/HeadlessEngineCommandWrapperEffect';
import { useEnterLayoutCustomizationMode } from '@/layout-customization/hooks/useEnterLayoutCustomizationMode';
-import { useResetLocationHash } from 'twenty-ui/utilities';
+import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
export const EditRecordPageLayoutSingleRecordCommand = () => {
const { enterLayoutCustomizationMode } = useEnterLayoutCustomizationMode();
-
+ const { closeSidePanelMenu } = useSidePanelMenu();
const { resetLocationHash } = useResetLocationHash();
- const handleExecute = () => {
+ const handleExecute = async () => {
+ await closeSidePanelMenu();
+
enterLayoutCustomizationMode();
resetLocationHash();
};
diff --git a/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelMenu.ts b/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelMenu.ts
index baf9b34a3cd..cf414833bf0 100644
--- a/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelMenu.ts
+++ b/packages/twenty-front/src/modules/side-panel/hooks/useSidePanelMenu.ts
@@ -11,6 +11,7 @@ import { sidePanelSearchObjectFilterState } from '@/side-panel/states/sidePanelS
import { sidePanelSearchState } from '@/side-panel/states/sidePanelSearchState';
import { useCloseAnyOpenDropdown } from '@/ui/layout/dropdown/hooks/useCloseAnyOpenDropdown';
import { emitSidePanelOpenEvent } from '@/ui/layout/side-panel/utils/emitSidePanelOpenEvent';
+import { waitForSidePanelClose } from '@/ui/layout/side-panel/utils/waitForSidePanelClose';
import { useRemoveFocusItemFromFocusStackById } from '@/ui/utilities/focus/hooks/useRemoveFocusItemFromFocusStackById';
import { t } from '@lingui/core/macro';
import { useStore } from 'jotai';
@@ -30,26 +31,30 @@ export const useSidePanelMenu = () => {
const { removeFocusItemFromFocusStackById } =
useRemoveFocusItemFromFocusStackById();
- const closeSidePanelMenu = useCallback(() => {
+ const closeSidePanelMenu = useCallback(async () => {
const isSidePanelOpened = store.get(isSidePanelOpenedState.atom);
- if (isSidePanelOpened) {
- const isLayoutCustomizationModeEnabled = store.get(
- isLayoutCustomizationModeEnabledState.atom,
- );
-
- if (isLayoutCustomizationModeEnabled) {
- resetRecordIndexSelection();
- }
-
- store.set(sidePanelNavigationStackState.atom, []);
- store.set(isSidePanelOpenedState.atom, false);
- store.set(isSidePanelClosingState.atom, true);
- closeAnyOpenDropdown();
- removeFocusItemFromFocusStackById({
- focusId: SIDE_PANEL_FOCUS_ID,
- });
+ if (!isSidePanelOpened) {
+ return;
}
+
+ const isLayoutCustomizationModeEnabled = store.get(
+ isLayoutCustomizationModeEnabledState.atom,
+ );
+
+ if (isLayoutCustomizationModeEnabled) {
+ resetRecordIndexSelection();
+ }
+
+ store.set(sidePanelNavigationStackState.atom, []);
+ store.set(isSidePanelOpenedState.atom, false);
+ store.set(isSidePanelClosingState.atom, true);
+ closeAnyOpenDropdown();
+ removeFocusItemFromFocusStackById({
+ focusId: SIDE_PANEL_FOCUS_ID,
+ });
+
+ await waitForSidePanelClose();
}, [
closeAnyOpenDropdown,
removeFocusItemFromFocusStackById,
diff --git a/packages/twenty-front/src/modules/ui/layout/side-panel/utils/waitForSidePanelClose.ts b/packages/twenty-front/src/modules/ui/layout/side-panel/utils/waitForSidePanelClose.ts
new file mode 100644
index 00000000000..1ede9344723
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/layout/side-panel/utils/waitForSidePanelClose.ts
@@ -0,0 +1,20 @@
+import { SIDE_PANEL_CLOSE_EVENT_NAME } from '@/ui/layout/side-panel/utils/emitSidePanelCloseEvent';
+
+const SIDE_PANEL_CLOSE_TIMEOUT_MS = 500;
+
+export const waitForSidePanelClose = (): Promise<void> => {
+ return new Promise((resolve) => {
+ const handler = () => {
+ window.removeEventListener(SIDE_PANEL_CLOSE_EVENT_NAME, handler);
+ clearTimeout(timeoutId);
+ resolve();
+ };
+
+ const timeoutId = setTimeout(() => {
+ window.removeEventListener(SIDE_PANEL_CLOSE_EVENT_NAME, handler);
+ resolve();
+ }, SIDE_PANEL_CLOSE_TIMEOUT_MS);
+
+ window.addEventListener(SIDE_PANEL_CLOSE_EVENT_NAME, handler);
+ });
+};