Skip to content

Commit d6d38bf

Browse files
authored
feat: keep entered filter value when changing filter operator (#2313)
1 parent 8e60931 commit d6d38bf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/Filter/Filter.react.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ import stringCompare from 'lib/stringCompare';
1313
import { CurrentApp } from 'context/currentApp';
1414

1515
function changeField(schema, filters, index, newField) {
16-
let newFilter = new Map({
16+
const allowedConstraints = Filters.FieldConstraints[schema[newField].type];
17+
const current = filters.get(index);
18+
const constraint = current.get('constraint');
19+
const compare = current.get('compareTo');
20+
const defaultCompare = Filters.DefaultComparisons[schema[newField].type];
21+
const useExisting = allowedConstraints.includes(constraint);
22+
const newFilter = new Map({
1723
field: newField,
18-
constraint: Filters.FieldConstraints[schema[newField].type][0],
19-
compareTo: Filters.DefaultComparisons[schema[newField].type]
24+
constraint: useExisting ? constraint : Filters.FieldConstraints[schema[newField].type][0],
25+
compareTo: (useExisting && typeof defaultCompare === typeof compare) ? compare : defaultCompare
2026
});
2127
return filters.set(index, newFilter);
2228
}

0 commit comments

Comments
 (0)