Skip to content

A local-first personal finance app

[AI] Fix category autocomplete keyboard selection (#8570)

Harsh Mathur008c60942405
diff --git a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-7-chromium-linux.png b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-7-chromium-linux.png
index 7a9c18849f..e56785af31 100644
Binary files a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-7-chromium-linux.png and b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-7-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-8-chromium-linux.png b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-8-chromium-linux.png
index ffd8d9b3f0..0aac0412e3 100644
Binary files a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-8-chromium-linux.png and b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-8-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-9-chromium-linux.png b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-9-chromium-linux.png
index bf2939a413..73c5735002 100644
Binary files a/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-9-chromium-linux.png and b/packages/desktop-client/e2e/transactions.test.ts-snapshots/Transactions-filters-transactions-by-category-9-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
index 8eeebb4924..ac512b2132 100644
--- a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
@@ -73,52 +73,17 @@ function CategoryList({
showBalances,
}: CategoryListProps) {
const { t } = useTranslation();
- const { splitTransaction, groupedCategories } = useMemo(() => {
- return items.reduce(
- (acc, item, index) => {
- if (item.id === 'split') {
- acc.splitTransaction = { ...item, highlightedIndex: index };
- return acc;
- }
-
- const groupId = item.group?.id || '';
- const existing = acc.groupedCategories.find(
- x => x.group?.id === groupId,
- );
- const itemWithIndex = {
- ...item,
- highlightedIndex: index,
+ const splitTransactionIndex = items.findIndex(item => item.id === 'split');
+ const splitTransaction =
+ splitTransactionIndex === -1
+ ? null
+ : {
+ ...items[splitTransactionIndex],
+ highlightedIndex: splitTransactionIndex,
};
-
- if (!existing) {
- acc.groupedCategories.push({
- group: item.group ?? null,
- categories: [itemWithIndex],
- });
- } else {
- existing.categories.push(itemWithIndex);
- }
-
- return acc;
- },
- {
- splitTransaction: null,
- groupedCategories: [],
- } as {
- splitTransaction:
- | (CategoryAutocompleteItem & {
- highlightedIndex: number;
- })
- | null;
- groupedCategories: Array<{
- group: CategoryGroupEntity | null;
- categories: Array<
- CategoryAutocompleteItem & { highlightedIndex: number }
- >;
- }>;
- },
- );
- }, [items]);
+ const categoryItems = items
+ .map((item, index) => ({ ...item, highlightedIndex: index }))
+ .filter(item => item.id !== 'split');
return (
<View>
@@ -145,37 +110,39 @@ function CategoryList({
embedded,
});
})()}
- {groupedCategories.map(({ group, categories }) => {
+ {categoryItems.map((item, index) => {
+ const group = item.group;
+
if (!group) {
return null;
}
+ const previousGroup = categoryItems[index - 1]?.group;
+ const showGroupHeader = previousGroup?.id !== group.id;
+
return (
- <Fragment key={group.id}>
- {renderCategoryItemGroupHeader({
- title: `${group.name}${group.hidden ? ` ${t('(hidden)')}` : ''}`,
+ <Fragment key={item.id}>
+ {showGroupHeader &&
+ renderCategoryItemGroupHeader({
+ title: `${group.name}${group.hidden ? ` ${t('(hidden)')}` : ''}`,
+ style: {
+ ...(showHiddenItems &&
+ group.hidden && { color: theme.pageTextSubdued }),
+ },
+ })}
+ {renderCategoryItem({
+ ...(getItemProps ? getItemProps({ item }) : {}),
+ item,
+ highlighted: highlightedIndex === item.highlightedIndex,
+ embedded,
style: {
...(showHiddenItems &&
- group.hidden && { color: theme.pageTextSubdued }),
+ (item.hidden || group.hidden) && {
+ color: theme.pageTextSubdued,
+ }),
},
+ showBalances,
})}
- {categories.map(item => (
- <Fragment key={item.id}>
- {renderCategoryItem({
- ...(getItemProps ? getItemProps({ item }) : {}),
- item,
- highlighted: highlightedIndex === item.highlightedIndex,
- embedded,
- style: {
- ...(showHiddenItems &&
- (item.hidden || group.hidden) && {
- color: theme.pageTextSubdued,
- }),
- },
- showBalances,
- })}
- </Fragment>
- ))}
</Fragment>
);
})}
diff --git a/upcoming-release-notes/fix-category-autocomplete-keyboard-selection.md b/upcoming-release-notes/fix-category-autocomplete-keyboard-selection.md
new file mode 100644
index 0000000000..4d59af5c5e
--- /dev/null
+++ b/upcoming-release-notes/fix-category-autocomplete-keyboard-selection.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [harshmathurx]
+---
+
+Fix category autocomplete keyboard selection to match the highlighted item