A local-first personal finance app
Make Select All respect filters and splits (#1864)
James Costian199a9f838dca
diff --git a/packages/desktop-client/src/components/accounts/Account.js b/packages/desktop-client/src/components/accounts/Account.jsindex 8785669fcd..9bcbf26170 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}><View style={styles.page}><AccountHeaderdiff --git a/packages/desktop-client/src/hooks/useSelected.tsx b/packages/desktop-client/src/hooks/useSelected.tsxindex 75b0d1b717..d9f2404642 100644--- a/packages/desktop-client/src/hooks/useSelected.tsx+++ b/packages/desktop-client/src/hooks/useSelected.tsx@@ -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) => {@@ -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 }@@ -300,6 +312,7 @@ type SelectedProviderWithItemsProps<T extends Item> = {initialSelectedIds: string[];fetchAllIds: () => Promise<string[]>;registerDispatch?: (dispatch: Dispatch<Actions>) => void;+ selectAllFilter?: (T) => boolean;children: ReactElement;};@@ -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);diff --git a/upcoming-release-notes/1864.md b/upcoming-release-notes/1864.mdnew file mode 100644index 0000000000..19c3cb9cb1--- /dev/null+++ b/upcoming-release-notes/1864.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [jamescostian]+---++Make Select All respect filters and splits