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 and artemiomorales committed Jan 4, 2024
1 parent 8173116 commit 39936f3
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

0 comments on commit 39936f3

Please sign in to comment.