Skip to content

Commit

Permalink
Merge 703c5e7 into 12a4876
Browse files Browse the repository at this point in the history
  • Loading branch information
JackNeto committed Aug 9, 2019
2 parents 12a4876 + 703c5e7 commit facd24e
Show file tree
Hide file tree
Showing 16 changed files with 518 additions and 454 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lint": "eslint src --ext '.js,.jsx' --config .eslintrc",
"lint:fix": "npm run lint --fix",
"deploy:staging": "npm run build && aws s3 sync build/ s3://entaxy-staging",
"deploy:production": "npm run build && aws s3 sync build/ s3://entaxy-production",
"deploy:test": "npm run build && aws s3 sync build/ s3://entaxy-test"
},
"dependencies": {
Expand Down Expand Up @@ -102,4 +103,4 @@
"git add"
]
}
}
}
25 changes: 0 additions & 25 deletions src/common/Header/__tests__/__snapshots__/index.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,6 @@ exports[`Header matches snapshot 1`] = `
Dashboard
</span>
</a>
<a
aria-disabled={false}
className="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-colorInherit"
href="/accounts"
onBlur={[Function]}
onClick={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex={0}
>
<span
className="MuiButton-label"
>
Accounts
</span>
</a>
<button
aria-owns={null}
className="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-colorInherit"
Expand Down
1 change: 0 additions & 1 deletion src/common/Header/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import store from '../../../store'
import Header from '..'

jest.mock('../../LoginButton', () => 'LoginButton')
jest.mock('../../../core/Accounts', () => 'Accounts')

describe('Header', () => {
it('matches snapshot', () => {
Expand Down
6 changes: 0 additions & 6 deletions src/common/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ const Header = ({ children, match }) => {
>
Dashboard
</Button>
<Button
color={buttonColourFor(['/accounts', '/institutions'])}
component={LinkTo('/accounts')}
>
Accounts
</Button>
<Button
color={buttonColourFor('/budget')}
aria-owns={open ? 'budget-menu-list-grow' : null}
Expand Down
4 changes: 2 additions & 2 deletions src/common/ModalDialog/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CloseIcon from '@material-ui/icons/Close'
import Typography from '@material-ui/core/Typography'

const styles = () => ({
formwrapper: {
formWrapper: {
marginLeft: 15,
marginRight: 15
},
Expand Down Expand Up @@ -48,7 +48,7 @@ const ModalDialog = ({
onClose={onCancel}
className={className}
>
<div className={classes.formwrapper}>
<div className={classes.formWrapper}>
<DialogTitle disableTypography className={classes.formHeader}>
<Typography variant="h6">{title}</Typography>
<IconButton aria-label="Close" onClick={onCancel} className={classes.closeButton}>
Expand Down
116 changes: 61 additions & 55 deletions src/core/Accounts/Transactions/TransactionDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { withStyles } from '@material-ui/core/styles'
import { withFormik } from 'formik'
import * as Yup from 'yup'
import PropTypes from 'prop-types'
import Grid from '@material-ui/core/Grid'
import TextField from '@material-ui/core/TextField'
import format from 'date-fns/format'
import parse from 'date-fns/parse'
Expand All @@ -15,6 +16,7 @@ import { createTransaction, updateTransaction } from '../../../store/transaction

const styles = theme => ({
root: {
minWidth: 600
},
input: {
marginBottom: theme.spacing(1),
Expand Down Expand Up @@ -89,61 +91,65 @@ export const TransactionDialogComponent = ({
onCancel={onCancel}
className={classes.root}
>
<TextField
label="Description"
inputProps={{
'aria-label': 'Description',
maxLength: 256
}}
className={classes.input}
value={values.description}
name="description"
onChange={handleChange}
error={errors.description && touched.description}
helperText={errors.description}
/>
<AutoComplete
className={classes.input}
label="Category"
name="categoryId"
value={values.categoryId}
options={budget.categoryTree}
onChange={setFieldValue}
error={errors.categoryId && touched.categoryId}
helperText={errors.categoryId}
styles={colourStyles}
/>
<TextField
type="number"
label="Amount"
inputProps={{
'aria-label': 'Amount',
maxLength: 10,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER,
step: 0.01
}}
className={classes.input}
value={values.amount}
name="amount"
onChange={handleChange}
error={errors.amount && touched.amount}
helperText={errors.amount}
/>
<TextField
type="date"
label="Date"
InputLabelProps={{
shrink: true,
'aria-label': 'Date'
}}
name="createdAt"
className={classes.input}
value={values.createdAt}
onChange={handleChange}
error={errors.createdAt && touched.createdAt}
helperText={errors.createdAt}
/>
<Grid container>
<Grid item xs={12}>
<TextField
label="Description"
inputProps={{
'aria-label': 'Description',
maxLength: 256
}}
className={classes.input}
value={values.description}
name="description"
onChange={handleChange}
error={errors.description && touched.description}
helperText={errors.description}
/>
<AutoComplete
className={classes.input}
label="Category"
name="categoryId"
value={values.categoryId}
options={budget.categoryTree}
onChange={setFieldValue}
error={errors.categoryId && touched.categoryId}
helperText={errors.categoryId}
styles={colourStyles}
/>
<TextField
type="number"
label="Amount"
inputProps={{
'aria-label': 'Amount',
maxLength: 10,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER,
step: 0.01
}}
className={classes.input}
value={values.amount}
name="amount"
onChange={handleChange}
error={errors.amount && touched.amount}
helperText={errors.amount}
/>
<TextField
type="date"
label="Date"
InputLabelProps={{
shrink: true,
'aria-label': 'Date'
}}
name="createdAt"
className={classes.input}
value={values.createdAt}
onChange={handleChange}
error={errors.createdAt && touched.createdAt}
helperText={errors.createdAt}
/>
</Grid>
</Grid>
</ModalDialog>
)

Expand Down
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
Loading

0 comments on commit facd24e

Please sign in to comment.