Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Breaking changes

- DataForm: introduce a new `card` layout. The `form.type` has been moved under a new `layout` object and it is now `form.layout.type`, check the README for details. [#71100](https://github.com/WordPress/gutenberg/pull/71100)
- Adds a new `config` prop to DataViews that allows hiding the view config control entirely. The `perPageSizes` prop has been moved to be part of this new prop. [#71173](https://github.com/WordPress/gutenberg/pull/71173)

### Features

Expand Down
4 changes: 2 additions & 2 deletions packages/dataviews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ The component receives the following props:

React component to be rendered next to the view config button.

#### `perPageSizes`: `number[]`
#### `config`: false | { perPageSizes: number[] }

A list of numbers used to control the available item counts per page. It's optional. Defaults to `[10, 20, 50, 100]`. The list needs to have a minimum of 2 items and a maximum of 6, otherwise the UI component won't be displayed.
Optional. Set it to `false` to hide the view config control entirely. Pass an object with a list of `perPageSizes` to control the available item counts per page (defaults to `[10, 20, 50, 100]`). `perPageSizes` needs to have a minimum of 2 items and a maximum of 6, otherwise the UI component won't be displayed.

#### `empty`: React node

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type DataViewsContextType< Item > = {
filters: NormalizedFilter[];
isShowingFilter: boolean;
setIsShowingFilter: ( value: boolean ) => void;
perPageSizes: number[];
config: false | { perPageSizes: number[] };
empty?: ReactNode;
hasInfiniteScrollHandler: boolean;
};
Expand Down Expand Up @@ -82,8 +82,10 @@ const DataViewsContext = createContext< DataViewsContextType< any > >( {
filters: [],
isShowingFilter: false,
setIsShowingFilter: () => {},
perPageSizes: [],
hasInfiniteScrollHandler: false,
config: {
perPageSizes: [],
},
} );

export default DataViewsContext;
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ function SortDirectionControl() {
}

function ItemsPerPageControl() {
const { view, perPageSizes, onChangeView } = useContext( DataViewsContext );
const { view, config, onChangeView } = useContext( DataViewsContext );
const { infiniteScrollEnabled } = view;
if (
perPageSizes.length < 2 ||
perPageSizes.length > 6 ||
! config ||
! config.perPageSizes ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this is a change in behaviour? Previously perPageSizes had some default values but these are no longer set? [ 10, 20, 50, 100 ]

Copy link
Member Author

@oandregal oandregal Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I missed that. They've been added where they were (see below).

config.perPageSizes.length < 2 ||
config.perPageSizes.length > 6 ||
infiniteScrollEnabled
) {
return null;
Expand All @@ -245,7 +247,7 @@ function ItemsPerPageControl() {
} );
} }
>
{ perPageSizes.map( ( value ) => {
{ config.perPageSizes.map( ( value ) => {
return (
<ToggleGroupControlOption
key={ value }
Expand Down
30 changes: 18 additions & 12 deletions packages/dataviews/src/components/dataviews/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ type DataViewsProps< Item > = {
header?: ReactNode;
getItemLevel?: ( item: Item ) => number;
children?: ReactNode;
perPageSizes?: number[];
config?:
| false
| {
perPageSizes: number[];
};
empty?: ReactNode;
} & ( Item extends ItemWithId
? { getItemId?: ( item: Item ) => string }
Expand All @@ -86,7 +90,7 @@ function DefaultUI( {
search = true,
searchLabel = undefined,
}: DefaultUIProps ) {
const { isShowingFilter } = useContext( DataViewsContext );
const { isShowingFilter, config } = useContext( DataViewsContext );
return (
<>
<HStack
Expand All @@ -103,14 +107,16 @@ function DefaultUI( {
{ search && <DataViewsSearch label={ searchLabel } /> }
<FiltersToggle />
</HStack>
<HStack
spacing={ 1 }
expanded={ false }
style={ { flexShrink: 0 } }
>
<DataViewsViewConfig />
{ header }
</HStack>
{ ( config || header ) && (
<HStack
spacing={ 1 }
expanded={ false }
style={ { flexShrink: 0 } }
>
config && <DataViewsViewConfig />
{ header }
</HStack>
) }
</HStack>
{ isShowingFilter && (
<DataViewsFilters className="dataviews-filters__container" />
Expand Down Expand Up @@ -141,7 +147,7 @@ function DataViews< Item >( {
isItemClickable = defaultIsItemClickable,
header,
children,
perPageSizes = [ 10, 20, 50, 100 ],
config = { perPageSizes: [ 10, 20, 50, 100 ] },
empty,
}: DataViewsProps< Item > ) {
const { infiniteScrollHandler } = paginationInfo;
Expand Down Expand Up @@ -248,7 +254,7 @@ function DataViews< Item >( {
filters,
isShowingFilter,
setIsShowingFilter,
perPageSizes,
config,
empty,
hasInfiniteScrollHandler: !! infiniteScrollHandler,
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const Default = ( { perPageSizes = [ 10, 25, 50, 100 ] } ) => {
) }
isItemClickable={ () => true }
defaultLayouts={ defaultLayouts }
perPageSizes={ perPageSizes }
config={ { perPageSizes } }
/>
);
};
Expand Down Expand Up @@ -172,7 +172,7 @@ export const MinimalUI = () => {
data={ shownData }
view={ view }
fields={ _fields }
perPageSizes={ [] }
config={ false }
search={ false }
onChangeView={ setView }
defaultLayouts={ {
Expand Down
Loading