Skip to content

Commit

Permalink
DataViews: Hide actions related UI in grid when no actions or bulk …
Browse files Browse the repository at this point in the history
…actions are passed (WordPress#68033)

Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
  • Loading branch information
3 people authored Dec 16, 2024
1 parent f5b8bec commit 2eb82b4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/dataviews/src/dataviews-layouts/grid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -47,6 +50,7 @@ interface GridItemProps< Item > {
descriptionField?: NormalizedField< Item >;
regularFields: NormalizedField< Item >[];
badgeFields: NormalizedField< Item >[];
hasBulkActions: boolean;
}

function GridItem< Item >( {
Expand All @@ -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 );
Expand Down Expand Up @@ -135,7 +140,7 @@ function GridItem< Item >( {
{ renderedMediaField }
</div>
) }
{ showMedia && renderedMediaField && (
{ hasBulkActions && showMedia && renderedMediaField && (
<DataViewsSelectionCheckbox
item={ item }
selection={ selection }
Expand All @@ -152,7 +157,9 @@ function GridItem< Item >( {
<div { ...clickableTitleItemProps } { ...titleA11yProps }>
{ renderedTitleField }
</div>
<ItemActions item={ item } actions={ actions } isCompact />
{ !! actions?.length && (
<ItemActions item={ item } actions={ actions } isCompact />
) }
</HStack>
<VStack spacing={ 1 }>
{ showDescription && descriptionField?.render && (
Expand Down Expand Up @@ -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
? {
Expand Down Expand Up @@ -292,6 +300,7 @@ export default function ViewGrid< Item >( {
descriptionField={ descriptionField }
regularFields={ regularFields }
badgeFields={ badgeFields }
hasBulkActions={ hasBulkActions }
/>
);
} ) }
Expand Down

0 comments on commit 2eb82b4

Please sign in to comment.