Skip to content

A local-first personal finance app

fix: filter empty note (#1708)

Syukron Rifa'il Muttaqi2a597fb3b85e
diff --git a/packages/loot-core/src/server/accounts/rules.ts b/packages/loot-core/src/server/accounts/rules.ts
index 635f508e1f..2d09078872 100644
--- a/packages/loot-core/src/server/accounts/rules.ts
+++ b/packages/loot-core/src/server/accounts/rules.ts
@@ -131,7 +131,7 @@ let CONDITION_TYPES = {
},
string: {
ops: ['is', 'contains', 'oneOf', 'isNot', 'doesNotContain', 'notOneOf'],
- nullable: false,
+ nullable: true,
parse(op, value, fieldName) {
if (op === 'oneOf' || op === 'notOneOf') {
assert(
diff --git a/packages/loot-core/src/server/accounts/transaction-rules.test.ts b/packages/loot-core/src/server/accounts/transaction-rules.test.ts
index 50211264f6..9827e5cd2c 100644
--- a/packages/loot-core/src/server/accounts/transaction-rules.test.ts
+++ b/packages/loot-core/src/server/accounts/transaction-rules.test.ts
@@ -402,6 +402,22 @@ describe('Transaction rules', () => {
notes: 'FooO',
amount: -322,
});
+ await db.insertTransaction({
+ id: '4',
+ date: '2020-10-16',
+ account,
+ payee: lowesId,
+ notes: null,
+ amount: 101,
+ });
+ await db.insertTransaction({
+ id: '5',
+ date: '2020-10-16',
+ account,
+ payee: lowesId,
+ notes: '',
+ amount: 124,
+ });
let transactions = await getMatchingTransactions([
{ field: 'date', op: 'is', value: '2020-10-15' },
@@ -411,7 +427,7 @@ describe('Transaction rules', () => {
transactions = await getMatchingTransactions([
{ field: 'payee', op: 'is', value: lowesId },
]);
- expect(transactions.map(t => t.id)).toEqual(['3']);
+ expect(transactions.map(t => t.id)).toEqual(['4', '5', '3']);
transactions = await getMatchingTransactions([
{ field: 'amount', op: 'is', value: 353 },
@@ -433,6 +449,11 @@ describe('Transaction rules', () => {
]);
expect(transactions.map(t => t.id)).toEqual(['2', '3', '1']);
+ transactions = await getMatchingTransactions([
+ { field: 'notes', op: 'is', value: '' },
+ ]);
+ expect(transactions.map(t => t.id)).toEqual(['4', '5']);
+
transactions = await getMatchingTransactions([
{ field: 'amount', op: 'gt', value: 300 },
]);
@@ -454,7 +475,7 @@ describe('Transaction rules', () => {
transactions = await getMatchingTransactions([
{ field: 'amount', op: 'gt', value: -1000, options: { inflow: true } },
]);
- expect(transactions.map(t => t.id)).toEqual(['2', '1']);
+ expect(transactions.map(t => t.id)).toEqual(['4', '5', '2', '1']);
// Same thing for `outflow`: never return `inflow` transactions
transactions = await getMatchingTransactions([
@@ -465,7 +486,7 @@ describe('Transaction rules', () => {
transactions = await getMatchingTransactions([
{ field: 'date', op: 'gt', value: '2020-10-10' },
]);
- expect(transactions.map(t => t.id)).toEqual(['2', '3']);
+ expect(transactions.map(t => t.id)).toEqual(['4', '5', '2', '3']);
// todo: isapprox
});
diff --git a/packages/loot-core/src/server/accounts/transaction-rules.ts b/packages/loot-core/src/server/accounts/transaction-rules.ts
index 758d7f44bb..4761375a32 100644
--- a/packages/loot-core/src/server/accounts/transaction-rules.ts
+++ b/packages/loot-core/src/server/accounts/transaction-rules.ts
@@ -419,6 +419,12 @@ export function conditionsToAQL(conditions, { recurDateBounds = 100 } = {}) {
};
}
return apply(field, '$eq', number);
+ } else if (type === 'string') {
+ if (value === '') {
+ return {
+ $or: [apply(field, '$eq', null), apply(field, '$eq', '')],
+ };
+ }
}
return apply(field, '$eq', value);
case 'isNot':
diff --git a/packages/loot-core/src/shared/rules.ts b/packages/loot-core/src/shared/rules.ts
index 53b143d61a..d0fa730a44 100644
--- a/packages/loot-core/src/shared/rules.ts
+++ b/packages/loot-core/src/shared/rules.ts
@@ -17,7 +17,7 @@ export const TYPE_INFO = {
},
string: {
ops: ['is', 'contains', 'oneOf', 'isNot', 'doesNotContain', 'notOneOf'],
- nullable: false,
+ nullable: true,
},
number: {
ops: ['is', 'isapprox', 'isbetween', 'gt', 'gte', 'lt', 'lte'],
diff --git a/upcoming-release-notes/1708.md b/upcoming-release-notes/1708.md
new file mode 100644
index 0000000000..faae4287d4
--- /dev/null
+++ b/upcoming-release-notes/1708.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [syukronrm]
+---
+
+fixing filter transaction to show empty note instead of showing error "Value cannot be empty"