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} > str => { const parts = str + .replace(/\bjan(\.|uary)?\b/i, '01') + .replace(/\bfeb(\.|ruary)?\b/i, '02') + .replace(/\bmar(\.|ch)?\b/i, '03') + .replace(/\bapr(\.|il)?\b/i, '04') + .replace(/\bmay\.?\b/i, '05') + .replace(/\bjun(\.|e)?\b/i, '06') + .replace(/\bjul(\.|y)?\b/i, '07') + .replace(/\baug(\.|ust)?\b/i, '08') + .replace(/\bsep(\.|tember)?\b/i, '09') + .replace(/\boct(\.|ober)?\b/i, '10') + .replace(/\bnov(\.|ember)?\b/i, '11') + .replace(/\bdec(\.|ember)?\b/i, '12') .replace(/^[^\d]+/, '') .replace(/[^\d]+$/, '') .split(/[^\d]+/); diff --git a/packages/desktop-client/src/components/modals/ImportTransactions.test.js b/packages/desktop-client/src/components/modals/ImportTransactions.test.js index 6f3f711fde7..3b8d4ed9ed5 100644 --- a/packages/desktop-client/src/components/modals/ImportTransactions.test.js +++ b/packages/desktop-client/src/components/modals/ImportTransactions.test.js @@ -8,8 +8,9 @@ describe('Import transactions', function () { { str: 42, order: 'yyyy mm dd' }, { str: {}, order: 'yyyy mm dd' }, { str: [], order: 'yyyy mm dd' }, + { str: 'Decimal 24 2020', order: 'mm dd yyyy' }, + { str: '24 aDec 2020', order: 'dd mm yyyy' }, { str: 'invalid', order: 'yyyy mm dd' }, - { str: '2020 Dec 24', order: 'yyyy mm dd' }, { str: '12 24 20', order: 'mm dd yyyy' }, { str: '20 12 24', order: 'yyyy mm dd' }, { str: '2020 12 24', order: 'yy mm dd' }, @@ -40,6 +41,9 @@ describe('Import transactions', function () { { order: 'yyyy mm dd', cases: [ + ['2020 Dec 24', '2020-12-24'], + ['2020 Dec. 24', '2020-12-24'], + ['2020 December 24', '2020-12-24'], ['20201224', '2020-12-24'], ['2020 12 24', '2020-12-24'], ['2020-1-2', '2020-01-02'], @@ -54,6 +58,9 @@ describe('Import transactions', function () { { order: 'yy mm dd', cases: [ + ['20 Dec 24', '2020-12-24'], + ['20 Dec. 24', '2020-12-24'], + ['20 December 24', '2020-12-24'], ['201224', '2020-12-24'], ['20 12 24', '2020-12-24'], ['20-12-24', '2020-12-24'], @@ -67,6 +74,9 @@ describe('Import transactions', function () { { order: 'mm dd yyyy', cases: [ + ['Dec 24, 2020', '2020-12-24'], + ['Dec. 24, 2020', '2020-12-24'], + ['December 24, 2020', '2020-12-24'], ['12242020', '2020-12-24'], ['1 24 2020', '2020-01-24'], ['01 24 2020', '2020-01-24'], @@ -81,6 +91,9 @@ describe('Import transactions', function () { { order: 'mm dd yy', cases: [ + ['Dec 24, 20', '2020-12-24'], + ['Dec. 24, 20', '2020-12-24'], + ['December 24, 20', '2020-12-24'], ['122420', '2020-12-24'], ['12 24 20 ', '2020-12-24'], ['12-24-20', '2020-12-24'], @@ -96,6 +109,9 @@ describe('Import transactions', function () { { order: 'dd mm yyyy', cases: [ + ['24 Dec 2020', '2020-12-24'], + ['24 Dec. 2020', '2020-12-24'], + ['24 December 2020', '2020-12-24'], ['24122020', '2020-12-24'], ['24 12 2020 ', '2020-12-24'], ['2 12 2020', '2020-12-02'], @@ -112,6 +128,9 @@ describe('Import transactions', function () { { order: 'dd mm yy', cases: [ + ['24 Dec 20', '2020-12-24'], + ['24 Dec. 20', '2020-12-24'], + ['24 December 20', '2020-12-24'], ['241220', '2020-12-24'], ['2412 20 ', '2020-12-24'], ['24-12-20', '2020-12-24'], diff --git a/packages/desktop-client/src/hooks/useSelected.tsx b/packages/desktop-client/src/hooks/useSelected.tsx index 75b0d1b7171..d9f2404642a 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( 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/1862.md b/upcoming-release-notes/1862.md new file mode 100644 index 00000000000..99e36a4be44 --- /dev/null +++ b/upcoming-release-notes/1862.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [jamescostian] +--- + +Allow month names and abbreviations in dates (e.g. "December 24 2020") when importing 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