From 01e662722cb095d1dbd1330e75b51736167a439e Mon Sep 17 00:00:00 2001 From: Nik Date: Sun, 14 Jan 2024 00:43:13 +0100 Subject: [PATCH] Add split distribution (#2151) * Add split distribution feature * Add upcoming release notes * Fix tests * Fix remaining test * Disable distribute button when all transactions are filled * Add canDistributeRemainder --------- Co-authored-by: Matiss Janis Aboltins --- .../transactions/TransactionsTable.jsx | 94 +++++++++++++++++-- .../transactions/TransactionsTable.test.jsx | 7 +- upcoming-release-notes/2151.md | 6 ++ 3 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 upcoming-release-notes/2151.md diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx b/packages/desktop-client/src/components/transactions/TransactionsTable.jsx index 77db1627272..bca1906fcea 100644 --- a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx +++ b/packages/desktop-client/src/components/transactions/TransactionsTable.jsx @@ -1349,7 +1349,7 @@ const Transaction = memo(function Transaction(props) { ); }); -function TransactionError({ error, isDeposit, onAddSplit, style }) { +function TransactionError({ error, isDeposit, onAddSplit, onDistributeRemainder, style, canDistributeRemainder }) { switch (error.type) { case 'SplitTransactionError': if (error.version === 1) { @@ -1372,10 +1372,20 @@ function TransactionError({ error, isDeposit, onAddSplit, style }) { + @@ -1433,6 +1443,7 @@ function NewTransaction({ onSave, onAdd, onAddSplit, + onDistributeRemainder, onManagePayees, onCreatePayee, onNavigateToTransferAccount, @@ -1442,6 +1453,8 @@ function NewTransaction({ const error = transactions[0].error; const isDeposit = transactions[0].amount > 0; + const emptyChildTransactions = transactions.filter(t => t.parent_id === transactions[0].id && t.amount === 0) + return ( onAddSplit(transactions[0].id)} + onDistributeRemainder={() => onDistributeRemainder(transactions[0].id)} + canDistributeRemainder={emptyChildTransactions.length > 0} /> ) : (