mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 12:43:09 -05:00
Enactment: enable triggering of rules on selected transaction form the account view. (#3805)
* Adding functionality to trigger the rules of transaction from the transaction view Signed-off-by: Stefano Tranquillini <stefano.tranquillini@gmail.com> * fix warnings Signed-off-by: Stefano Tranquillini <stefano.tranquillini@gmail.com> * Fixing errors on the checks: adding changelog and lint Signed-off-by: Stefano Tranquillini <1928354+esseti@users.noreply.github.com> * Applying suggestion from the bot. Signed-off-by: Stefano Tranquillini <1928354+esseti@users.noreply.github.com> * ✨ Enhance transaction processing in Account component by implementing rules execution and batch updates. Added utility function imports for improved functionality. * Update packages/desktop-client/src/components/accounts/Account.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Refactor Account component imports by removing unused utility functions for cleaner code. * Update packages/desktop-client/src/components/accounts/Account.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore: correct coderabbitai * Removed hotkey * Update packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx --------- Signed-off-by: Stefano Tranquillini <stefano.tranquillini@gmail.com> Signed-off-by: Stefano Tranquillini <1928354+esseti@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: UnderKoen <koenvanstaveren@hotmail.com>
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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;
|
||||
|
||||
6
upcoming-release-notes/3805.md
Normal file
6
upcoming-release-notes/3805.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Enhancements
|
||||
authors: [esseti]
|
||||
---
|
||||
|
||||
Enables rule activation from the account view via dropdown menu or by pressing 'R'
|
||||
Reference in New Issue
Block a user