Skip to content

Commit

Permalink
Filter by account when linking schedules (#3188)
Browse files Browse the repository at this point in the history
* Add "S" hotkey for viewing/linking schedules.

* Default to filtering by account name when linking a schedule to a transaction.

* Work on 'all accounts' page.

* Update help modal

* add release note
  • Loading branch information
psybers authored Aug 8, 2024
1 parent 1abca76 commit 65c5f2c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 52 deletions.
1 change: 1 addition & 0 deletions packages/desktop-client/src/components/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export function Modals() {
key={name}
transactionIds={options?.transactionIds}
getTransaction={options?.getTransaction}
accountName={options?.accountName}
/>
);

Expand Down
1 change: 1 addition & 0 deletions packages/desktop-client/src/components/accounts/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export function AccountHeader({
</View>
) : (
<SelectedTransactionsButton
account={account}
getTransaction={id => transactions.find(t => t.id === id)}
onShow={onShowTransactions}
onDuplicate={onBatchDuplicate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,31 +206,38 @@ export function KeyboardShortcutModal() {
meta={ctrl}
/>
<Shortcut shortcut="B" description="Bank sync" meta={ctrl} />
<GroupHeading group="Select a transaction, then" />
<GroupHeading group="With transaction(s) selected" />
<Shortcut
shortcut="J"
description="Move to the next transaction down"
shortcut="F"
description="Filter to the selected transactions"
/>
<Shortcut
shortcut="K"
description="Move to the next transaction up"
shortcut="D"
description="Delete selected transactions"
/>
<Shortcut
shortcut=""
description="Move to the next transaction down and scroll"
shortcut="A"
description="Set account for selected transactions"
/>
<Shortcut
shortcut=""
description="Move to the next transaction up and scroll"
shortcut="P"
description="Set payee for selected transactions"
/>
<Shortcut
shortcut="Space"
description="Toggle selection of current transaction"
shortcut="N"
description="Set notes for selected transactions"
/>
<Shortcut
shortcut="Space"
description="Toggle all transactions between current and most recently selected transaction"
shift={true}
shortcut="C"
description="Set category for selected transactions"
/>
<Shortcut
shortcut="L"
description="Toggle cleared for selected transactions"
/>
<Shortcut
shortcut="S"
description="Link or view schedule for selected transactions"
/>
</>
)}
Expand Down Expand Up @@ -296,34 +303,31 @@ export function KeyboardShortcutModal() {
shortcut="F"
description="Filter transactions"
/>
<GroupHeading group="With transaction(s) selected" />
<GroupHeading group="Select a transaction, then" />
<Shortcut
shortcut="F"
description="Filter to the selected transactions"
shortcut="J"
description="Move to the next transaction down"
/>
<Shortcut
shortcut="D"
description="Delete selected transactions"
shortcut="K"
description="Move to the next transaction up"
/>
<Shortcut
shortcut="A"
description="Set account for selected transactions"
shortcut=""
description="Move to the next transaction down and scroll"
/>
<Shortcut
shortcut="P"
description="Set payee for selected transactions"
shortcut=""
description="Move to the next transaction up and scroll"
/>
<Shortcut
shortcut="N"
description="Set notes for selected transactions"
shortcut="Space"
description="Toggle selection of current transaction"
/>
<Shortcut
shortcut="C"
description="Set category for selected transactions"
/>
<Shortcut
shortcut="L"
description="Toggle cleared for current transaction"
shortcut="Space"
description="Toggle all transactions between current and most recently selected transaction"
shift={true}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import { ROW_HEIGHT, SchedulesTable } from './SchedulesTable';
export function ScheduleLink({
transactionIds: ids,
getTransaction,
accountName,
}: {
transactionIds: string[];
getTransaction: (transactionId: string) => TransactionEntity;
accountName: string;
}) {
const dispatch = useDispatch();
const [filter, setFilter] = useState('');
const [filter, setFilter] = useState(accountName);

const scheduleData = useSchedules({
transform: useCallback((q: Query) => q.filter({ completed: false }), []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Menu } from '../common/Menu';
import { SelectedItemsButton } from '../table';

export function SelectedTransactionsButton({
account,
getTransaction,
onShow,
onDuplicate,
Expand Down Expand Up @@ -112,6 +113,32 @@ export function SelectedTransactionsButton({
return areNoReconciledTransactions && areAllSplitTransactions;
}, [selectedIds, types, getTransaction]);

function onLinkSchedule() {
dispatch(
pushModal('schedule-link', {
transactionIds: selectedIds,
getTransaction,
accountName: account?.name ?? '',
}),
);
}

function onViewSchedule() {
const firstId = selectedIds[0];
let scheduleId;
if (isPreviewId(firstId)) {
const parts = firstId.split('/');
scheduleId = parts[1];
} else {
const trans = getTransaction(firstId);
scheduleId = trans && trans.schedule;
}

if (scheduleId) {
dispatch(pushModal('schedule-edit', { id: scheduleId }));
}
}

const hotKeyOptions = {
enabled: types.trans,
scopes: ['app'],
Expand Down Expand Up @@ -144,14 +171,22 @@ export function SelectedTransactionsButton({
onEdit,
selectedIds,
]);
useHotkeys(
's',
() => (!types.trans || linked ? onViewSchedule() : onLinkSchedule()),
{
scopes: ['app'],
},
[onLinkSchedule, onViewSchedule, linked, selectedIds],
);

return (
<SelectedItemsButton
name="transactions"
items={[
...(!types.trans
? [
{ name: 'view-schedule', text: 'View schedule' },
{ name: 'view-schedule', text: 'View schedule', key: 'S' },
{ name: 'post-transaction', text: 'Post transaction' },
{ name: 'skip', text: 'Skip scheduled date' },
]
Expand All @@ -168,6 +203,7 @@ export function SelectedTransactionsButton({
{
name: 'view-schedule',
text: 'View schedule',
key: 'S',
disabled: selectedIds.length > 1,
},
{ name: 'unlink-schedule', text: 'Unlink schedule' },
Expand All @@ -176,6 +212,7 @@ export function SelectedTransactionsButton({
{
name: 'link-schedule',
text: 'Link schedule',
key: 'S',
},
{
name: 'create-rule',
Expand Down Expand Up @@ -242,27 +279,10 @@ export function SelectedTransactionsButton({
onScheduleAction(name, selectedIds);
break;
case 'view-schedule':
const firstId = selectedIds[0];
let scheduleId;
if (isPreviewId(firstId)) {
const parts = firstId.split('/');
scheduleId = parts[1];
} else {
const trans = getTransaction(firstId);
scheduleId = trans && trans.schedule;
}

if (scheduleId) {
dispatch(pushModal('schedule-edit', { id: scheduleId }));
}
onViewSchedule();
break;
case 'link-schedule':
dispatch(
pushModal('schedule-link', {
transactionIds: selectedIds,
getTransaction,
}),
);
onLinkSchedule();
break;
case 'unlink-schedule':
onUnlink(selectedIds);
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3188.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [psybers]
---

Filter by account when linking schedules and add shortcut "S" to link schedule.

0 comments on commit 65c5f2c

Please sign in to comment.