Action menu refactoring (#11454)
# Description Closes [#696](https://github.com/twentyhq/core-team-issues/issues/696) - `useAction` hooks have been removed for all actions - Every action can now declare a react component - Some standard action components have been introduced: `Action`, `ActionLink` and `ActionModal` - The `ActionDisplay` component uses the new `displayType` prop of the `ActionMenuContext` to render the right component for the action according to its container: `ActionButton`, `ActionDropdownItem` or `ActionListItem` - The `ActionDisplayer` wraps the action component inside a context which gives it all the information about the action -`actionMenuEntriesComponenState` has been removed and now all actions are computed directly using `useRegisteredAction` - This computation is done inside `ActionMenuContextProvider` and the actions are passed inside a context - `actionMenuType` gives information about the container of the action, so the action can know wether or not to close this container upon execution
This commit is contained in:
@ -0,0 +1,43 @@
|
||||
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext';
|
||||
import { ActionMenuComponentInstanceContext } from '@/action-menu/states/contexts/ActionMenuComponentInstanceContext';
|
||||
import { getActionMenuDropdownIdFromActionMenuId } from '@/action-menu/utils/getActionMenuDropdownIdFromActionMenuId';
|
||||
import { getRightDrawerActionMenuDropdownIdFromActionMenuId } from '@/action-menu/utils/getRightDrawerActionMenuDropdownIdFromActionMenuId';
|
||||
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
|
||||
import { useDropdownV2 } from '@/ui/layout/dropdown/hooks/useDropdownV2';
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { useContext } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const useCloseActionMenu = (preventCommandMenuClosing?: boolean) => {
|
||||
const { actionMenuType, isInRightDrawer } = useContext(ActionMenuContext);
|
||||
|
||||
const { closeCommandMenu } = useCommandMenu();
|
||||
|
||||
const { closeDropdown } = useDropdownV2();
|
||||
|
||||
const actionMenuId = useAvailableComponentInstanceIdOrThrow(
|
||||
ActionMenuComponentInstanceContext,
|
||||
);
|
||||
|
||||
const dropdownId = isInRightDrawer
|
||||
? getRightDrawerActionMenuDropdownIdFromActionMenuId(actionMenuId)
|
||||
: getActionMenuDropdownIdFromActionMenuId(actionMenuId);
|
||||
|
||||
const closeActionMenu = () => {
|
||||
if (actionMenuType === 'command-menu') {
|
||||
if (isDefined(preventCommandMenuClosing) && preventCommandMenuClosing) {
|
||||
return;
|
||||
}
|
||||
closeCommandMenu();
|
||||
}
|
||||
|
||||
if (
|
||||
actionMenuType === 'index-page-action-menu-dropdown' ||
|
||||
actionMenuType === 'command-menu-show-page-action-menu-dropdown'
|
||||
) {
|
||||
closeDropdown(dropdownId);
|
||||
}
|
||||
};
|
||||
|
||||
return { closeActionMenu };
|
||||
};
|
||||
Reference in New Issue
Block a user