Revize bf332c46
Přidáno uživatelem Václav Honzík před asi 3 roky(ů)
frontend/package.json | ||
---|---|---|
6 | 6 |
"dependencies": { |
7 | 7 |
"@emotion/react": "^11.8.2", |
8 | 8 |
"@emotion/styled": "^11.8.1", |
9 |
"@faker-js/faker": "^6.0.0", |
|
9 | 10 |
"@mui/icons-material": "^5.5.1", |
10 | 11 |
"@mui/material": "^5.5.2", |
11 | 12 |
"@testing-library/jest-dom": "^5.14.1", |
frontend/src/features/Catalog/Catalog.tsx | ||
---|---|---|
7 | 7 |
Stack, |
8 | 8 |
TextField, |
9 | 9 |
} from '@mui/material' |
10 |
import { useEffect, useState } from 'react' |
|
11 | 10 |
import { CatalogDto } from '../../swagger/data-contracts' |
12 | 11 |
import CatalogTable from './CatalogTable' |
12 |
import { faker } from '@faker-js/faker' |
|
13 | ||
13 | 14 | |
14 | 15 |
const Catalog = () => { |
16 | ||
17 |
// Creates a generic row for the table |
|
15 | 18 |
const createRow = (): CatalogDto => ({ |
16 |
name: 'Cell', |
|
17 |
certainty: 100, |
|
18 |
longitude: 1, |
|
19 |
latitude: 2, |
|
20 |
writtenForms: ['Written Form'], |
|
21 |
bibliography: ['Bibliography'], |
|
22 |
countries: ['Country'], |
|
23 |
alternativeNames: ['Alternative Name'], |
|
19 |
name: faker.commerce.product(), |
|
20 |
certainty: faker.random.number({ min: 1, max: 1000 }), |
|
21 |
longitude: faker.address.latitude() as unknown as number, |
|
22 |
latitude: faker.address.longitude() as unknown as number, |
|
23 |
writtenForms: [faker.name.firstName()], |
|
24 |
bibliography: [faker.name.lastName()], |
|
25 |
types: [faker.commerce.color()], |
|
26 |
countries: [faker.address.country()], |
|
27 |
alternativeNames: [faker.commerce.productName()], |
|
24 | 28 |
}) |
25 |
const data: CatalogDto[] = Array(25).fill(createRow())
|
|
29 |
const data: CatalogDto[] = Array(33).fill({}).map(() => createRow())
|
|
26 | 30 | |
27 | 31 |
return ( |
28 | 32 |
<> |
frontend/src/features/Catalog/CatalogService.ts | ||
---|---|---|
1 |
import axios from "../../api/axiosInstance" |
|
2 |
import { CatalogDto } from "../../swagger/data-contracts" |
|
3 | ||
4 |
export const getCatalogItems = async (componentMounted: boolean, setCatalog: (catalogItems: CatalogDto[]) => void, ) => { |
|
5 |
try { |
|
6 |
const { data } = await axios.get('/catalog') |
|
7 |
} |
|
8 |
catch (err: any) { |
|
9 | ||
10 |
} |
|
11 |
} |
|
12 | ||
13 |
export const getCatalogItem = (id: string) => { |
|
14 | ||
15 |
} |
frontend/src/features/Catalog/CatalogTable.tsx | ||
---|---|---|
2 | 2 |
import { |
3 | 3 |
Box, |
4 | 4 |
Paper, |
5 |
Stack, |
|
5 | 6 |
Table, |
6 | 7 |
TableBody, |
7 | 8 |
TableCell, |
8 | 9 |
TableContainer, |
9 | 10 |
TableFooter, |
11 |
TableHead, |
|
10 | 12 |
TablePagination, |
11 | 13 |
TableRow, |
14 |
Typography, |
|
12 | 15 |
} from '@mui/material' |
13 |
import TablePaginationActions, { TablePaginationActionsProps } from '@mui/material/TablePagination/TablePaginationActions' |
|
16 |
import TablePaginationActions, { |
|
17 |
TablePaginationActionsProps, |
|
18 |
} from '@mui/material/TablePagination/TablePaginationActions' |
|
14 | 19 |
import { FunctionComponent, useState } from 'react' |
15 | 20 |
import IconButton from '@mui/material/IconButton' |
16 | 21 |
import FirstPageIcon from '@mui/icons-material/FirstPage' |
... | ... | |
19 | 24 |
import LastPageIcon from '@mui/icons-material/LastPage' |
20 | 25 |
import { CatalogDto } from '../../swagger/data-contracts' |
21 | 26 | |
27 |
// Currently adapted from https://mui.com/components/tables/ |
|
22 | 28 | |
23 | 29 |
const CatalogTableActions: FunctionComponent<TablePaginationActionsProps> = ({ |
24 | 30 |
count, |
... | ... | |
122 | 128 |
createData('Oreo', 437, 18.0), |
123 | 129 |
].sort((a, b) => (a.calories < b.calories ? -1 : 1)) |
124 | 130 | |
125 | ||
126 | 131 |
export interface CatalogTableProps { |
127 | 132 |
data: CatalogDto[] |
128 | 133 |
} |
... | ... | |
149 | 154 |
setPage(0) |
150 | 155 |
} |
151 | 156 | |
157 |
// Table columns |
|
158 |
const columns = [ |
|
159 |
'Name', |
|
160 |
'Alternative names', |
|
161 |
'Written form', |
|
162 |
'Type', |
|
163 |
'State or territory', |
|
164 |
'Coordinates', |
|
165 |
'Certainty', |
|
166 |
] |
|
167 | ||
152 | 168 |
return ( |
153 |
<TableContainer component={Paper}> |
|
154 |
<Table sx={{ minWidth: 500 }} aria-label="custom pagination table"> |
|
169 |
// TODO remove mb |
|
170 |
<TableContainer component={Paper} sx={{mb: 16 }} > |
|
171 |
<Table |
|
172 |
sx={{ minWidth: 500 }} |
|
173 |
aria-label="sticky table" |
|
174 |
stickyHeader |
|
175 |
> |
|
176 |
<TableHead> |
|
177 |
<TableRow> |
|
178 |
{columns.map((col, idx) => ( |
|
179 |
<TableCell key={idx} align="left"> |
|
180 |
<Typography fontWeight="bold">{col}</Typography> |
|
181 |
</TableCell> |
|
182 |
))} |
|
183 |
</TableRow> |
|
184 |
</TableHead> |
|
155 | 185 |
<TableBody> |
156 | 186 |
{(rowsPerPage > 0 |
157 | 187 |
? data.slice( |
... | ... | |
164 | 194 |
<TableCell component="th" scope="row"> |
165 | 195 |
{row.name} |
166 | 196 |
</TableCell> |
167 |
<TableCell style={{ width: 160 }} align="right"> |
|
168 |
{row?.alternativeNames ? row.alternativeNames.join(', ') : ''} |
|
197 |
<TableCell> |
|
198 |
{row?.alternativeNames |
|
199 |
? row.alternativeNames.join(', ') |
|
200 |
: 'N/A'} |
|
201 |
</TableCell> |
|
202 |
<TableCell> |
|
203 |
{row?.writtenForms |
|
204 |
? row.writtenForms.join(', ') |
|
205 |
: 'N/A'} |
|
169 | 206 |
</TableCell> |
170 |
<TableCell style={{ width: 160 }} align="right">
|
|
171 |
{row?.writtenForms ? row.writtenForms.join(', ') : ''}
|
|
207 |
<TableCell> |
|
208 |
{row?.types ? row.types.join(', ') : 'N/A'}
|
|
172 | 209 |
</TableCell> |
173 |
<TableCell style={{ width: 160 }} align="right"> |
|
174 |
{row?.writtenForms ? row.writtenForms.join(', ') : ''} |
|
210 |
<TableCell> |
|
211 |
{/* Here should be State or Territory but not currently present in DTO */} |
|
212 |
{row?.countries |
|
213 |
? row.countries.join(', ') |
|
214 |
: 'N/A'} |
|
215 |
</TableCell> |
|
216 |
<TableCell> |
|
217 |
{row?.latitude && row?.longitude |
|
218 |
? `${row.latitude}, ${row.longitude}` |
|
219 |
: 'N/A'} |
|
220 |
</TableCell> |
|
221 |
<TableCell> |
|
222 |
{row?.certainty ? row.certainty : 'N/A'} |
|
175 | 223 |
</TableCell> |
176 | 224 |
</TableRow> |
177 | 225 |
))} |
178 |
{emptyRows > 0 && ( |
|
226 |
{/* {emptyRows > 0 && (
|
|
179 | 227 |
<TableRow style={{ height: 53 * emptyRows }}> |
180 | 228 |
<TableCell colSpan={6} /> |
181 | 229 |
</TableRow> |
182 |
)} |
|
230 |
)} */}
|
|
183 | 231 |
</TableBody> |
184 |
<TableFooter> |
|
185 |
<TableRow> |
|
186 |
<TablePagination |
|
187 |
rowsPerPageOptions={[ |
|
188 |
5, |
|
189 |
10, |
|
190 |
25, |
|
191 |
{ label: 'All', value: -1 }, |
|
192 |
]} |
|
193 |
colSpan={3} |
|
194 |
count={rows.length} |
|
232 |
</Table> |
|
233 |
<TablePagination |
|
234 |
rowsPerPageOptions={[5, 10, 25]} |
|
235 |
component="div" |
|
236 |
count={data.length} |
|
195 | 237 |
rowsPerPage={rowsPerPage} |
196 | 238 |
page={page} |
197 |
SelectProps={{ |
|
198 |
inputProps: { |
|
199 |
'aria-label': 'rows per page', |
|
200 |
}, |
|
201 |
native: true, |
|
202 |
}} |
|
203 | 239 |
onPageChange={handleChangePage} |
204 | 240 |
onRowsPerPageChange={handleChangeRowsPerPage} |
205 |
ActionsComponent={CatalogTableActions} |
|
206 | 241 |
/> |
207 |
</TableRow> |
|
208 |
</TableFooter> |
|
209 |
</Table> |
|
210 | 242 |
</TableContainer> |
211 | 243 |
) |
212 | 244 |
} |
frontend/src/features/Theme/themeReducer.ts | ||
---|---|---|
12 | 12 |
const initialTheme = createTheme({ |
13 | 13 |
palette: { |
14 | 14 |
mode: 'light' |
15 |
}, |
|
16 |
typography: { |
|
17 |
fontFamily: [ |
|
18 |
'-apple-system', |
|
19 |
'BlinkMacSystemFont', |
|
20 |
'"Segoe UI"', |
|
21 |
'Roboto', |
|
22 |
'"Helvetica Neue"', |
|
23 |
'Arial', |
|
24 |
'sans-serif', |
|
25 |
'"Apple Color Emoji"', |
|
26 |
'"Segoe UI Emoji"', |
|
27 |
'"Segoe UI Symbol"', |
|
28 |
].join(','), |
|
15 | 29 |
} |
16 | 30 |
}) |
17 | 31 |
const initialState: ThemeState = { |
Také k dispozici: Unified diff
re #9130 catalog header + fakerjs random data