From 4d27d469d7ace9410bd53d3529265c612696a929 Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Mon, 16 Dec 2024 18:14:00 +0200 Subject: [PATCH] DataViews: Hide actions related UI in `grid` when no actions or bulk actions are passed (#68033) Co-authored-by: ntsekouras Co-authored-by: oandregal --- .../src/dataviews-layouts/grid/index.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/dataviews/src/dataviews-layouts/grid/index.tsx b/packages/dataviews/src/dataviews-layouts/grid/index.tsx index b1f074c5682993..cdb70219d229ad 100644 --- a/packages/dataviews/src/dataviews-layouts/grid/index.tsx +++ b/packages/dataviews/src/dataviews-layouts/grid/index.tsx @@ -22,7 +22,10 @@ import { useInstanceId } from '@wordpress/compose'; */ import ItemActions from '../../components/dataviews-item-actions'; import DataViewsSelectionCheckbox from '../../components/dataviews-selection-checkbox'; -import { useHasAPossibleBulkAction } from '../../components/dataviews-bulk-actions'; +import { + useHasAPossibleBulkAction, + useSomeItemHasAPossibleBulkAction, +} from '../../components/dataviews-bulk-actions'; import type { Action, NormalizedField, @@ -47,6 +50,7 @@ interface GridItemProps< Item > { descriptionField?: NormalizedField< Item >; regularFields: NormalizedField< Item >[]; badgeFields: NormalizedField< Item >[]; + hasBulkActions: boolean; } function GridItem< Item >( { @@ -63,6 +67,7 @@ function GridItem< Item >( { descriptionField, regularFields, badgeFields, + hasBulkActions, }: GridItemProps< Item > ) { const { showTitle = true, showMedia = true, showDescription = true } = view; const hasBulkAction = useHasAPossibleBulkAction( actions, item ); @@ -135,7 +140,7 @@ function GridItem< Item >( { { renderedMediaField } ) } - { showMedia && renderedMediaField && ( + { hasBulkActions && showMedia && renderedMediaField && ( ( {
{ renderedTitleField }
- + { !! actions?.length && ( + + ) } { showDescription && descriptionField?.render && ( @@ -258,6 +265,7 @@ export default function ViewGrid< Item >( { ); const hasData = !! data?.length; const updatedPreviewSize = useUpdatedPreviewSizeOnViewportChange(); + const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ); const usedPreviewSize = updatedPreviewSize || view.layout?.previewSize; const gridStyle = usedPreviewSize ? { @@ -292,6 +300,7 @@ export default function ViewGrid< Item >( { descriptionField={ descriptionField } regularFields={ regularFields } badgeFields={ badgeFields } + hasBulkActions={ hasBulkActions } /> ); } ) }