|
1 | 1 | import React from 'react'; |
2 | | -import TableSortLabel from '@material-ui/core/TableSortLabel'; |
| 2 | +import Table from '@material-ui/core/Table'; |
| 3 | +import TableRow from '@material-ui/core/TableRow'; |
| 4 | +import TableBody from '@material-ui/core/TableBody'; |
| 5 | +import TableHead from '@material-ui/core/TableHead'; |
| 6 | +import TableFooter from '@material-ui/core/TableFooter'; |
| 7 | +import TablePagination from '@material-ui/core/TablePagination'; |
3 | 8 |
|
4 | | -import Table from '../ui/Table'; |
5 | | -import TableBody from '../ui/TableBody'; |
6 | | -import TableFooter from '../ui/TableFooter'; |
7 | | -import TableCell from '../ui/TableCell'; |
8 | | -import TableHead from '../ui/TableHead'; |
9 | | -import TableRow from '../ui/TableRow'; |
10 | | -import FileRow from './FileRow'; |
11 | 9 | import TableActions from '../ui/TableActions'; |
12 | | -import TablePagination from '../ui/TablePagination'; |
| 10 | +import TableHeadCell from '../ui/TableHeadCell'; |
| 11 | +import FileRow from './FileRow'; |
13 | 12 |
|
14 | | -export default function FileListTable({ |
| 13 | +function FileListTable({ |
15 | 14 | fileListDocument, |
16 | | - count = 0, |
17 | | - page = 0, |
18 | | - rowsPerPage = 10, |
19 | 15 | onChangePage, |
20 | 16 | onChangeRowsPerPage, |
| 17 | + rowsPerPageOptions, |
| 18 | + page, |
| 19 | + rowsPerPage, |
21 | 20 | onChangeOrder, |
22 | 21 | orderBy, |
23 | 22 | orderDirection, |
24 | 23 | }) { |
25 | | - const { file: fileList = [] } = fileListDocument; |
26 | | - const rowsPerPageOptions = [10, 100, 250]; |
27 | | - if (!rowsPerPageOptions.includes(rowsPerPage)) { rowsPerPageOptions.push(rowsPerPage); } |
| 24 | + if (fileListDocument === undefined) { |
| 25 | + return null; |
| 26 | + } |
| 27 | + const { file: fileList = [], hits: count = 0 } = fileListDocument; |
28 | 28 | return ( |
29 | | - <Table> |
30 | | - <TableHead> |
31 | | - <TableRow> |
32 | | - <TableCell> |
33 | | - <TableSortLabel |
34 | | - active={orderBy === 'filename'} |
35 | | - direction={orderDirection} |
36 | | - onClick={onChangeOrder ? onChangeOrder('filename') : undefined} |
37 | | - > |
38 | | - Path |
39 | | - </TableSortLabel> |
40 | | - </TableCell> |
41 | | - <TableCell> |
42 | | - <TableSortLabel |
43 | | - active={orderBy === 'fileId'} |
44 | | - direction={orderDirection} |
45 | | - onClick={onChangeOrder ? onChangeOrder('fileId') : undefined} |
46 | | - > |
47 | | - ID |
48 | | - </TableSortLabel> |
49 | | - </TableCell> |
50 | | - <TableCell> |
51 | | - <TableSortLabel |
52 | | - active={orderBy === 'state'} |
53 | | - direction={orderDirection} |
54 | | - onClick={onChangeOrder ? onChangeOrder('state') : undefined} |
55 | | - > |
56 | | - State |
57 | | - </TableSortLabel> |
58 | | - </TableCell> |
59 | | - <TableCell>Storage</TableCell> |
60 | | - <TableCell> |
61 | | - <TableSortLabel |
62 | | - active={orderBy === 'size'} |
63 | | - direction={orderDirection} |
64 | | - onClick={onChangeOrder ? onChangeOrder('size') : undefined} |
65 | | - > |
66 | | - Size |
67 | | - </TableSortLabel> |
68 | | - </TableCell> |
69 | | - <TableCell> |
70 | | - <TableSortLabel |
71 | | - active={orderBy === 'timestamp'} |
72 | | - direction={orderDirection} |
73 | | - onClick={onChangeOrder ? onChangeOrder('timestamp') : undefined} |
74 | | - > |
75 | | - Timestamp |
76 | | - </TableSortLabel> |
77 | | - </TableCell> |
78 | | - </TableRow> |
79 | | - </TableHead> |
80 | | - <TableBody> |
81 | | - {fileList.map((fileDocument) => ( |
82 | | - <FileRow |
83 | | - key={fileDocument.id} |
84 | | - fileDocument={fileDocument} |
85 | | - /> |
86 | | - ))} |
87 | | - </TableBody> |
88 | | - {onChangePage && ( |
89 | | - <TableFooter> |
90 | | - <TableRow> |
91 | | - <TablePagination |
92 | | - count={count} |
93 | | - page={page} |
94 | | - rowsPerPage={rowsPerPage} |
95 | | - onPageChange={onChangePage} |
96 | | - onRowsPerPageChange={onChangeRowsPerPage} |
97 | | - ActionsComponent={TableActions} |
98 | | - rowsPerPageOptions={rowsPerPageOptions} |
99 | | - /> |
100 | | - </TableRow> |
101 | | - </TableFooter> |
102 | | - )} |
103 | | - </Table> |
| 29 | + <> |
| 30 | + <Table> |
| 31 | + <TableHead> |
| 32 | + <TableRow> |
| 33 | + <TableHeadCell |
| 34 | + name="filename" |
| 35 | + onChangeOrder={onChangeOrder} |
| 36 | + orderBy={orderBy} |
| 37 | + orderDirection={orderDirection} |
| 38 | + /> |
| 39 | + <TableHeadCell |
| 40 | + name="fileId" |
| 41 | + onChangeOrder={onChangeOrder} |
| 42 | + orderBy={orderBy} |
| 43 | + orderDirection={orderDirection} |
| 44 | + /> |
| 45 | + <TableHeadCell |
| 46 | + name="state" |
| 47 | + onChangeOrder={onChangeOrder} |
| 48 | + orderBy={orderBy} |
| 49 | + orderDirection={orderDirection} |
| 50 | + /> |
| 51 | + <TableHeadCell name="Storage" /> |
| 52 | + <TableHeadCell |
| 53 | + name="size" |
| 54 | + onChangeOrder={onChangeOrder} |
| 55 | + orderBy={orderBy} |
| 56 | + orderDirection={orderDirection} |
| 57 | + /> |
| 58 | + <TableHeadCell |
| 59 | + name="timestamp" |
| 60 | + onChangeOrder={onChangeOrder} |
| 61 | + orderBy={orderBy} |
| 62 | + orderDirection={orderDirection} |
| 63 | + /> |
| 64 | + </TableRow> |
| 65 | + </TableHead> |
| 66 | + <TableBody> |
| 67 | + {fileList.map((fileDocument) => ( |
| 68 | + <FileRow key={fileDocument.id} fileDocument={fileDocument} /> |
| 69 | + ))} |
| 70 | + </TableBody> |
| 71 | + {onChangePage && onChangeRowsPerPage && ( |
| 72 | + <TableFooter> |
| 73 | + <TableRow> |
| 74 | + <TablePagination |
| 75 | + count={count} |
| 76 | + page={page} |
| 77 | + rowsPerPage={rowsPerPage} |
| 78 | + onPageChange={onChangePage} |
| 79 | + onRowsPerPageChange={onChangeRowsPerPage} |
| 80 | + ActionsComponent={TableActions} |
| 81 | + rowsPerPageOptions={rowsPerPageOptions} |
| 82 | + /> |
| 83 | + </TableRow> |
| 84 | + </TableFooter> |
| 85 | + )} |
| 86 | + </Table> |
| 87 | + </> |
104 | 88 | ); |
105 | 89 | } |
| 90 | + |
| 91 | +export default FileListTable; |
0 commit comments