This repository was archived by the owner on May 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathindex.js
More file actions
72 lines (64 loc) · 1.83 KB
/
index.js
File metadata and controls
72 lines (64 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// @flow
import * as React from 'react';
import { connect } from 'react-redux';
import { getTransactions } from 'selectors/transactions';
import { getCategories } from 'selectors/categories';
import EntryFormRow from 'containers/EntryFormRow';
import type { Transaction } from 'modules/transactions';
import BudgetGridRow from 'components/BudgetGridRow';
import styles from './style.module.scss';
type BudgetGridProps = {
transactions: Transaction[],
categories: Object,
};
export class BudgetGrid extends React.Component<BudgetGridProps> {
state = {
editTransactionId: '',
};
editTransaction = (id: String) => {
this.setState({ editTransactionId: id });
};
getRowContent = (transaction, categories) =>
transaction.id === this.state.editTransactionId ? (
<EntryFormRow
key={transaction.id}
transaction={transaction}
categories={categories}
setEditTransaction={this.editTransaction}
/>
) : (
<BudgetGridRow
key={transaction.id}
transaction={transaction}
categories={categories}
setEditTransaction={this.editTransaction}
/>
);
render() {
const { transactions, categories } = this.props;
return (
<table className={styles.budgetGrid}>
<thead>
<tr>
<th>Category</th>
<th>Description</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
{transactions.map(
(transaction: Transaction): React.Element<any> => this.getRowContent(transaction, categories)
)}
</tbody>
<tfoot>
<EntryFormRow />
</tfoot>
</table>
);
}
}
const mapStateToProps = state => ({
transactions: getTransactions(state),
categories: getCategories(state),
});
export default connect(mapStateToProps)(BudgetGrid);