From 78aab807034b21253b1a63455dd768f0c31cee42 Mon Sep 17 00:00:00 2001 From: Qstick Date: Wed, 31 May 2023 19:33:28 -0500 Subject: [PATCH] New: Additional custom filter predicates for strings --- .../src/Helpers/Props/filterBuilderTypes.js | 18 +++++++++++++++++- .../src/Helpers/Props/filterTypePredicates.js | 16 ++++++++++++++++ frontend/src/Helpers/Props/filterTypes.js | 10 +++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/frontend/src/Helpers/Props/filterBuilderTypes.js b/frontend/src/Helpers/Props/filterBuilderTypes.js index 776ba2afc..c0806fabc 100644 --- a/frontend/src/Helpers/Props/filterBuilderTypes.js +++ b/frontend/src/Helpers/Props/filterBuilderTypes.js @@ -1,14 +1,18 @@ import * as filterTypes from './filterTypes'; export const ARRAY = 'array'; +export const CONTAINS = 'contains'; export const DATE = 'date'; +export const EQUAL = 'equal'; export const EXACT = 'exact'; export const NUMBER = 'number'; export const STRING = 'string'; export const all = [ ARRAY, + CONTAINS, DATE, + EQUAL, EXACT, NUMBER, STRING @@ -20,6 +24,10 @@ export const possibleFilterTypes = { { key: filterTypes.NOT_CONTAINS, value: 'does not contain' } ], + [CONTAINS]: [ + { key: filterTypes.CONTAINS, value: 'contains' } + ], + [DATE]: [ { key: filterTypes.LESS_THAN, value: 'is before' }, { key: filterTypes.GREATER_THAN, value: 'is after' }, @@ -29,6 +37,10 @@ export const possibleFilterTypes = { { key: filterTypes.NOT_IN_NEXT, value: 'not in the next' } ], + [EQUAL]: [ + { key: filterTypes.EQUAL, value: 'is' } + ], + [EXACT]: [ { key: filterTypes.EQUAL, value: 'is' }, { key: filterTypes.NOT_EQUAL, value: 'is not' } @@ -47,6 +59,10 @@ export const possibleFilterTypes = { { key: filterTypes.CONTAINS, value: 'contains' }, { key: filterTypes.NOT_CONTAINS, value: 'does not contain' }, { key: filterTypes.EQUAL, value: 'equal' }, - { key: filterTypes.NOT_EQUAL, value: 'not equal' } + { key: filterTypes.NOT_EQUAL, value: 'not equal' }, + { key: filterTypes.STARTS_WITH, value: 'starts with' }, + { key: filterTypes.NOT_STARTS_WITH, value: 'does not start with' }, + { key: filterTypes.ENDS_WITH, value: 'ends with' }, + { key: filterTypes.NOT_ENDS_WITH, value: 'does not end with' } ] }; diff --git a/frontend/src/Helpers/Props/filterTypePredicates.js b/frontend/src/Helpers/Props/filterTypePredicates.js index a3ea11956..d07059c02 100644 --- a/frontend/src/Helpers/Props/filterTypePredicates.js +++ b/frontend/src/Helpers/Props/filterTypePredicates.js @@ -39,6 +39,22 @@ const filterTypePredicates = { [filterTypes.NOT_EQUAL]: function(itemValue, filterValue) { return itemValue !== filterValue; + }, + + [filterTypes.STARTS_WITH]: function(itemValue, filterValue) { + return itemValue.toLowerCase().startsWith(filterValue.toLowerCase()); + }, + + [filterTypes.NOT_STARTS_WITH]: function(itemValue, filterValue) { + return !itemValue.toLowerCase().startsWith(filterValue.toLowerCase()); + }, + + [filterTypes.ENDS_WITH]: function(itemValue, filterValue) { + return itemValue.toLowerCase().endsWith(filterValue.toLowerCase()); + }, + + [filterTypes.NOT_ENDS_WITH]: function(itemValue, filterValue) { + return !itemValue.toLowerCase().endsWith(filterValue.toLowerCase()); } }; diff --git a/frontend/src/Helpers/Props/filterTypes.js b/frontend/src/Helpers/Props/filterTypes.js index 993e8df57..239a4e7e9 100644 --- a/frontend/src/Helpers/Props/filterTypes.js +++ b/frontend/src/Helpers/Props/filterTypes.js @@ -10,6 +10,10 @@ export const LESS_THAN = 'lessThan'; export const LESS_THAN_OR_EQUAL = 'lessThanOrEqual'; export const NOT_CONTAINS = 'notContains'; export const NOT_EQUAL = 'notEqual'; +export const STARTS_WITH = 'startsWith'; +export const NOT_STARTS_WITH = 'notStartsWith'; +export const ENDS_WITH = 'endsWith'; +export const NOT_ENDS_WITH = 'notEndsWith'; export const all = [ CONTAINS, @@ -23,5 +27,9 @@ export const all = [ IN_LAST, NOT_IN_LAST, IN_NEXT, - NOT_IN_NEXT + NOT_IN_NEXT, + STARTS_WITH, + NOT_STARTS_WITH, + ENDS_WITH, + NOT_ENDS_WITH ];