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
4 changes: 4 additions & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking changes

- Revert the ability to hide the view config via `config` prop and export a `DataViews.Footer` component to support the "Minimal UI" story. [#71276](https://github.com/WordPress/gutenberg/pull/71276)

### Bug Fixes

- DataViews: Fix incorrect documentation for `defaultLayouts` prop. [#71334](https://github.com/WordPress/gutenberg/pull/71334)
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.

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

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.
Optional. 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;
config: false | { perPageSizes: number[] };
config: { perPageSizes: number[] };
empty?: ReactNode;
hasInfiniteScrollHandler: boolean;
};
Expand Down
30 changes: 14 additions & 16 deletions packages/dataviews/src/components/dataviews/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ type DataViewsProps< Item > = {
header?: ReactNode;
getItemLevel?: ( item: Item ) => number;
children?: ReactNode;
config?:
| false
| {
perPageSizes: number[];
};
config?: {
perPageSizes: number[];
};
empty?: ReactNode;
} & ( Item extends ItemWithId
? { getItemId?: ( item: Item ) => string }
Expand All @@ -90,7 +88,7 @@ function DefaultUI( {
search = true,
searchLabel = undefined,
}: DefaultUIProps ) {
const { isShowingFilter, config } = useContext( DataViewsContext );
const { isShowingFilter } = useContext( DataViewsContext );
return (
<>
<HStack
Expand All @@ -107,16 +105,14 @@ function DefaultUI( {
{ search && <DataViewsSearch label={ searchLabel } /> }
<FiltersToggle />
</HStack>
{ ( config || header ) && (
<HStack
spacing={ 1 }
expanded={ false }
style={ { flexShrink: 0 } }
>
config && <DataViewsViewConfig />
{ header }
</HStack>
) }
<HStack
spacing={ 1 }
expanded={ false }
style={ { flexShrink: 0 } }
>
<DataViewsViewConfig />
{ header }
</HStack>
</HStack>
{ isShowingFilter && (
<DataViewsFilters className="dataviews-filters__container" />
Expand Down Expand Up @@ -282,6 +278,7 @@ const DataViewsSubComponents = DataViews as typeof DataViews & {
Pagination: typeof DataViewsPagination;
Search: typeof DataViewsSearch;
ViewConfig: typeof DataviewsViewConfigDropdown;
Footer: typeof DataViewsFooter;
};

DataViewsSubComponents.BulkActionToolbar = BulkActionsFooter;
Expand All @@ -292,5 +289,6 @@ DataViewsSubComponents.LayoutSwitcher = ViewTypeMenu;
DataViewsSubComponents.Pagination = DataViewsPagination;
DataViewsSubComponents.Search = DataViewsSearch;
DataViewsSubComponents.ViewConfig = DataviewsViewConfigDropdown;
DataViewsSubComponents.Footer = DataViewsFooter;
Copy link
Member Author

Choose a reason for hiding this comment

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

I've exported Footer as a subcomponent, as Jay suggested. I don't think I have a calibrated instinct to say if this is a good idea or not. It's better than having to use the classes, agree to that. Though I'm not sure at which point we stop making DataViews components public API. All things considered, I'm fine with going ahead with this.


export default DataViewsSubComponents;
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ export const CustomEmpty = () => {
);
};

export const MinimalUI = () => {
const MinimalUIComponent = ( {
layout = 'table',
}: {
layout: 'table' | 'list' | 'grid';
} ) => {
const [ view, setView ] = useState< View >( {
...DEFAULT_VIEW,
fields: [ 'title', 'description', 'categories' ],
Expand All @@ -165,22 +169,38 @@ export const MinimalUI = () => {
filterBy: false,
} ) );

useEffect( () => {
setView( {
...view,
type: layout as any,
} );
}, [ layout ] );

return (
<DataViews
getItemId={ ( item ) => item.id.toString() }
paginationInfo={ paginationInfo }
data={ shownData }
view={ view }
fields={ _fields }
config={ false }
search={ false }
onChangeView={ setView }
defaultLayouts={ {
table: {},
} }
/>
defaultLayouts={ { [ layout ]: {} } }
>
<DataViews.Layout />
<DataViews.Footer />
</DataViews>
);
};
export const MinimalUI = {
render: MinimalUIComponent,
argTypes: {
layout: {
control: 'select',
options: [ 'table', 'list', 'grid' ],
defaultValue: 'table',
},
},
};

/**
* Custom composition example
Expand Down
Loading