diff --git a/packages/desktop-client/src/components/accounts/Account.js b/packages/desktop-client/src/components/accounts/Account.js index 1b9400739b447f8b69fe9e59448364edcb40b658..1dcd56c381648e67c99eb2109bfcc32b578a219a 100644 --- a/packages/desktop-client/src/components/accounts/Account.js +++ b/packages/desktop-client/src/components/accounts/Account.js @@ -1829,6 +1829,7 @@ class AccountInternal extends PureComponent { replaceModal, showExtraBalances, accountId, + categoryId, } = this.props; let { transactions, @@ -1851,6 +1852,10 @@ class AccountInternal extends PureComponent { return <Navigate to="/accounts" replace />; } + let category = categoryGroups + .flatMap(g => g.categories) + .find(category => category.id === categoryId); + let showEmptyMessage = !loading && !accountId && accounts.length === 0; let isNameEditable = @@ -1932,6 +1937,7 @@ class AccountInternal extends PureComponent { this.paged && this.paged.fetchNext() } accounts={accounts} + category={category} categoryGroups={categoryGroups} payees={payees} balances={ @@ -2076,6 +2082,7 @@ export default function Account() { !!(activeLocation.state && activeLocation.state.locationPtr) } accountId={params.id} + categoryId={activeLocation?.state?.filter?.category} location={location} /> </SplitsExpandedProvider> diff --git a/packages/desktop-client/src/components/accounts/TransactionList.js b/packages/desktop-client/src/components/accounts/TransactionList.js index 28cd4d6579e11179afbf5153b07c6cbb69ba2bbc..f31eae02f44a3a083df61026b168f71ad7a142b8 100644 --- a/packages/desktop-client/src/components/accounts/TransactionList.js +++ b/packages/desktop-client/src/components/accounts/TransactionList.js @@ -59,6 +59,7 @@ export default function TransactionList({ loadMoreTransactions, account, accounts, + category, categoryGroups, payees, balances, @@ -163,6 +164,7 @@ export default function TransactionList({ showCategory={true} animated={animated} currentAccountId={account && account.id} + currentCategoryId={category && category.id} isAdding={isAdding} isNew={isNew} isMatched={isMatched} diff --git a/packages/desktop-client/src/components/accounts/TransactionsTable.js b/packages/desktop-client/src/components/accounts/TransactionsTable.js index 803decab474b946c01133fd2901d28120d3af16d..c0482a777fd2ca0c349f05a4943f726b16759c5d 100644 --- a/packages/desktop-client/src/components/accounts/TransactionsTable.js +++ b/packages/desktop-client/src/components/accounts/TransactionsTable.js @@ -604,7 +604,7 @@ const Transaction = memo(function Transaction(props) { notes, date, account: accountId, - category, + category: categoryId, cleared, is_parent: isParent, _unmatched = false, @@ -944,7 +944,7 @@ const Transaction = memo(function Transaction(props) { <CustomCell name="category" width="flex" - value={category} + value={categoryId} formatter={value => value ? getDisplayValue( @@ -958,7 +958,7 @@ const Transaction = memo(function Transaction(props) { exposed={focusedField === 'category'} onExpose={name => onEdit(id, name)} valueStyle={ - !category + !categoryId ? { fontStyle: 'italic', fontWeight: 300, @@ -984,7 +984,7 @@ const Transaction = memo(function Transaction(props) { }) => ( <CategoryAutocomplete categoryGroups={categoryGroups} - value={category} + value={categoryId} focused={true} tableBehavior={true} showSplitOption={!isChild && !isParent} @@ -1108,12 +1108,17 @@ function TransactionError({ error, isDeposit, onAddSplit, style }) { } } -function makeTemporaryTransactions(currentAccountId, lastDate) { +function makeTemporaryTransactions( + currentAccountId, + currentCategoryId, + lastDate, +) { return [ { id: 'temp', date: lastDate || currentDay(), account: currentAccountId || null, + category: currentCategoryId || null, cleared: false, amount: null, }, @@ -1519,7 +1524,12 @@ export let TransactionTable = forwardRef((props, ref) => { // Derive new transactions from the `isAdding` prop if (prevIsAdding !== props.isAdding) { if (!prevIsAdding && props.isAdding) { - setNewTransactions(makeTemporaryTransactions(props.currentAccountId)); + setNewTransactions( + makeTemporaryTransactions( + props.currentAccountId, + props.currentCategoryId, + ), + ); } setPrevIsAdding(props.isAdding); } @@ -1536,7 +1546,11 @@ export let TransactionTable = forwardRef((props, ref) => { let transactions = latestState.current.newTransactions; let lastDate = transactions.length > 0 ? transactions[0].date : null; setNewTransactions( - makeTemporaryTransactions(props.currentAccountId, lastDate), + makeTemporaryTransactions( + props.currentAccountId, + props.currentCategoryId, + lastDate, + ), ); newNavigator.onEdit('temp', 'date'); props.onAdd(transactions); @@ -1760,7 +1774,12 @@ export let TransactionTable = forwardRef((props, ref) => { ); function onCloseAddTransaction() { - setNewTransactions(makeTemporaryTransactions(props.currentAccountId)); + setNewTransactions( + makeTemporaryTransactions( + props.currentAccountId, + props.currentCategoryId, + ), + ); props.onCloseAddTransaction(); } diff --git a/upcoming-release-notes/1176.md b/upcoming-release-notes/1176.md new file mode 100644 index 0000000000000000000000000000000000000000..f2c2fb9290e8c238e92b2d1ff264d39fd1a7d1eb --- /dev/null +++ b/upcoming-release-notes/1176.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [joel-jeremy] +--- + +Automatically set category when adding a transaction to the budget category transaction list