Close command menu after destroy (#12525)
Added an argument `closeCommandMenuFromShowPageOptionsMenu` which allows us to not only close the parent action menu if the action is located inside the record page action menu dropdown, but to also close the command menu after, which is the behavior we want for the destroy action.
This commit is contained in:
@ -5,14 +5,19 @@ import { useContext } from 'react';
|
|||||||
|
|
||||||
export const Action = ({
|
export const Action = ({
|
||||||
onClick,
|
onClick,
|
||||||
preventCommandMenuClosing,
|
closeSidePanelOnShowPageOptionsActionExecution = false,
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution = true,
|
||||||
}: {
|
}: {
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
preventCommandMenuClosing?: boolean;
|
closeSidePanelOnShowPageOptionsActionExecution?: boolean;
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const actionConfig = useContext(ActionConfigContext);
|
const actionConfig = useContext(ActionConfigContext);
|
||||||
|
|
||||||
const { closeActionMenu } = useCloseActionMenu(preventCommandMenuClosing);
|
const { closeActionMenu } = useCloseActionMenu({
|
||||||
|
closeSidePanelOnShowPageOptionsActionExecution,
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution,
|
||||||
|
});
|
||||||
|
|
||||||
if (!actionConfig) {
|
if (!actionConfig) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -18,6 +18,8 @@ export type ActionModalProps = {
|
|||||||
confirmButtonText?: string;
|
confirmButtonText?: string;
|
||||||
confirmButtonAccent?: ButtonAccent;
|
confirmButtonAccent?: ButtonAccent;
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
|
closeSidePanelOnShowPageOptionsActionExecution?: boolean;
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ActionModal = ({
|
export const ActionModal = ({
|
||||||
@ -27,10 +29,15 @@ export const ActionModal = ({
|
|||||||
confirmButtonText = 'Confirm',
|
confirmButtonText = 'Confirm',
|
||||||
confirmButtonAccent = 'danger',
|
confirmButtonAccent = 'danger',
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
|
closeSidePanelOnShowPageOptionsActionExecution,
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution,
|
||||||
}: ActionModalProps) => {
|
}: ActionModalProps) => {
|
||||||
const { openModal } = useModal();
|
const { openModal } = useModal();
|
||||||
|
|
||||||
const { closeActionMenu } = useCloseActionMenu();
|
const { closeActionMenu } = useCloseActionMenu({
|
||||||
|
closeSidePanelOnShowPageOptionsActionExecution,
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution,
|
||||||
|
});
|
||||||
|
|
||||||
const handleConfirmClick = () => {
|
const handleConfirmClick = () => {
|
||||||
onConfirmClick();
|
onConfirmClick();
|
||||||
|
|||||||
@ -10,6 +10,9 @@ export const CreateNewTableRecordNoSelectionRecordAction = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Action onClick={() => createNewIndexRecord()} preventCommandMenuClosing />
|
<Action
|
||||||
|
onClick={() => createNewIndexRecord()}
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution={false}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -36,6 +36,7 @@ export const DestroySingleRecordAction = () => {
|
|||||||
subtitle="Are you sure you want to destroy this record? It cannot be recovered anymore."
|
subtitle="Are you sure you want to destroy this record? It cannot be recovered anymore."
|
||||||
onConfirmClick={handleDeleteClick}
|
onConfirmClick={handleDeleteClick}
|
||||||
confirmButtonText="Permanently Destroy Record"
|
confirmButtonText="Permanently Destroy Record"
|
||||||
|
closeSidePanelOnShowPageOptionsActionExecution={true}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,13 @@ import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/com
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { isDefined } from 'twenty-shared/utils';
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
|
|
||||||
export const useCloseActionMenu = (preventCommandMenuClosing?: boolean) => {
|
export const useCloseActionMenu = ({
|
||||||
|
closeSidePanelOnShowPageOptionsActionExecution = false,
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution = true,
|
||||||
|
}: {
|
||||||
|
closeSidePanelOnShowPageOptionsActionExecution?: boolean;
|
||||||
|
closeSidePanelOnCommandMenuListActionExecution?: boolean;
|
||||||
|
} = {}) => {
|
||||||
const { actionMenuType, isInRightDrawer } = useContext(ActionMenuContext);
|
const { actionMenuType, isInRightDrawer } = useContext(ActionMenuContext);
|
||||||
|
|
||||||
const { closeCommandMenu } = useCommandMenu();
|
const { closeCommandMenu } = useCommandMenu();
|
||||||
@ -25,7 +31,10 @@ export const useCloseActionMenu = (preventCommandMenuClosing?: boolean) => {
|
|||||||
|
|
||||||
const closeActionMenu = () => {
|
const closeActionMenu = () => {
|
||||||
if (actionMenuType === 'command-menu') {
|
if (actionMenuType === 'command-menu') {
|
||||||
if (isDefined(preventCommandMenuClosing) && preventCommandMenuClosing) {
|
if (
|
||||||
|
isDefined(closeSidePanelOnCommandMenuListActionExecution) &&
|
||||||
|
!closeSidePanelOnCommandMenuListActionExecution
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
closeCommandMenu();
|
closeCommandMenu();
|
||||||
@ -37,6 +46,14 @@ export const useCloseActionMenu = (preventCommandMenuClosing?: boolean) => {
|
|||||||
) {
|
) {
|
||||||
closeDropdown(dropdownId);
|
closeDropdown(dropdownId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
actionMenuType === 'command-menu-show-page-action-menu-dropdown' &&
|
||||||
|
isDefined(closeSidePanelOnShowPageOptionsActionExecution) &&
|
||||||
|
closeSidePanelOnShowPageOptionsActionExecution
|
||||||
|
) {
|
||||||
|
closeCommandMenu();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return { closeActionMenu };
|
return { closeActionMenu };
|
||||||
|
|||||||
@ -76,7 +76,7 @@ export const useCommandMenuSearchRecords = () => {
|
|||||||
objectNameSingular: CoreObjectNameSingular.Note,
|
objectNameSingular: CoreObjectNameSingular.Note,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
preventCommandMenuClosing
|
closeSidePanelOnCommandMenuListActionExecution={false}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user