diff options
author | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-04-06 11:23:22 +0530 |
---|---|---|
committer | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-04-06 11:23:22 +0530 |
commit | 11c34f710c75a3d789b603d053e177a226b2f118 (patch) | |
tree | a8995bad569a47aef885bbc3558e6b531f202fd1 | |
parent | f8a35be5076e44b7c7e37978bf9c6822be965475 (diff) | |
download | trackermap-web-11c34f710c75a3d789b603d053e177a226b2f118.tar.gz trackermap-web-11c34f710c75a3d789b603d053e177a226b2f118.tar.bz2 trackermap-web-11c34f710c75a3d789b603d053e177a226b2f118.zip |
stoppage report data-grid conversion
-rw-r--r-- | modern/src/reports/StopReportPage.js | 81 |
1 files changed, 54 insertions, 27 deletions
diff --git a/modern/src/reports/StopReportPage.js b/modern/src/reports/StopReportPage.js index d06997e2..78731510 100644 --- a/modern/src/reports/StopReportPage.js +++ b/modern/src/reports/StopReportPage.js @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { TableContainer, Table, TableRow, TableCell, TableHead, TableBody, Paper } from '@material-ui/core'; +import { DataGrid } from '@material-ui/data-grid'; import t from '../common/localization'; import { formatDistance, formatHours, formatDate, formatVolume } from '../common/formatter'; import ReportFilter from './ReportFilter'; @@ -29,36 +29,63 @@ const Filter = ({ setItems }) => { const StopReportPage = () => { const distanceUnit = useAttributePreference('distanceUnit'); + const volumeUnit = useAttributePreference('volumeUnit'); + const [items, setItems] = useState([]); + + const columns = [{ + headerName: t('reportStartTime'), + field: 'startTime', + type: 'dateTime', + flex: 1, + valueFormatter: ({ value }) => formatDate(value), + }, { + headerName: t('positionOdometer'), + field: 'startOdometer', + type: 'number', + flex: 1, + valueFormatter: ({ value }) => formatDistance(value, distanceUnit), + }, { + headerName: t('positionAddress'), + field: 'address', + type: 'string', + hide: true, + flex: 1, + }, { + headerName: t('reportEndTime'), + field: 'endTime', + type: 'dateTime', + flex: 1, + valueFormatter: ({ value }) => formatDate(value), + }, { + headerName: t('reportDuration'), + field: 'duration', + type: 'string', + flex: 1, + valueFormatter: ({ value }) => formatHours(value), + }, { + headerName: t('reportEngineHours'), + field: 'engineHours', + type: 'string', + flex: 1, + valueFormatter: ({ value }) => formatHours(value), + }, { + headerName: t('reportSpentFuel'), + field: 'spentFuel', + type: 'number', + flex: 1, + hide: true, + valueFormatter: ({ value }) => formatVolume(value, volumeUnit), + }] return ( <ReportLayoutPage filter={<Filter setItems={setItems} />}> - <TableContainer component={Paper}> - <Table> - <TableHead> - <TableRow> - <TableCell>{t('reportStartTime')}</TableCell> - <TableCell>{t('positionOdometer')}</TableCell> - <TableCell>{t('reportEndTime')}</TableCell> - <TableCell>{t('reportDuration')}</TableCell> - <TableCell>{t('reportEngineHours')}</TableCell> - <TableCell>{t('reportSpentFuel')}</TableCell> - </TableRow> - </TableHead> - <TableBody> - {items.map((item) => ( - <TableRow key={item.id}> - <TableCell>{formatDate(item.startTime)}</TableCell> - <TableCell>{formatDistance(item.startOdometer, distanceUnit)}</TableCell> - <TableCell>{formatDate(item.endTime)}</TableCell> - <TableCell>{formatHours(item.duration)}</TableCell> - <TableCell>{formatHours(item.engineHours)}</TableCell> - <TableCell>{formatVolume(item.spentFuel)}</TableCell> - </TableRow> - ))} - </TableBody> - </Table> - </TableContainer> + <DataGrid + rows={items} + columns={columns} + hideFooter + autoHeight + getRowId={() => Math.random()} /> </ReportLayoutPage> ); }; |