From 34ec9a62ac0b65665f15f6e80729495e2558547f Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Tue, 24 Nov 2020 14:26:26 +0530 Subject: Refactoring and Improvements in chart report --- modern/src/reports/ChartReportPage.js | 90 ++++++++++++++++++---------------- modern/src/reports/ChartType.js | 53 -------------------- modern/src/reports/ReportLayoutPage.js | 4 +- 3 files changed, 50 insertions(+), 97 deletions(-) delete mode 100644 modern/src/reports/ChartType.js (limited to 'modern/src/reports') diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js index 68989331..e37f7ca1 100644 --- a/modern/src/reports/ChartReportPage.js +++ b/modern/src/reports/ChartReportPage.js @@ -1,43 +1,53 @@ import React, { useState } from 'react'; -import { Card, CardHeader, CardContent } from '@material-ui/core'; -import { Box, Divider } from '@material-ui/core'; -import { makeStyles } from '@material-ui/core/styles'; +import { Box, Paper, FormControl, InputLabel, Select, MenuItem } from '@material-ui/core'; import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; -import ChartType from './ChartType'; +import t from '../common/localization'; +import { chartTypes } from '../common/chartTypes'; +import { useAttributePreference } from '../common/preferences'; +import { getConverter, formatDate } from '../common/formatter'; import {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; -const useStyles = makeStyles((theme) => ({ - formControl: { - minWidth: 160, - }, -})); +const ReportFilterForm = ({ setItems, setType }) => { -const ReportFilterForm = ({ setItems }) => { + const speedUnit = useAttributePreference('speedUnit'); const handleSubmit = async (deviceId, from, to, mail, headers) => { const query = new URLSearchParams({ deviceId, from, to, mail }); const response = await fetch(`/api/reports/route?${query.toString()}`, { headers }); if (response.ok) { - const contentType = response.headers.get('content-type'); - if (contentType) { - if (contentType === 'application/json') { - setItems(await response.json()); - } else { - window.location.assign(window.URL.createObjectURL(await response.blob())); - } - } + const data = await response.json(); + let formattedData = data.map((obj)=>{ + return Object.assign(obj, + {speed: getConverter('speed')(obj.speed, speedUnit)}, + {fixTime: formatDate(obj.fixTime)} + ); + }) + setItems(formattedData); } - }; + } - return ; + return ( + + + {t('reportChartType')} + + + + ) }; -const CustomizedAxisTick = ({ x, y, stroke, payload }) =>{ +const CustomizedAxisTick = ({ x, y, payload }) =>{ + const parts = payload.value.split(' '); return ( - {payload.value} + {parts[0]} + {parts[1]} ); } @@ -48,27 +58,23 @@ const ChartReportPage = () => { const [type, setType] = useState('speed'); return ( - - - } /> - - - - - - } /> - - - - - - - - - - + + + + + + } height={60} /> + + + + + + + + + ); -} +}; export default ChartReportPage; diff --git a/modern/src/reports/ChartType.js b/modern/src/reports/ChartType.js deleted file mode 100644 index 586ea88a..00000000 --- a/modern/src/reports/ChartType.js +++ /dev/null @@ -1,53 +0,0 @@ -import React from 'react'; -import { FormControl, Select, MenuItem } from '@material-ui/core'; -import { makeStyles } from '@material-ui/core/styles'; -import t from '../common/localization'; - -const useStyles = makeStyles((theme) => ({ - formControl: { - minWidth: 160, - }, -})); - -const ChartType = ({ type, setType }) => { - const classes = useStyles(); - - return ( - - - - ); -} - -export default ChartType; diff --git a/modern/src/reports/ReportLayoutPage.js b/modern/src/reports/ReportLayoutPage.js index ddc7325b..e4219bfd 100644 --- a/modern/src/reports/ReportLayoutPage.js +++ b/modern/src/reports/ReportLayoutPage.js @@ -18,7 +18,7 @@ const useStyles = makeStyles(theme => ({ }, })); -const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, children }) => { +const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, setType, children }) => { const classes = useStyles(); return (
@@ -27,7 +27,7 @@ const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, childre - + -- cgit v1.2.3