RemovedFileTable.js
5.03 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
import React, { useState } from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import moment from 'moment';
import PerfectScrollbar from 'react-perfect-scrollbar';
import { makeStyles } from '@material-ui/styles';
import {
Card,
CardActions,
CardContent,
Avatar,
Checkbox,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
Typography,
TablePagination
} from '@material-ui/core';
import { getInitials } from 'helpers';
const useStyles = makeStyles(theme => ({
root: {},
content: {
padding: 0
},
inner: {
minWidth: 1050
},
nameContainer: {
display: 'flex',
alignItems: 'center'
},
avatar: {
marginRight: theme.spacing(2)
},
actions: {
justifyContent: 'flex-end'
}
}));
const RemovedFileTable = props => {
const { className, files: files, ...rest } = props;
const classes = useStyles();
const [selectedUsers, setSelectedUsers] = useState([]);
const [rowsPerPage, setRowsPerPage] = useState(10);
const [page, setPage] = useState(0);
const handleSelectAll = event => {
const { files } = props;
let selectedUsers;
if (event.target.checked) {
selectedUsers = files.map(user => user.id);
} else {
selectedUsers = [];
}
setSelectedUsers(selectedUsers);
};
const handleSelectOne = (event, id) => {
const selectedIndex = selectedUsers.indexOf(id);
let newSelectedUsers = [];
if (selectedIndex === -1) {
newSelectedUsers = newSelectedUsers.concat(selectedUsers, id);
} else if (selectedIndex === 0) {
newSelectedUsers = newSelectedUsers.concat(selectedUsers.slice(1));
} else if (selectedIndex === selectedUsers.length - 1) {
newSelectedUsers = newSelectedUsers.concat(selectedUsers.slice(0, -1));
} else if (selectedIndex > 0) {
newSelectedUsers = newSelectedUsers.concat(
selectedUsers.slice(0, selectedIndex),
selectedUsers.slice(selectedIndex + 1)
);
}
setSelectedUsers(newSelectedUsers);
};
const handlePageChange = (event, page) => {
setPage(page);
};
const handleRowsPerPageChange = event => {
setRowsPerPage(event.target.value);
};
return (
<Card
{...rest}
className={clsx(classes.root, className)}
>
<CardContent className={classes.content}>
<PerfectScrollbar>
<div className={classes.inner}>
<Table>
<TableHead>
<TableRow>
<TableCell padding="checkbox">
<Checkbox
checked={selectedUsers.length === files.length}
color="primary"
indeterminate={
selectedUsers.length > 0 &&
selectedUsers.length < files.length
}
onChange={handleSelectAll}
/>
</TableCell>
<TableCell>이름</TableCell>
<TableCell>마지막으로 수정한 날짜</TableCell>
<TableCell>크기</TableCell>
<TableCell>공유</TableCell>
</TableRow>
</TableHead>
<TableBody>
{files.slice(0, rowsPerPage).map(file => (
<TableRow
className={classes.tableRow}
hover
key={file.id}
selected={selectedUsers.indexOf(file.id) !== -1}
>
<TableCell padding="checkbox">
<Checkbox
checked={selectedUsers.indexOf(file.id) !== -1}
color="primary"
onChange={event => handleSelectOne(event, file.id)}
value="true"
/>
</TableCell>
<TableCell>
<div className={classes.nameContainer}>
{/* 파일 아이콘 */}
<Typography variant="body1">{file.name}</Typography>
</div>
</TableCell>
<TableCell>
{moment(file.modifiedAt).format('DD/MM/YYYY')}
</TableCell>
<TableCell>{file.size}</TableCell>
<TableCell>
{file.share}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</PerfectScrollbar>
</CardContent>
<CardActions className={classes.actions}>
<TablePagination
component="div"
count={files.length}
onChangePage={handlePageChange}
onChangeRowsPerPage={handleRowsPerPageChange}
page={page}
rowsPerPage={rowsPerPage}
rowsPerPageOptions={[5, 10, 25]}
/>
</CardActions>
</Card>
);
};
RemovedFileTable.propTypes = {
className: PropTypes.string,
files: PropTypes.array.isRequired
};
export default RemovedFileTable;