How to update the operator of a condition inside a CustomOperatorSelector #982
-
|
I have a export function CustomOperatorSelector(props: OperatorSelectorProps) {
const { rule, options, value, schema, path } = props;
// Determine required operator based on rule value's aggregation type
let requiredOperator: string | null = null;
if (rule.value && typeof rule.value === 'object' && 'mode' in rule.value) {
const numValue = rule.value as NumericRuleValue;
if (numValue.mode === 'agg') {
if (numValue.agg === 'min') {
requiredOperator = 'num.gt'; // min → only allow > (price greater than minimum)
} else if (numValue.agg === 'max') {
requiredOperator = 'num.lt'; // max → only allow < (price less than maximum)
}
}
}
// Filter options if there's a required operator
const filteredOptions: FullOptionList<FullOperator> = requiredOperator
? options.filter((op): op is FullOperator => !('options' in op) && op.name === requiredOperator)
: options;
// Auto-correct operator if current value doesn't match required
// HOW DO I DO THIS?
onPropChange('operator', requiredOperator, path);
}, [requiredOperator, value, schema.actions, path]);
return (
<MaterialValueSelector {...props} options={filteredOptions} variant="outlined" size="small" />
);
}The problem is that after selecting the operator, the query might be in a bad "state" because the "old" operator might not be compatible with the new value. I want to change the operator in the current query. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Can you go through this page and see if it helps? https://react-querybuilder.js.org/docs/tips/arbitrary-updates If not, or you need further assistance, let me know. |
Beta Was this translation helpful? Give feedback.
Can you go through this page and see if it helps?
https://react-querybuilder.js.org/docs/tips/arbitrary-updates
If not, or you need further assistance, let me know.