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

Make Select All respect filters and splits #1864

Merged
merged 1 commit into from
Nov 9, 2023
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
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
Loading