From f8a35be5076e44b7c7e37978bf9c6822be965475 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Thu, 1 Apr 2021 12:35:05 +0530 Subject: trip data-grid implementation --- modern/src/reports/TripReportPage.js | 117 +++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 32 deletions(-) diff --git a/modern/src/reports/TripReportPage.js b/modern/src/reports/TripReportPage.js index c1ba664..82c5439 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 ( }> - - - - - {t('reportStartTime')} - {t('reportStartOdometer')} - {t('reportEndTime')} - {t('reportEndOdometer')} - {t('sharedDistance')} - {t('reportAverageSpeed')} - {t('reportMaximumSpeed')} - {t('reportDuration')} - - - - {items.map((item) => ( - - {formatDate(item.startTime)} - {formatDistance(item.startOdometer, distanceUnit)} - {formatDate(item.endTime)} - {formatDistance(item.endOdometer, distanceUnit)} - {formatDistance(item.distance, distanceUnit)} - {formatSpeed(item.averageSpeed, speedUnit)} - {formatSpeed(item.maxSpeed, speedUnit)} - {formatHours(item.duration)} - - ))} - -
-
+ Math.random()} />
); } -- cgit v1.2.3