aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
Diffstat (limited to 'modern')
-rw-r--r--modern/src/reports/TripReportPage.js117
1 files changed, 85 insertions, 32 deletions
diff --git a/modern/src/reports/TripReportPage.js b/modern/src/reports/TripReportPage.js
index c1ba6646..82c5439b 100644
--- a/modern/src/reports/TripReportPage.js
+++ b/modern/src/reports/TripReportPage.js
@@ -1,7 +1,7 @@
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, formatSpeed, formatHours, formatDate } from '../common/formatter';
+import { formatDistance, formatSpeed, formatHours, formatDate, formatVolume } from '../common/formatter';
import ReportFilter from './ReportFilter';
import ReportLayoutPage from './ReportLayoutPage';
import { useAttributePreference } from '../common/preferences';
@@ -30,40 +30,93 @@ const TripReportPage = () => {
const distanceUnit = useAttributePreference('distanceUnit');
const speedUnit = useAttributePreference('speedUnit');
+ 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('reportStartOdometer'),
+ field: 'startOdometer',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDistance(value, distanceUnit),
+ }, {
+ headerName: t('reportStartAddress'),
+ field: 'startAddress',
+ type: 'string',
+ hide: true,
+ flex: 1,
+ }, {
+ headerName: t('reportEndTime'),
+ field: 'endTime',
+ type: 'dateTime',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDate(value),
+ }, {
+ headerName: t('reportStartOdometer'),
+ field: 'endOdometer',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDistance(value, distanceUnit),
+ }, {
+ headerName: t('reportEndAddress'),
+ field: 'endAddress',
+ type: 'string',
+ hide: true,
+ flex: 1,
+ }, {
+ headerName: t('sharedDistance'),
+ field: 'distance',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatDistance(value, distanceUnit),
+ }, {
+ headerName: t('reportAverageSpeed'),
+ field: 'averageSpeed',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatSpeed(value, speedUnit),
+ }, {
+ headerName: t('reportMaximumSpeed'),
+ field: 'maxSpeed',
+ type: 'number',
+ flex: 1,
+ valueFormatter: ({ value }) => formatSpeed(value, speedUnit),
+ }, {
+ headerName: t('reportDuration'),
+ field: 'duration',
+ type: 'string',
+ flex: 1,
+ valueFormatter: ({ value }) => formatHours(value),
+ }, {
+ headerName: t('reportSpentFuel'),
+ field: 'spentFuel',
+ type: 'number',
+ flex: 1,
+ hide: true,
+ valueFormatter: ({ value }) => formatVolume(value, volumeUnit),
+ }, {
+ headerName: t('sharedDriver'),
+ field: 'driverName',
+ type: 'string',
+ flex: 1,
+ hide: true
+ }]
+
return (
<ReportLayoutPage filter={<Filter setItems={setItems} />}>
- <TableContainer component={Paper}>
- <Table>
- <TableHead>
- <TableRow>
- <TableCell>{t('reportStartTime')}</TableCell>
- <TableCell>{t('reportStartOdometer')}</TableCell>
- <TableCell>{t('reportEndTime')}</TableCell>
- <TableCell>{t('reportEndOdometer')}</TableCell>
- <TableCell>{t('sharedDistance')}</TableCell>
- <TableCell>{t('reportAverageSpeed')}</TableCell>
- <TableCell>{t('reportMaximumSpeed')}</TableCell>
- <TableCell>{t('reportDuration')}</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>{formatDistance(item.endOdometer, distanceUnit)}</TableCell>
- <TableCell>{formatDistance(item.distance, distanceUnit)}</TableCell>
- <TableCell>{formatSpeed(item.averageSpeed, speedUnit)}</TableCell>
- <TableCell>{formatSpeed(item.maxSpeed, speedUnit)}</TableCell>
- <TableCell>{formatHours(item.duration)}</TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- </TableContainer>
+ <DataGrid
+ rows={items}
+ columns={columns}
+ hideFooter
+ autoHeight
+ getRowId={() => Math.random()} />
</ReportLayoutPage>
);
}