-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[WIP] Auto-fill empty split transaction with outstanding amount on click. #1271
Closed
Closed
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
78777b5
add ability to balance
Shazib 77c8860
Merge branch 'master' into split-transactions-autofill
Shazib 4a90621
Release notes
Shazib d57fe5c
Merge branch 'master' into split-transactions-autofill
Shazib ad78d50
Merge branch 'actualbudget:master' into split-transactions-autofill
Shazib e1542ec
Fix
Shazib 30b8e26
Merge branch 'master' into split-transactions-autofill
Shazib 2d02e02
Merge branch 'master' into split-transactions-autofill
Shazib a64bc1a
Merge branch 'master' into split-transactions-autofill
Shazib 448ce91
Merge branch 'master' into split-transactions-autofill
Shazib c376b20
Fix how test locates the “Add Split” button
j-f1 0422603
Fix remaining failed check
j-f1 517fd0e
Merge branch 'master' into split-transactions-autofill
Shazib fd55daa
Merge branch 'master' into split-transactions-autofill
Shazib a3fb0f2
Merge branch 'master' into split-transactions-autofill
Shazib d05d9cb
Merge branch 'master' into split-transactions-autofill
Shazib 38f28af
Merge branch 'master' into split-transactions-autofill
Shazib 84f676c
Better implementation
Shazib 16455a7
Merge branch 'master' into split-transactions-autofill
Shazib 4313cd4
Merge branch 'master' into split-transactions-autofill
Shazib 64141ea
Merge branch 'master' into split-transactions-autofill
Shazib 5e8df33
Merge branch 'master' into split-transactions-autofill
Shazib 0c8c625
Fix for existing splits
d2f6734
Existing split support
98785c5
Try passing error null to trigger end edit
410aa15
Merge branch 'master' into split-transactions-autofill
Shazib fd0028a
lint
7206b3a
Merge branch 'master' into split-transactions-autofill
Shazib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1296,7 +1296,13 @@ const Transaction = memo(function Transaction(props) { | |
); | ||
}); | ||
|
||
function TransactionError({ error, isDeposit, onAddSplit, style }) { | ||
function TransactionError({ | ||
error, | ||
isDeposit, | ||
onAddSplit, | ||
style, | ||
onBalanceLastSplit, | ||
}) { | ||
switch (error.type) { | ||
case 'SplitTransactionError': | ||
if (error.version === 1) { | ||
|
@@ -1312,17 +1318,25 @@ function TransactionError({ error, isDeposit, onAddSplit, style }) { | |
> | ||
<Text> | ||
Amount left:{' '} | ||
<Text style={{ fontWeight: 500 }}> | ||
<Button | ||
bare | ||
onClick={onBalanceLastSplit} | ||
style={{ | ||
display: 'inline', | ||
fontWeight: 500, | ||
}} | ||
> | ||
{integerToCurrency( | ||
isDeposit ? error.difference : -error.difference, | ||
)} | ||
</Text> | ||
</Button> | ||
</Text> | ||
<View style={{ flex: 1 }} /> | ||
<Button | ||
type="primary" | ||
style={{ marginLeft: 15, padding: '4px 10px' }} | ||
onClick={onAddSplit} | ||
data-testid="add-split-button" | ||
> | ||
Add Split | ||
</Button> | ||
|
@@ -1384,6 +1398,7 @@ function NewTransaction({ | |
onCreatePayee, | ||
onNavigateToTransferAccount, | ||
onNavigateToSchedule, | ||
onBalanceLastSplit, | ||
balance, | ||
}) { | ||
const error = transactions[0].error; | ||
|
@@ -1454,6 +1469,7 @@ function NewTransaction({ | |
<TransactionError | ||
error={error} | ||
isDeposit={isDeposit} | ||
onBalanceLastSplit={onBalanceLastSplit} | ||
onAddSplit={() => onAddSplit(transactions[0].id)} | ||
/> | ||
) : ( | ||
|
@@ -1478,6 +1494,7 @@ function TransactionTableInner({ | |
newNavigator, | ||
renderEmpty, | ||
onScroll, | ||
onBalanceLastSplit, | ||
...props | ||
}) { | ||
const containerRef = createRef(); | ||
|
@@ -1651,6 +1668,7 @@ function TransactionTableInner({ | |
onManagePayees={props.onManagePayees} | ||
onCreatePayee={props.onCreatePayee} | ||
onNavigateToTransferAccount={onNavigateToTransferAccount} | ||
onBalanceLastSplit={onBalanceLastSplit} | ||
onNavigateToSchedule={onNavigateToSchedule} | ||
balance={ | ||
props.transactions?.length > 0 | ||
|
@@ -2041,6 +2059,46 @@ export let TransactionTable = forwardRef((props, ref) => { | |
[splitsExpanded.dispatch], | ||
); | ||
|
||
let onBalanceLastSplit = useCallback(async () => { | ||
const { tableNavigator, newTransactions } = latestState.current; | ||
const parentTransaction = newTransactions[0]; | ||
|
||
const allSubTransactions = newTransactions.filter( | ||
t => t.parent_id === parentTransaction.id, | ||
); | ||
|
||
const emptyTransactions = allSubTransactions.filter(t => t.amount === 0); | ||
const remainingAmount = | ||
parentTransaction.amount - | ||
allSubTransactions.reduce((acc, t) => acc + t.amount, 0); | ||
|
||
const amountPerTransaction = Math.floor( | ||
remainingAmount / emptyTransactions.length, | ||
); | ||
let remainingCents = | ||
remainingAmount - amountPerTransaction * emptyTransactions.length; | ||
|
||
let amounts = new Array(emptyTransactions.length).fill( | ||
amountPerTransaction, | ||
); | ||
for (let amountIndex in amounts) { | ||
if (remainingCents === 0) break; | ||
|
||
amounts[amountIndex] += 1; | ||
remainingCents--; | ||
} | ||
|
||
for (const transactionIndex in emptyTransactions) { | ||
await onSave({ | ||
...emptyTransactions[transactionIndex], | ||
amount: amounts[transactionIndex], | ||
}); | ||
} | ||
|
||
// cancel focused field | ||
tableNavigator.onEdit(null, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing |
||
}, [latestState]); | ||
|
||
return ( | ||
<TransactionTableInner | ||
tableRef={mergedRef} | ||
|
@@ -2061,6 +2119,7 @@ export let TransactionTable = forwardRef((props, ref) => { | |
newTransactions={newTransactions} | ||
tableNavigator={tableNavigator} | ||
newNavigator={newNavigator} | ||
onBalanceLastSplit={onBalanceLastSplit} | ||
/> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Enhancements | ||
authors: [Shazib,NikxDa] | ||
--- | ||
|
||
Allow clicking on 'Amount Left' value to auto-fill the last empty split(s). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed to work in my initial tests.....