Skip to content

Commit

Permalink
Make Select All respect filters and splits (#1864)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescostian authored Nov 9, 2023
1 parent df5aa31 commit 199a9f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/desktop-client/src/components/accounts/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
>
<View style={styles.page}>
<AccountHeader
Expand Down
23 changes: 21 additions & 2 deletions packages/desktop-client/src/hooks/useSelected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function useSelected<T extends Item>(
name: string,
items: T[],
initialSelectedIds: string[],
selectAllFilter?: (T) => boolean,
) {
let [state, dispatch] = useReducer(
(state: State, action: Actions) => {
Expand Down Expand Up @@ -128,9 +129,20 @@ export default function useSelected<T extends Item>(
return { ...state, selectedItems: new Set<string>() };

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 }
Expand Down Expand Up @@ -300,6 +312,7 @@ type SelectedProviderWithItemsProps<T extends Item> = {
initialSelectedIds: string[];
fetchAllIds: () => Promise<string[]>;
registerDispatch?: (dispatch: Dispatch<Actions>) => void;
selectAllFilter?: (T) => boolean;
children: ReactElement;
};

Expand All @@ -311,9 +324,15 @@ export function SelectedProviderWithItems<T extends Item>({
initialSelectedIds,
fetchAllIds,
registerDispatch,
selectAllFilter,
children,
}: SelectedProviderWithItemsProps<T>) {
let selected = useSelected<T>(name, items, initialSelectedIds);
let selected = useSelected<T>(
name,
items,
initialSelectedIds,
selectAllFilter,
);

useEffect(() => {
registerDispatch?.(selected.dispatch);
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1864.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [jamescostian]
---

Make Select All respect filters and splits

0 comments on commit 199a9f8

Please sign in to comment.