Skip to content

Commit

Permalink
Hide group title in CrudMoreActionsMenu when only one group is pres…
Browse files Browse the repository at this point in the history
…ent (#2920)
  • Loading branch information
fichtnerma authored Jan 14, 2025
1 parent 77ba36c commit 92b3255
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-shoes-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin": minor
---

Hide group title in `CrudMoreActionsMenu` when only one group is present
32 changes: 22 additions & 10 deletions packages/admin/admin/src/dataGrid/CrudMoreActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ export interface CrudMoreActionsMenuProps
}

interface CrudMoreActionsGroupProps {
groupTitle: ReactNode;
groupTitle?: ReactNode;
menuListProps?: MenuListProps;
typographyProps?: ComponentProps<typeof Typography>;
}

function CrudMoreActionsGroup({ groupTitle, children, menuListProps, typographyProps }: PropsWithChildren<CrudMoreActionsGroupProps>) {
return (
<>
<Typography variant="overline" color={(theme) => theme.palette.grey[500]} sx={{ padding: "20px 15px 0 15px" }} {...typographyProps}>
{groupTitle}
</Typography>
{groupTitle && (
<Typography variant="overline" color={(theme) => theme.palette.grey[500]} sx={{ padding: "20px 15px 0 15px" }} {...typographyProps}>
{groupTitle}
</Typography>
)}
<MenuList {...menuListProps}>{children}</MenuList>
</>
);
Expand Down Expand Up @@ -116,11 +118,13 @@ export function CrudMoreActionsMenu({ slotProps, overallActions, selectiveAction
const handleClick = (event: MouseEvent<HTMLButtonElement>) => setAnchorEl(event.currentTarget);

const handleClose = () => setAnchorEl(null);
const hasOverallActions = !!overallActions?.length;
const hasSelectiveActions = !!selectiveActions?.length;

return (
<>
<MoreActionsButton variant="text" color="inherit" endIcon={<MoreVertical />} {...buttonProps} onClick={handleClick}>
<FormattedMessage id="comet.crudMoreActions.title" defaultMessage="More actions" />
<FormattedMessage id="comet.crudMoreActions.title" defaultMessage="More" />
{!!selectionSize && <MoreActionsSelectedItemsChip size="small" color="primary" {...chipProps} label={selectionSize} />}
</MoreActionsButton>
<Menu
Expand All @@ -134,9 +138,13 @@ export function CrudMoreActionsMenu({ slotProps, overallActions, selectiveAction
menuProps?.onClose?.(event, reason);
}}
>
{!!overallActions?.length && (
{hasOverallActions && (
<CrudMoreActionsGroup
groupTitle={<FormattedMessage id="comet.crudMoreActions.overallActions" defaultMessage="Overall actions" />}
groupTitle={
hasSelectiveActions ? (
<FormattedMessage id="comet.crudMoreActions.overallActions" defaultMessage="Overall actions" />
) : undefined
}
{...groupProps}
>
{overallActions.map((item, index) => {
Expand Down Expand Up @@ -165,11 +173,15 @@ export function CrudMoreActionsMenu({ slotProps, overallActions, selectiveAction
</CrudMoreActionsGroup>
)}

{!!overallActions?.length && !!selectiveActions?.length && <CrudMoreActionsDivider {...dividerProps} />}
{hasOverallActions && hasSelectiveActions && <CrudMoreActionsDivider {...dividerProps} />}

{!!selectiveActions?.length && (
{hasSelectiveActions && (
<CrudMoreActionsGroup
groupTitle={<FormattedMessage id="comet.crudMoreActions.selectiveActions" defaultMessage="Selective actions" />}
groupTitle={
hasOverallActions ? (
<FormattedMessage id="comet.crudMoreActions.selectiveActions" defaultMessage="Selective actions" />
) : undefined
}
{...groupProps}
>
{selectiveActions.map((item, index) => {
Expand Down

0 comments on commit 92b3255

Please sign in to comment.