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

Enactment: enable triggering of rules on selected transaction form the account view. #3805

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
25 changes: 25 additions & 0 deletions packages/desktop-client/src/components/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
type RuleConditionEntity,
type TransactionEntity,
type TransactionFilterEntity,
type RuleEntity,
} from 'loot-core/src/types/models';

import { useAccounts } from '../../hooks/useAccounts';
Expand Down Expand Up @@ -705,6 +706,29 @@ class AccountInternal extends PureComponent<
return groupById<{ id: string; balance: number }>(data);
}

onRunRules = async (ids: string[]) => {
// this should be probably inside the onEdit function that the others button are calling
// but I'm not sure how to do it and if i'll break anything
const transactions = this.state.transactions;
for (const transId of ids) {
const trans = transactions.find(({ id }) => transId === id);
send('payees-get-rules', {
id: trans.payee,
}).then((the_rules: RuleEntity[]) => {
the_rules.forEach((rule: RuleEntity) => {
send('rule-apply-actions', {
transactions: [trans],
actions: rule.actions,
}).then(() => {
// once rule is applied, fetch the transaction again.
// should just update the one that has been updated, but not sure how to do it.
// probably via the updateTransaction function ?
this.fetchTransactions();
});
});
});
}
};
matt-fidd marked this conversation as resolved.
Show resolved Hide resolved
onAddTransaction = () => {
this.setState({ isAdding: true });
};
Expand Down Expand Up @@ -1736,6 +1760,7 @@ class AccountInternal extends PureComponent<
onImport={this.onImport}
onBatchDelete={this.onBatchDelete}
onBatchDuplicate={this.onBatchDuplicate}
onRunRules={this.onRunRules}
onBatchEdit={this.onBatchEdit}
onBatchLinkSchedule={this.onBatchLinkSchedule}
onBatchUnlinkSchedule={this.onBatchUnlinkSchedule}
Expand Down
3 changes: 3 additions & 0 deletions packages/desktop-client/src/components/accounts/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type AccountHeaderProps = {
onMenuSelect: AccountMenuProps['onMenuSelect'];
onReconcile: ComponentProps<typeof ReconcileMenu>['onReconcile'];
onBatchEdit: ComponentProps<typeof SelectedTransactionsButton>['onEdit'];
onRunRules: ComponentProps<typeof SelectedTransactionsButton>['onRunRules'];
onBatchDelete: ComponentProps<typeof SelectedTransactionsButton>['onDelete'];
onBatchDuplicate: ComponentProps<
typeof SelectedTransactionsButton
Expand Down Expand Up @@ -177,6 +178,7 @@ export function AccountHeader({
onDeleteFilter,
onScheduleAction,
onSetTransfer,
onRunRules,
onMakeAsSplitTransaction,
onMakeAsNonSplitTransactions,
}: AccountHeaderProps) {
Expand Down Expand Up @@ -359,6 +361,7 @@ export function AccountHeader({
onDuplicate={onBatchDuplicate}
onDelete={onBatchDelete}
onEdit={onBatchEdit}
onRunRules={onRunRules}
onLinkSchedule={onBatchLinkSchedule}
onUnlinkSchedule={onBatchUnlinkSchedule}
onCreateRule={onCreateRule}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type SelectedTransactionsButtonProps = {
onLinkSchedule: (selectedIds: string[]) => void;
onUnlinkSchedule: (selectedIds: string[]) => void;
onCreateRule: (selectedIds: string[]) => void;
onRunRules: (selectedIds: string[]) => void;
onSetTransfer: (selectedIds: string[]) => void;
onScheduleAction: (
action: 'post-transaction' | 'skip',
Expand All @@ -50,6 +51,7 @@ export function SelectedTransactionsButton({
onLinkSchedule,
onUnlinkSchedule,
onCreateRule,
onRunRules,
onSetTransfer,
onScheduleAction,
showMakeTransfer,
Expand Down Expand Up @@ -193,6 +195,10 @@ export function SelectedTransactionsButton({
onEdit,
selectedIds,
]);
useHotkeys('r', () => onRunRules(selectedIds), hotKeyOptions, [
onRunRules,
selectedIds,
]);
useHotkeys(
's',
() =>
Expand Down Expand Up @@ -253,7 +259,13 @@ export function SelectedTransactionsButton({
name: 'create-rule',
text: t('Create rule'),
} as const,
{
name: 'run-rules',
text: t('Run Rules'),
key: 'R',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this action will need a hotkey.

} as const,
]),

...(showMakeTransfer
? [
{
Expand Down Expand Up @@ -325,6 +337,9 @@ export function SelectedTransactionsButton({
case 'create-rule':
onCreateRule(selectedIds);
break;
case 'run-rules':
onRunRules(selectedIds);
break;
case 'set-transfer':
onSetTransfer(selectedIds);
break;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3805.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [esseti]
---

Enables rule activation from the account view via dropdown menu or by pressing 'R'