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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import classNames from 'classnames';
import DeleteIcon from '@material-ui/icons/Delete';
import EditIcon from '@material-ui/icons/BorderColor';
import DoneIcon from '@material-ui/icons/Done';
import css from 'ba-styles/Table.scss';
import { TableCell, IconButton } from '@material-ui/core';
import EditableCell from './EditableCell';
import SelectableCell from './SelectableCell';
import ToggleCell from './ToggleCell';
import DatePickerCell from './DatePickerCell';
import TimePickerCell from './TimePickerCell';
const styles = theme => ({
button: {
margin: theme.spacing(1),
},
});
class Row extends React.Component {
render() {
const {
classes,
anchor,
item,
removeRow,
updateRow,
editRow,
finishEditRow,
branch
} = this.props;
const eventDel = () => {
removeRow(item, branch);
};
const eventEdit = () => {
editRow(item, branch);
};
const eventDone = () => {
finishEditRow(item, branch);
};
const renderCell = dataArray => dataArray.map((itemCell, index) => {
if (itemCell.name !== 'action' && !itemCell.hidden) {
const inputType = anchor[index].type;
switch (inputType) {
case 'selection':
return (
<SelectableCell
updateRow={(event) => updateRow(event, branch)}
cellData={{
type: itemCell.name,
value: item.get(itemCell.name),
id: item.get('id'),
}}
edited={item.get('edited')}
key={index.toString()}
options={anchor[index].options}
branch={branch}
/>
);
case 'toggle':
return (
<ToggleCell
updateRow={(event) => updateRow(event, branch)}
cellData={{
type: itemCell.name,
value: item.get(itemCell.name),
id: item.get('id'),
}}
edited={item.get('edited')}
key={index.toString()}
branch={branch}
/>
);
case 'date':
return (
<DatePickerCell
updateRow={(event) => updateRow(event, branch)}
cellData={{
type: itemCell.name,
value: item.get(itemCell.name),
id: item.get('id'),
}}
edited={item.get('edited')}
key={index.toString()}
branch={branch}
/>
);
case 'time':
return (
<TimePickerCell
updateRow={(event) => updateRow(event, branch)}
cellData={{
type: itemCell.name,
value: item.get(itemCell.name),
id: item.get('id'),
}}
edited={item.get('edited')}
key={index.toString()}
branch={branch}
/>
);
default:
return (
<EditableCell
updateRow={(event) => updateRow(event, branch)}
cellData={{
type: itemCell.name,
value: item.get(itemCell.name),
id: item.get('id'),
}}
edited={item.get('edited')}
key={index.toString()}
inputType={inputType}
branch={branch}
/>
);
}
}
return false;
});
return (
<tr className={item.get('edited') ? css.editing : ''}>
{renderCell(anchor)}
<TableCell padding="none">
<IconButton
onClick={() => eventEdit(this)}
className={classNames((item.get('edited') ? css.hideAction : ''), classes.button)}
aria-label="Edit"
>
<EditIcon />
</IconButton>
<IconButton
onClick={() => eventDone(this)}
color="secondary"
className={classNames((!item.get('edited') ? css.hideAction : ''), classes.button)}
aria-label="Done"
>
<DoneIcon />
</IconButton>
<IconButton
onClick={() => eventDel(this)}
className={classes.button}
aria-label="Delete"
>
<DeleteIcon />
</IconButton>
</TableCell>
</tr>
);
}
}
Row.propTypes = {
classes: PropTypes.object.isRequired,
anchor: PropTypes.array.isRequired,
item: PropTypes.object.isRequired,
removeRow: PropTypes.func.isRequired,
updateRow: PropTypes.func.isRequired,
editRow: PropTypes.func.isRequired,
finishEditRow: PropTypes.func.isRequired,
branch: PropTypes.string.isRequired
};
export default withStyles(styles)(Row);
|