Skip to content

Commit

Permalink
update sanitizeOperators
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Feb 7, 2024
1 parent 6dc16b4 commit e551120
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/dataviews/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import { OPERATOR_IN, OPERATOR_NOT_IN } from './constants';
import { OPERATORS } from './constants';

/**
* Helper util to sort data by text fields, when sorting is done client side.
Expand Down Expand Up @@ -58,9 +58,9 @@ export function getPaginationResults( { data, view } ) {
export const sanitizeOperators = ( field ) => {
let operators = field.filterBy?.operators;
if ( ! operators || ! Array.isArray( operators ) ) {
operators = [ OPERATOR_IN, OPERATOR_NOT_IN ];
operators = Object.keys( OPERATORS );
}
return operators.filter( ( operator ) =>
[ OPERATOR_IN, OPERATOR_NOT_IN ].includes( operator )
Object.keys( OPERATORS ).includes( operator )
);
};
13 changes: 2 additions & 11 deletions packages/dataviews/src/view-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
import SingleSelectionCheckbox from './single-selection-checkbox';
import { unlock } from './lock-unlock';
import ItemActions from './item-actions';
import { ENUMERATION_TYPE, OPERATORS, SORTING_DIRECTIONS } from './constants';
import { sanitizeOperators } from './utils';
import { ENUMERATION_TYPE, SORTING_DIRECTIONS } from './constants';

const {
DropdownMenuV2: DropdownMenu,
Expand All @@ -55,16 +56,6 @@ function WithSeparators( { children } ) {

const sortArrows = { asc: '↑', desc: '↓' };

const sanitizeOperators = ( field ) => {
let operators = field.filterBy?.operators;
if ( ! operators || ! Array.isArray( operators ) ) {
operators = Object.keys( OPERATORS );
}
return operators.filter( ( operator ) =>
Object.keys( OPERATORS ).includes( operator )
);
};

const HeaderMenu = forwardRef( function HeaderMenu(
{ field, view, onChangeView, onHide, setOpenedFilter },
ref
Expand Down

0 comments on commit e551120

Please sign in to comment.