Skip to content

Commit

Permalink
DataViews: centralize control of filter visibility in the Filters com…
Browse files Browse the repository at this point in the history
…ponent (#57056)
  • Loading branch information
oandregal authored Dec 14, 2023
1 parent bcc5a9b commit 8c010bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
6 changes: 1 addition & 5 deletions packages/dataviews/src/filter-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Children, Fragment } from '@wordpress/element';
/**
* Internal dependencies
*/
import { OPERATOR_IN, OPERATOR_NOT_IN, LAYOUT_LIST } from './constants';
import { OPERATOR_IN, OPERATOR_NOT_IN } from './constants';
import { unlock } from './lock-unlock';

const {
Expand Down Expand Up @@ -73,10 +73,6 @@ function WithSeparators( { children } ) {
}

export default function FilterSummary( { filter, view, onChangeView } ) {
if ( view.type === LAYOUT_LIST ) {
return null;
}

const filterInView = view.filters.find( ( f ) => f.field === filter.field );
const activeElement = filter.elements.find(
( element ) => element.value === filterInView?.value
Expand Down
11 changes: 8 additions & 3 deletions packages/dataviews/src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import FilterSummary from './filter-summary';
import AddFilter from './add-filter';
import ResetFilters from './reset-filters';
import { ENUMERATION_TYPE, OPERATOR_IN, OPERATOR_NOT_IN } from './constants';
import {
ENUMERATION_TYPE,
OPERATOR_IN,
OPERATOR_NOT_IN,
LAYOUT_LIST,
} from './constants';

const sanitizeOperators = ( field ) => {
let operators = field.filterBy?.operators;
Expand Down Expand Up @@ -57,7 +62,7 @@ export default function Filters( { fields, view, onChangeView } ) {
const filterComponents = [
addFilter,
...filters.map( ( filter ) => {
if ( ! filter.isVisible ) {
if ( ! filter.isVisible || view.type === LAYOUT_LIST ) {
return null;
}

Expand All @@ -72,7 +77,7 @@ export default function Filters( { fields, view, onChangeView } ) {
} ),
];

if ( filterComponents.length > 1 ) {
if ( filterComponents.length > 1 && view.type !== LAYOUT_LIST ) {
filterComponents.push(
<ResetFilters
key="reset-filters"
Expand Down
9 changes: 0 additions & 9 deletions packages/dataviews/src/reset-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { LAYOUT_LIST } from './constants';

export default ( { view, onChangeView } ) => {
if ( view.type === LAYOUT_LIST ) {
return null;
}

return (
<Button
disabled={ view.search === '' && view.filters?.length === 0 }
Expand Down

1 comment on commit 8c010bd

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 8c010bd.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7208297242
📝 Reported issues:

Please sign in to comment.