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

Merged
merged 17 commits into from
Jan 12, 2025
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
38 changes: 38 additions & 0 deletions packages/desktop-client/src/components/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,43 @@ class AccountInternal extends PureComponent<
return groupById<{ id: string; balance: number }>(data);
}

onRunRules = async (ids: string[]) => {
try {
this.setState({ workingHard: true });
esseti marked this conversation as resolved.
Show resolved Hide resolved
// Bulk fetch transactions
const transactions = this.state.transactions.filter(trans =>
ids.includes(trans.id),
);
const changedTransactions = [];
for (const transaction of transactions) {
const res: TransactionEntity | null = await send('rules-run', {
transaction,
});
if (res) {
changedTransactions.push(res);
}
}

// If we have changed transactions, update them in the database
if (changedTransactions.length > 0) {
await send('transactions-batch-update', {
updated: changedTransactions,
});
}

// Fetch updated transactions once at the end
this.fetchTransactions();
} catch (error) {
console.error('Error applying rules:', error);
this.props.addNotification({
type: 'error',
message: 'Failed to apply rules to transactions',
});
} finally {
this.setState({ workingHard: false });
}
};

onAddTransaction = () => {
this.setState({ isAdding: true });
};
Expand Down Expand Up @@ -1734,6 +1771,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 @@ -253,7 +255,12 @@ export function SelectedTransactionsButton({
name: 'create-rule',
text: t('Create rule'),
} as const,
{
name: 'run-rules',
text: t('Run Rules'),
} as const,
]),

...(showMakeTransfer
? [
{
Expand Down Expand Up @@ -325,6 +332,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'
Loading