From 199a9f838dca4b334edf3c7aeea8f6929081eed8 Mon Sep 17 00:00:00 2001 From: James Costian Date: Thu, 9 Nov 2023 09:11:51 -0600 Subject: [PATCH] Make Select All respect filters and splits (#1864) --- .../src/components/accounts/Account.js | 1 + .../desktop-client/src/hooks/useSelected.tsx | 23 +++++++++++++++++-- upcoming-release-notes/1864.md | 6 +++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 upcoming-release-notes/1864.md diff --git a/packages/desktop-client/src/components/accounts/Account.js b/packages/desktop-client/src/components/accounts/Account.js index 8785669fcdd..9bcbf26170c 100644 --- a/packages/desktop-client/src/components/accounts/Account.js +++ b/packages/desktop-client/src/components/accounts/Account.js @@ -1201,6 +1201,7 @@ class AccountInternal extends PureComponent { items={allTransactions} fetchAllIds={this.fetchAllIds} registerDispatch={dispatch => (this.dispatchSelected = dispatch)} + selectAllFilter={item => !item._unmatched && !item.is_parent} > ( name: string, items: T[], initialSelectedIds: string[], + selectAllFilter?: (T) => boolean, ) { let [state, dispatch] = useReducer( (state: State, action: Actions) => { @@ -128,9 +129,20 @@ export default function useSelected( return { ...state, selectedItems: new Set() }; case 'select-all': + let selectedItems: string[] = []; + if (action.ids && items && selectAllFilter) { + const idsToInclude = new Set( + items.filter(selectAllFilter).map(item => item.id), + ); + selectedItems = action.ids.filter(id => idsToInclude.has(id)); + } else if (items && selectAllFilter) { + selectedItems = items.filter(selectAllFilter).map(item => item.id); + } else { + selectedItems = action.ids || items.map(item => item.id); + } return { ...state, - selectedItems: new Set(action.ids || items.map(item => item.id)), + selectedItems: new Set(selectedItems), selectedRange: action.ids && action.ids.length === 1 ? { start: action.ids[0], end: null } @@ -300,6 +312,7 @@ type SelectedProviderWithItemsProps = { initialSelectedIds: string[]; fetchAllIds: () => Promise; registerDispatch?: (dispatch: Dispatch) => void; + selectAllFilter?: (T) => boolean; children: ReactElement; }; @@ -311,9 +324,15 @@ export function SelectedProviderWithItems({ initialSelectedIds, fetchAllIds, registerDispatch, + selectAllFilter, children, }: SelectedProviderWithItemsProps) { - let selected = useSelected(name, items, initialSelectedIds); + let selected = useSelected( + name, + items, + initialSelectedIds, + selectAllFilter, + ); useEffect(() => { registerDispatch?.(selected.dispatch); diff --git a/upcoming-release-notes/1864.md b/upcoming-release-notes/1864.md new file mode 100644 index 00000000000..19c3cb9cb19 --- /dev/null +++ b/upcoming-release-notes/1864.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [jamescostian] +--- + +Make Select All respect filters and splits