Files
twenty/packages/twenty-front/src/modules/action-menu/actions/display/components/ActionDisplay.tsx
Raphaël Bosi 9e0402e691 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
2025-04-09 13:12:49 +00:00

53 lines
1.5 KiB
TypeScript

import { ActionButton } from '@/action-menu/actions/display/components/ActionButton';
import { ActionDropdownItem } from '@/action-menu/actions/display/components/ActionDropdownItem';
import { ActionListItem } from '@/action-menu/actions/display/components/ActionListItem';
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext';
import { MessageDescriptor } from '@lingui/core';
import { useContext } from 'react';
import { assertUnreachable } from 'twenty-shared/utils';
import { IconComponent } from 'twenty-ui/display';
import { MenuItemAccent } from 'twenty-ui/navigation';
export type ActionDisplayProps = {
key: string;
label: MessageDescriptor | string;
shortLabel?: MessageDescriptor | string;
description?: MessageDescriptor | string;
Icon: IconComponent;
accent?: MenuItemAccent;
hotKeys?: string[];
};
export const ActionDisplay = ({
action,
onClick,
to,
}: {
action: ActionDisplayProps;
onClick?: (event?: React.MouseEvent<HTMLElement>) => void;
to?: string;
}) => {
const { displayType } = useContext(ActionMenuContext);
if (!action) {
return null;
}
if (displayType === 'button') {
return <ActionButton action={action} onClick={onClick} to={to} />;
}
if (displayType === 'listItem') {
return <ActionListItem action={action} onClick={onClick} to={to} />;
}
if (displayType === 'dropdownItem') {
return <ActionDropdownItem action={action} onClick={onClick} to={to} />;
}
return assertUnreachable(
displayType,
`Unsupported display type: ${displayType}`,
);
};