Skip to content

Commit

Permalink
feat: keep entered filter value when changing filter operator (#2313)
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy committed Oct 9, 2022
1 parent 8e60931 commit d6d38bf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/Filter/Filter.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ import stringCompare from 'lib/stringCompare';
import { CurrentApp } from 'context/currentApp';

function changeField(schema, filters, index, newField) {
let newFilter = new Map({
const allowedConstraints = Filters.FieldConstraints[schema[newField].type];
const current = filters.get(index);
const constraint = current.get('constraint');
const compare = current.get('compareTo');
const defaultCompare = Filters.DefaultComparisons[schema[newField].type];
const useExisting = allowedConstraints.includes(constraint);
const newFilter = new Map({
field: newField,
constraint: Filters.FieldConstraints[schema[newField].type][0],
compareTo: Filters.DefaultComparisons[schema[newField].type]
constraint: useExisting ? constraint : Filters.FieldConstraints[schema[newField].type][0],
compareTo: (useExisting && typeof defaultCompare === typeof compare) ? compare : defaultCompare
});
return filters.set(index, newFilter);
}
Expand Down

0 comments on commit d6d38bf

Please sign in to comment.