diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx index 4be9f28866b..d6c3a290c0e 100644 --- a/packages/desktop-client/src/components/accounts/Account.tsx +++ b/packages/desktop-client/src/components/accounts/Account.tsx @@ -702,6 +702,45 @@ class AccountInternal extends PureComponent< return groupById<{ id: string; balance: number }>(data); } + onRunRules = async (ids: string[]) => { + try { + this.setState({ workingHard: true }); + // Bulk fetch transactions + const transactions = this.state.transactions.filter(trans => + ids.includes(trans.id), + ); + //call the runrules function + const changedTransactions = []; + for (const transaction of transactions) { + await send('rules-run', { + transaction, + }).then((res: TransactionEntity | null) => { + 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 + await 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 }); }; @@ -1730,6 +1769,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} diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsx index 4a66ebc45de..8fdb036455d 100644 --- a/packages/desktop-client/src/components/accounts/Header.tsx +++ b/packages/desktop-client/src/components/accounts/Header.tsx @@ -95,6 +95,7 @@ type AccountHeaderProps = { onMenuSelect: AccountMenuProps['onMenuSelect']; onReconcile: ComponentProps['onReconcile']; onBatchEdit: ComponentProps['onEdit']; + onRunRules: ComponentProps['onRunRules']; onBatchDelete: ComponentProps['onDelete']; onBatchDuplicate: ComponentProps< typeof SelectedTransactionsButton @@ -177,6 +178,7 @@ export function AccountHeader({ onDeleteFilter, onScheduleAction, onSetTransfer, + onRunRules, onMakeAsSplitTransaction, onMakeAsNonSplitTransactions, }: AccountHeaderProps) { @@ -359,6 +361,7 @@ export function AccountHeader({ onDuplicate={onBatchDuplicate} onDelete={onBatchDelete} onEdit={onBatchEdit} + onRunRules={onRunRules} onLinkSchedule={onBatchLinkSchedule} onUnlinkSchedule={onBatchUnlinkSchedule} onCreateRule={onCreateRule} diff --git a/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx b/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx index fa1c85836ee..6ff7985af9c 100644 --- a/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx +++ b/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx @@ -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', @@ -50,6 +51,7 @@ export function SelectedTransactionsButton({ onLinkSchedule, onUnlinkSchedule, onCreateRule, + onRunRules, onSetTransfer, onScheduleAction, showMakeTransfer, @@ -193,6 +195,10 @@ export function SelectedTransactionsButton({ onEdit, selectedIds, ]); + useHotkeys('r', () => onRunRules(selectedIds), hotKeyOptions, [ + onRunRules, + selectedIds, + ]); useHotkeys( 's', () => @@ -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', + } as const, ]), + ...(showMakeTransfer ? [ { @@ -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; diff --git a/upcoming-release-notes/3805.md b/upcoming-release-notes/3805.md new file mode 100644 index 00000000000..1355b1f1a98 --- /dev/null +++ b/upcoming-release-notes/3805.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [esseti] +--- + +Enables rule activation from the account view via dropdown menu or by pressing 'R'