Skip to content

A local-first personal finance app

Sort saved filters by alphabetical order (#1298)

Sean Tsai185daf470d50
diff --git a/packages/loot-core/src/client/data-hooks/filters.tsx b/packages/loot-core/src/client/data-hooks/filters.tsx
index 875673395f..b7b65060d4 100644
--- a/packages/loot-core/src/client/data-hooks/filters.tsx
+++ b/packages/loot-core/src/client/data-hooks/filters.tsx
@@ -1,3 +1,5 @@
+import { useMemo } from 'react';
+
import q from '../query-helpers';
import { useLiveQuery } from '../query-hooks';
@@ -16,7 +18,16 @@ function toJS(rows) {
}
export function useFilters() {
- return toJS(
+ const filters = toJS(
useLiveQuery(() => q('transaction_filters').select('*'), []) || [],
);
+
+ /** Sort filters by alphabetical order */
+ function sort(filters) {
+ return filters.sort((a, b) =>
+ a.name.trim().localeCompare(b.name.trim(), { ignorePunctuation: true }),
+ );
+ }
+
+ return useMemo(() => sort(filters), [filters]);
}
diff --git a/upcoming-release-notes/1298.md b/upcoming-release-notes/1298.md
new file mode 100644
index 0000000000..eb522257f8
--- /dev/null
+++ b/upcoming-release-notes/1298.md
@@ -0,0 +1,5 @@
+---
+category: Maintenance
+authors: [aleetsaiya]
+---
+Sort saved filters by alphabetical order
\ No newline at end of file