Skip to content

Commit

Permalink
Fix regression in case sensitivity for is/matches operator (#3399)
Browse files Browse the repository at this point in the history
* Fix regression in case sensitivity for `is`/`matches` operators

* Add test

* Add release notes

* Fix failing tests

---------

Co-authored-by: youngcw <calebyoung94@gmail.com>
  • Loading branch information
jfdoming and youngcw authored Sep 28, 2024
1 parent f79edf8 commit 545c8d5
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 350 deletions.
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 @@ -580,14 +581,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 @@ -654,7 +656,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);

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

0 comments on commit 545c8d5

Please sign in to comment.