Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve previous condition field value on constraint change #1969

Merged
merged 7 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/BrowserFilter/BrowserFilter.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export default class BrowserFilter extends React.Component {
if (Filters.Constraints[filter.get('constraint')].hasOwnProperty('field')) {
type = Filters.Constraints[filter.get('constraint')].field;
}*/

// since we are preserving previous compareTo value
// remove compareTo for constraints which are not comparable
let isComparable = Filters.Constraints[filter.get('constraint')].comparable;
if (!isComparable) {
return filter.delete('compareTo')
}
return filter;
});
this.props.onChange(formatted);
Expand Down
2 changes: 1 addition & 1 deletion src/components/BrowserFilter/FilterRow.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ let FilterRow = ({
color={active ? 'blue' : 'purple'}
value={Constraints[currentConstraint].name}
options={constraints.map((c) => Constraints[c].name)}
onChange={(c) => onChangeConstraint(constraintLookup[c])} />
onChange={(c) => onChangeConstraint(constraintLookup[c], compareTo)} />
{compareValue(compareInfo, compareTo, onChangeCompareTo, active, parentContentId)}
<button type='button' className={styles.remove} onClick={onDeleteRow}><Icon name='minus-solid' width={14} height={14} fill='rgba(0,0,0,0.4)' /></button>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Filter/Filter.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function changeField(schema, filters, index, newField) {
return filters.set(index, newFilter);
}

function changeConstraint(schema, filters, index, newConstraint) {
function changeConstraint(schema, filters, index, newConstraint, prevCompareTo) {
let field = filters.get(index).get('field');
let compareType = schema[field].type;
if (Object.prototype.hasOwnProperty.call(Filters.Constraints[newConstraint], 'field')) {
Expand All @@ -30,7 +30,7 @@ function changeConstraint(schema, filters, index, newConstraint) {
let newFilter = new Map({
field: field,
constraint: newConstraint,
compareTo: Filters.DefaultComparisons[compareType]
compareTo: prevCompareTo ?? Filters.DefaultComparisons[compareType]
})
return filters.set(index, newFilter);
}
Expand Down Expand Up @@ -110,8 +110,8 @@ let Filter = ({ schema, filters, renderRow, onChange, blacklist, className }) =>
onChangeField: newField => {
onChange(changeField(schema, filters, i, newField));
},
onChangeConstraint: newConstraint => {
onChange(changeConstraint(schema, filters, i, newConstraint));
onChangeConstraint: (newConstraint, prevCompareTo) => {
onChange(changeConstraint(schema, filters, i, newConstraint, prevCompareTo));
},
onChangeCompareTo: newCompare => {
onChange(changeCompareTo(schema, filters, i, compareType, newCompare));
Expand Down