From 6979a2abaa9801c279e1e0866cf0f83ffe945f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Thu, 28 Jun 2018 15:02:35 +0200 Subject: [PATCH] fix weird glitch on Select/Unselect feature when selecting a New --- src/components/base/AccountsList/index.js | 14 +++++++++++--- .../modals/AddAccounts/steps/03-step-import.js | 13 +++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/base/AccountsList/index.js b/src/components/base/AccountsList/index.js index 6300a0b4..3dc55fdf 100644 --- a/src/components/base/AccountsList/index.js +++ b/src/components/base/AccountsList/index.js @@ -18,8 +18,8 @@ class AccountsList extends Component< editedNames: { [accountId: string]: string }, setAccountName?: (Account, string) => void, onToggleAccount?: Account => void, - onSelectAll?: () => void, - onUnselectAll?: () => void, + onSelectAll?: (Account[]) => void, + onUnselectAll?: (Account[]) => void, title?: string, emptyText?: string, autoFocusFirstInput?: boolean, @@ -36,6 +36,14 @@ class AccountsList extends Component< toggleCollapse = () => { this.setState(({ collapsed }) => ({ collapsed: !collapsed })) } + onSelectAll = () => { + const { accounts, onSelectAll } = this.props + if (onSelectAll) onSelectAll(accounts) + } + onUnselectAll = () => { + const { accounts, onUnselectAll } = this.props + if (onUnselectAll) onUnselectAll(accounts) + } render() { const { accounts, @@ -76,7 +84,7 @@ class AccountsList extends Component< {withToggleAll && ( diff --git a/src/components/modals/AddAccounts/steps/03-step-import.js b/src/components/modals/AddAccounts/steps/03-step-import.js index c7372a4d..1584b9f4 100644 --- a/src/components/modals/AddAccounts/steps/03-step-import.js +++ b/src/components/modals/AddAccounts/steps/03-step-import.js @@ -132,14 +132,19 @@ class StepImport extends PureComponent { } } - handleSelectAll = () => { - const { scannedAccounts, setScannedAccounts } = this.props + handleSelectAll = (accountsToSelect: Account[]) => { + const { setScannedAccounts, checkedAccountsIds } = this.props setScannedAccounts({ - checkedAccountsIds: scannedAccounts.filter(a => a.operations.length > 0).map(a => a.id), + checkedAccountsIds: uniq(checkedAccountsIds.concat(accountsToSelect.map(a => a.id))), }) } - handleUnselectAll = () => this.props.setScannedAccounts({ checkedAccountsIds: [] }) + handleUnselectAll = (accountsToRemove: Account[]) => { + const { setScannedAccounts, checkedAccountsIds } = this.props + setScannedAccounts({ + checkedAccountsIds: checkedAccountsIds.filter(id => !accountsToRemove.some(a => id === a.id)), + }) + } renderError() { const { err, t } = this.props