Skip to content

Commit

Permalink
DataViews: load the filter toggle as open if there are primary filters (
Browse files Browse the repository at this point in the history
WordPress#64651)

Co-authored-by: oandregal <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
3 people authored and bph committed Aug 31, 2024
1 parent 26cc3d8 commit 7753eb9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/dataviews/src/components/dataviews/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export default function DataViews< Item >( {
}: DataViewsProps< Item > ) {
const [ selectionState, setSelectionState ] = useState< string[] >( [] );
const [ density, setDensity ] = useState< number >( 0 );
const [ isShowingFilter, setIsShowingFilter ] =
useState< boolean >( false );
const isUncontrolled =
selectionProperty === undefined || onChangeSelection === undefined;
const selection = isUncontrolled ? selectionState : selectionProperty;
Expand All @@ -95,6 +93,10 @@ export default function DataViews< Item >( {
}, [ selection, data, getItemId ] );

const filters = useFilters( _fields, view );
const [ isShowingFilter, setIsShowingFilter ] = useState< boolean >( () =>
( filters || [] ).some( ( filter ) => filter.isPrimary )
);

return (
<DataViewsContext.Provider
value={ {
Expand Down
7 changes: 0 additions & 7 deletions test/e2e/specs/site-editor/patterns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@ test.describe( 'Patterns', () => {

await expect( patterns.item ).toHaveCount( 3 );

await patterns.content
.getByRole( 'button', {
name: 'Toggle filter display',
exact: true,
} )
.click();

const searchBox = patterns.content.getByRole( 'searchbox', {
name: 'Search',
} );
Expand Down

0 comments on commit 7753eb9

Please sign in to comment.