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 regression in case sensitivity for is/matches operator #3399

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getFieldError,
unparse,
FIELD_TYPES,
TYPE_INFO,
getValidOps,
} from 'loot-core/src/shared/rules';
import { titleFirst } from 'loot-core/src/shared/util';

Expand Down Expand Up @@ -77,7 +77,7 @@ function ConfigureField({
}, [op]);

const type = FIELD_TYPES.get(field);
let ops = TYPE_INFO[type].ops.filter(op => op !== 'isbetween');
let ops = getValidOps(field).filter(op => op !== 'isbetween');

// Month and year fields are quite hacky right now! Figure out how
// to clean this up later
Expand Down Expand Up @@ -259,7 +259,7 @@ export function FilterButton({ onApply, compact, hover, exclude }) {
case 'configure': {
const { field } = deserializeField(action.field);
const type = FIELD_TYPES.get(field);
const ops = TYPE_INFO[type].ops;
const ops = getValidOps(field);
return {
...state,
fieldsOpen: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function updateFilterReducer(
switch (action.type) {
case 'set-op': {
const type = FIELD_TYPES.get(state.field);
let value = state.value;
let value: RuleConditionEntity['value'] | null = state.value;
if (
(type === 'id' || type === 'string') &&
(action.op === 'contains' ||
Expand Down
10 changes: 6 additions & 4 deletions packages/desktop-client/src/components/modals/EditRuleModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import {
unparse,
makeValue,
FIELD_TYPES,
TYPE_INFO,
ALLOCATION_METHODS,
isValidOp,
getValidOps,
} from 'loot-core/src/shared/rules';
import {
integerToCurrency,
Expand Down Expand Up @@ -577,14 +578,15 @@ function ConditionsList({
if (
(prevType === 'string' || prevType === 'number') &&
prevType === newCond.type &&
cond.op !== 'isbetween'
cond.op !== 'isbetween' &&
isValidOp(newCond.field, cond.op)
) {
// Don't clear the value & op if the type is string/number and
// the type hasn't changed
newCond.op = cond.op;
return newInput(makeValue(cond.value, newCond));
} else {
newCond.op = TYPE_INFO[newCond.type].ops[0];
newCond.op = getValidOps(newCond.field)[0];
return newInput(makeValue(null, newCond));
}
} else if (field === 'op') {
Expand Down Expand Up @@ -651,7 +653,7 @@ function ConditionsList({
) : (
<Stack spacing={2} data-testid="condition-list">
{conditions.map((cond, i) => {
let ops = TYPE_INFO[cond.type].ops;
let ops = getValidOps(cond.field);
Copy link
Contributor

@coderabbitai coderabbitai bot Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use getValidOps consistently.

Consider using getValidOps consistently to retrieve valid operations for all condition fields instead of having a separate hack for recurring dates and amount inflow/outflow. This would make the code more maintainable and less error-prone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done in a separate refactor, but right now there is no way for getValidOps to perform op-specific logic. The change would also need additional testing that I don't want to add to an already-large PR. But thanks for the suggestion! I made a note of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfdoming, I understand. Deferring this change to a separate refactor makes sense to keep this PR focused. Thank you for considering the suggestion.

(_/)
( ..)
(")
(")


// Hack for now, these ops should be the only ones available
// for recurring dates
Expand Down
Loading
Loading