Skip to content

Commit

Permalink
Fixed opening balance row display and selection
Browse files Browse the repository at this point in the history
  • Loading branch information
JackNeto committed Aug 9, 2019
1 parent c8d57ec commit 703c5e7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 13 deletions.
22 changes: 16 additions & 6 deletions src/core/Accounts/Transactions/TransactionsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ export class TransactionsTableComponent extends React.Component {

handleSelectAllClick = (event, filteredTransactions) => {
if (event.target.checked) {
this.setState({ selected: filteredTransactions.map(n => n.id) })
this.setState({
selected: filteredTransactions.reduce((result, transaction) => {
return [...result, ...('id' in transaction ? [transaction.id] : [])]
}, [])
})
return
}
this.resetSelection()
Expand All @@ -186,12 +190,18 @@ export class TransactionsTableComponent extends React.Component {
})
}

renderCellAmount = ({ cellData }) => (
{
renderCellAmount = ({ cellData, rowData }) => {
if (cellData.amount === 0 && rowData.id === undefined) {
return {
positiveAmount: this.props.formatDecimal(cellData.amount),
negativeAmount: null
}[cellData.restrictTo]
}
return {
positiveAmount: cellData.amount > 0 ? this.props.formatDecimal(cellData.amount) : null,
negativeAmount: cellData.amount < 0 ? this.props.formatDecimal(cellData.amount) : null
}[cellData.restrictTo]
)
}

render() {
const {
Expand Down Expand Up @@ -251,8 +261,8 @@ export class TransactionsTableComponent extends React.Component {
key="label"
>
<Checkbox
indeterminate={selected.length > 0 && selected.length < filteredTransactions.length}
checked={selected.length > 0 && selected.length === filteredTransactions.length}
indeterminate={selected.length > 0 && selected.length < filteredTransactions.length - 1}
checked={selected.length > 0 && selected.length === filteredTransactions.length - 1}
onChange={event => this.handleSelectAllClick(event, filteredTransactions)}
/>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,60 @@ describe('TransactionsTable', () => {

describe('renderCellAmount', () => {
it('should render for positive amounts', () => {
expect(instance.renderCellAmount({ cellData: { amount: 1, restrictTo: 'positiveAmount' } })).not.toBeNull()
expect(instance.renderCellAmount({ cellData: { amount: 0, restrictTo: 'positiveAmount' } })).toBeNull()
expect(instance.renderCellAmount({ cellData: { amount: -1, restrictTo: 'positiveAmount' } })).toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: 1, restrictTo: 'positiveAmount' },
rowData: { id: 1 }
})).not.toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: 0, restrictTo: 'positiveAmount' },
rowData: { id: 1 }
})).toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: -1, restrictTo: 'positiveAmount' },
rowData: { id: 1 }
})).toBeNull()
})

it('should render for negative amounts', () => {
expect(instance.renderCellAmount({ cellData: { amount: -11, restrictTo: 'negativeAmount' } })).not.toBeNull()
expect(instance.renderCellAmount({ cellData: { amount: 0, restrictTo: 'negativeAmount' } })).toBeNull()
expect(instance.renderCellAmount({ cellData: { amount: 1, restrictTo: 'negativeAmount' } })).toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: -11, restrictTo: 'negativeAmount' },
rowData: { id: 1 }
})).not.toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: 0, restrictTo: 'negativeAmount' },
rowData: { id: 1 }
})).toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: 1, restrictTo: 'negativeAmount' },
rowData: { id: 1 }
})).toBeNull()
})

it('should render opening balance amounts', () => {
expect(instance.renderCellAmount({
cellData: { amount: 1, restrictTo: 'positiveAmount' },
rowData: { }
})).not.toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: 0, restrictTo: 'positiveAmount' },
rowData: { }
})).not.toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: -1, restrictTo: 'positiveAmount' },
rowData: { }
})).toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: 1, restrictTo: 'negativeAmount' },
rowData: { }
})).toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: 0, restrictTo: 'negativeAmount' },
rowData: { }
})).toBeNull()
expect(instance.renderCellAmount({
cellData: { amount: -1, restrictTo: 'negativeAmount' },
rowData: { }
})).not.toBeNull()
})
})

Expand Down
3 changes: 2 additions & 1 deletion src/core/Accounts/Transactions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export class TransactionsComponent extends React.Component {
accountId: account.id,
description: 'Opening balance',
amount: account.openingBalance,
createdAt: account.openingBalanceDate
createdAt: account.openingBalanceDate,
type: 'openingBalance'
}
return [openingBalanceTransaction, ...transactions].filter(transaction => (
transaction.accountId === account.id
Expand Down

0 comments on commit 703c5e7

Please sign in to comment.