Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataViews: centralize control of filter visibility in the Filters component #57056

Merged
merged 1 commit into from
Dec 14, 2023
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
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
Loading