A local-first personal finance app
Enactment: enable triggering of rules on selected transaction form the account view. (#3805)
Stefanoa1be1d43f6c3
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsxindex 601834aa35..3b5819ac74 100644--- a/packages/desktop-client/src/components/accounts/Account.tsx+++ b/packages/desktop-client/src/components/accounts/Account.tsx@@ -704,6 +704,43 @@ 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),+ );+ 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 });};@@ -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}diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsxindex 1866534b56..08e7147a41 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<typeof ReconcileMenu>['onReconcile'];onBatchEdit: ComponentProps<typeof SelectedTransactionsButton>['onEdit'];+ onRunRules: ComponentProps<typeof SelectedTransactionsButton>['onRunRules'];onBatchDelete: ComponentProps<typeof SelectedTransactionsButton>['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.tsxindex f11325572a..77a6966b17 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,@@ -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? [{@@ -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;diff --git a/upcoming-release-notes/3805.md b/upcoming-release-notes/3805.mdnew file mode 100644index 0000000000..1355b1f1a9--- /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'