Skip to content

Commit f4c3060

Browse files
authored
fix: preserve previous condition field value on constraint change (#1969)
1 parent e87bb6f commit f4c3060

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/components/BrowserFilter/BrowserFilter.react.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ export default class BrowserFilter extends React.Component {
7878
if (Filters.Constraints[filter.get('constraint')].hasOwnProperty('field')) {
7979
type = Filters.Constraints[filter.get('constraint')].field;
8080
}*/
81+
82+
// since we are preserving previous compareTo value
83+
// remove compareTo for constraints which are not comparable
84+
let isComparable = Filters.Constraints[filter.get('constraint')].comparable;
85+
if (!isComparable) {
86+
return filter.delete('compareTo')
87+
}
8188
return filter;
8289
});
8390
this.props.onChange(formatted);

src/components/BrowserFilter/FilterRow.react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let FilterRow = ({
101101
color={active ? 'blue' : 'purple'}
102102
value={Constraints[currentConstraint].name}
103103
options={constraints.map((c) => Constraints[c].name)}
104-
onChange={(c) => onChangeConstraint(constraintLookup[c])} />
104+
onChange={(c) => onChangeConstraint(constraintLookup[c], compareTo)} />
105105
{compareValue(compareInfo, compareTo, onChangeCompareTo, active, parentContentId)}
106106
<button type='button' className={styles.remove} onClick={onDeleteRow}><Icon name='minus-solid' width={14} height={14} fill='rgba(0,0,0,0.4)' /></button>
107107
</div>

src/components/Filter/Filter.react.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function changeField(schema, filters, index, newField) {
2121
return filters.set(index, newFilter);
2222
}
2323

24-
function changeConstraint(schema, filters, index, newConstraint) {
24+
function changeConstraint(schema, filters, index, newConstraint, prevCompareTo) {
2525
let field = filters.get(index).get('field');
2626
let compareType = schema[field].type;
2727
if (Object.prototype.hasOwnProperty.call(Filters.Constraints[newConstraint], 'field')) {
@@ -30,7 +30,7 @@ function changeConstraint(schema, filters, index, newConstraint) {
3030
let newFilter = new Map({
3131
field: field,
3232
constraint: newConstraint,
33-
compareTo: Filters.DefaultComparisons[compareType]
33+
compareTo: prevCompareTo ?? Filters.DefaultComparisons[compareType]
3434
})
3535
return filters.set(index, newFilter);
3636
}
@@ -110,8 +110,8 @@ let Filter = ({ schema, filters, renderRow, onChange, blacklist, className }) =>
110110
onChangeField: newField => {
111111
onChange(changeField(schema, filters, i, newField));
112112
},
113-
onChangeConstraint: newConstraint => {
114-
onChange(changeConstraint(schema, filters, i, newConstraint));
113+
onChangeConstraint: (newConstraint, prevCompareTo) => {
114+
onChange(changeConstraint(schema, filters, i, newConstraint, prevCompareTo));
115115
},
116116
onChangeCompareTo: newCompare => {
117117
onChange(changeCompareTo(schema, filters, i, compareType, newCompare));

0 commit comments

Comments
 (0)