Skip to content

A local-first personal finance app

fix filter transactions by closed account transfer payee (#5438)

Julian116c6959649b
diff --git a/eslint.config.mjs b/eslint.config.mjs
index eea22bda24..ed924be4d3 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -457,6 +457,7 @@ export default pluginTypescript.config(
'warn',
{
varsIgnorePattern: '^(_|React)',
+ argsIgnorePattern: '^(_|React)',
ignoreRestSiblings: true,
caughtErrors: 'none',
},
diff --git a/packages/desktop-client/src/components/FixedSizeList.tsx b/packages/desktop-client/src/components/FixedSizeList.tsx
index aaa2775219..e82b50e648 100644
--- a/packages/desktop-client/src/components/FixedSizeList.tsx
+++ b/packages/desktop-client/src/components/FixedSizeList.tsx
@@ -477,7 +477,6 @@ export class FixedSizeList extends PureComponent<
return style;
};
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
_getItemStyleCache = memoizeOne((_, __, ___) => ({}));
_getRangeToRender() {
diff --git a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
index ab3785a3be..b05f79386b 100644
--- a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
@@ -88,16 +88,13 @@ function getPayeeSuggestions(
function filterActivePayees(
payees: PayeeAutocompleteItem[],
- focusTransferPayees: boolean,
accounts: AccountEntity[],
) {
- let activePayees = accounts ? getActivePayees(payees, accounts) : payees;
-
- if (focusTransferPayees && activePayees) {
- activePayees = activePayees.filter(p => !!p.transfer_acct);
- }
+ return accounts ? getActivePayees(payees, accounts) : payees;
+}
- return activePayees || [];
+function filterTransferPayees(payees: PayeeAutocompleteItem[]) {
+ return payees.filter(payee => !!payee.transfer_acct);
}
function makeNew(id, rawPayee) {
@@ -256,6 +253,7 @@ function PayeeList({
export type PayeeAutocompleteProps = ComponentProps<
typeof Autocomplete<PayeeAutocompleteItem>
> & {
+ showInactivePayees?: boolean;
showMakeTransfer?: boolean;
showManagePayees?: boolean;
embedded?: boolean;
@@ -276,6 +274,7 @@ export type PayeeAutocompleteProps = ComponentProps<
export function PayeeAutocomplete({
value,
inputProps,
+ showInactivePayees = false,
showMakeTransfer = true,
showManagePayees = false,
clearOnBlur = true,
@@ -307,18 +306,30 @@ export function PayeeAutocomplete({
const hasPayeeInput = !!rawPayee;
const payeeSuggestions: PayeeAutocompleteItem[] = useMemo(() => {
const suggestions = getPayeeSuggestions(commonPayees, payees);
- const filteredSuggestions = filterActivePayees(
- suggestions,
- focusTransferPayees,
- accounts,
- );
+
+ let filteredSuggestions: PayeeAutocompleteItem[] = [...suggestions];
+
+ if (!showInactivePayees) {
+ filteredSuggestions = filterActivePayees(filteredSuggestions, accounts);
+ }
+
+ if (focusTransferPayees) {
+ filteredSuggestions = filterTransferPayees(filteredSuggestions);
+ }
if (!hasPayeeInput) {
return filteredSuggestions;
}
return [{ id: 'new', favorite: false, name: '' }, ...filteredSuggestions];
- }, [commonPayees, payees, focusTransferPayees, accounts, hasPayeeInput]);
+ }, [
+ commonPayees,
+ payees,
+ focusTransferPayees,
+ accounts,
+ hasPayeeInput,
+ showInactivePayees,
+ ]);
const dispatch = useDispatch();
diff --git a/packages/desktop-client/src/components/filters/FiltersMenu.jsx b/packages/desktop-client/src/components/filters/FiltersMenu.jsx
index 6835af0503..7f59fecab2 100644
--- a/packages/desktop-client/src/components/filters/FiltersMenu.jsx
+++ b/packages/desktop-client/src/components/filters/FiltersMenu.jsx
@@ -35,6 +35,7 @@ import { titleFirst } from 'loot-core/shared/util';
import { CompactFiltersButton } from './CompactFiltersButton';
import { FiltersButton } from './FiltersButton';
import { OpButton } from './OpButton';
+import { PayeeFilter } from './PayeeFilter';
import { subfieldFromFilter } from './subfieldFromFilter';
import { subfieldToOptions } from './subfieldToOptions';
import { updateFilterReducer } from './updateFilterReducer';
@@ -229,7 +230,7 @@ function ConfigureField({
});
}}
>
- {type !== 'boolean' && (
+ {type !== 'boolean' && field !== 'payee' && (
<GenericInput
ref={inputRef}
field={field}
@@ -253,6 +254,14 @@ function ConfigureField({
/>
)}
+ {field === 'payee' && (
+ <PayeeFilter
+ value={formattedValue}
+ op={op}
+ onChange={v => dispatch({ type: 'set-value', value: v })}
+ />
+ )}
+
<Stack
direction="row"
justify="flex-end"
diff --git a/packages/desktop-client/src/components/filters/PayeeFilter.tsx b/packages/desktop-client/src/components/filters/PayeeFilter.tsx
new file mode 100644
index 0000000000..1b00eb1cfe
--- /dev/null
+++ b/packages/desktop-client/src/components/filters/PayeeFilter.tsx
@@ -0,0 +1,62 @@
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+
+import {
+ PayeeAutocomplete,
+ type PayeeAutocompleteItem,
+} from '@desktop-client/components/autocomplete/PayeeAutocomplete';
+
+type PayeeFilterValue =
+ | PayeeAutocompleteItem['id']
+ | PayeeAutocompleteItem['id'][];
+
+/** This component only supports single- or multi-select operations. */
+type PayeeFilterOp = 'is' | 'isNot' | 'oneOf' | 'notOneOf';
+
+type PayeeFilterProps = {
+ /** The selected value(s) of the filter. This is a controlled component. */
+ value: PayeeFilterValue;
+
+ /** To determine the use of a single- or multi-select input. */
+ op: PayeeFilterOp;
+
+ /** Called whenever the selected value(s) of the filter change. */
+ onChange: (value: PayeeFilterValue) => void;
+};
+
+/**
+ * Component to filter on payee.
+ *
+ * This component also shows "inactive" payees, specifically meant for transfer payees
+ * whose account are closed. This lets the end-user filter transactions (among others)
+ * based on transfer payees of closed accounts.
+ */
+export const PayeeFilter = ({ value, op, onChange }: PayeeFilterProps) => {
+ const { t } = useTranslation();
+ const multi = ['oneOf', 'notOneOf'].includes(op);
+
+ let coercedValue: PayeeFilterValue = value;
+ if (multi) {
+ coercedValue = Array.isArray(value) ? value : [];
+ } else {
+ coercedValue = Array.isArray(value) ? (value[0] ?? null) : value;
+ }
+
+ const placeholder =
+ multi && coercedValue.length > 0 ? undefined : t('nothing');
+
+ return (
+ // @ts-ignore: typing is not playing nicely with the union type of AutocompleteProps.
+ <PayeeAutocomplete
+ type={multi ? 'multi' : 'single'}
+ showInactivePayees={true}
+ showMakeTransfer={false}
+ openOnFocus={true}
+ value={coercedValue}
+ inputProps={{ placeholder }}
+ onSelect={(payeeIdOrIds: string | string[], _: string) =>
+ onChange(payeeIdOrIds)
+ }
+ />
+ );
+};
diff --git a/upcoming-release-notes/5438.md b/upcoming-release-notes/5438.md
new file mode 100644
index 0000000000..79e227b893
--- /dev/null
+++ b/upcoming-release-notes/5438.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [Serializator]
+---
+
+Allow filter based on transfer payee from closed account