Memoize external accounts for bank sync (#4540)

* Memoize external accounts

* md
This commit is contained in:
lelemm
2025-03-05 12:23:08 -03:00
committed by GitHub
parent 84e4cda6ad
commit 1fed3ebbd7
2 changed files with 15 additions and 4 deletions

View File

@@ -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';
@@ -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);
@@ -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;
@@ -176,7 +181,7 @@ export function SelectLinkedAccountsModal({
/>
<Table
items={externalAccounts}
items={sortedExternalAccounts}
style={{ backgroundColor: theme.tableHeaderBackground }}
getItemKey={index => index}
renderItem={({ key, item }) => (

View File

@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [lelemm]
---
Memoize external accounts for bank sync modal