Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Memoize external accounts for bank sync #4540

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import { useTranslation, Trans } from 'react-i18next';

import { Button } from '@actual-app/components/button';
Expand Down Expand Up @@ -41,7 +41,12 @@ export function SelectLinkedAccountsModal({
externalAccounts,
syncSource = undefined,
}) {
externalAccounts.sort((a, b) => a.name.localeCompare(b.name));
const sortedExternalAccounts = useMemo(() => {
const toSort = [...externalAccounts];
toSort.sort((a, b) => a.name.localeCompare(b.name));
return toSort;
}, [externalAccounts]);

const { t } = useTranslation();
const dispatch = useDispatch();
const localAccounts = useAccounts().filter(a => a.closed === 0);
Expand All @@ -68,7 +73,7 @@ export function SelectLinkedAccountsModal({
// Link new accounts
Object.entries(chosenAccounts).forEach(
([chosenExternalAccountId, chosenLocalAccountId]) => {
const externalAccount = externalAccounts.find(
const externalAccount = sortedExternalAccounts.find(
account => account.account_id === chosenExternalAccountId,
);
const offBudget = chosenLocalAccountId === addOffBudgetAccountOption.id;
Expand Down Expand Up @@ -176,7 +181,7 @@ export function SelectLinkedAccountsModal({
/>

<Table
items={externalAccounts}
items={sortedExternalAccounts}
style={{ backgroundColor: theme.tableHeaderBackground }}
getItemKey={index => index}
renderItem={({ key, item }) => (
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4540.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [lelemm]
---

Memoize external accounts for bank sync modal