From 9c2dbcf00b944cca546875af4f0bcab695119a40 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Fri, 27 Nov 2020 16:31:49 +0530 Subject: Chart report code improvements and refactoring --- modern/src/reports/ChartReportPage.js | 21 +++++++++++++-------- modern/src/reports/ReportLayoutPage.js | 11 +++++------ 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'modern/src/reports') diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js index 5aefca1..19ec9c1 100644 --- a/modern/src/reports/ChartReportPage.js +++ b/modern/src/reports/ChartReportPage.js @@ -3,7 +3,8 @@ import { Box, Paper } from '@material-ui/core'; import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; import { useAttributePreference } from '../common/preferences'; -import { getConverter, formatDate } from '../common/formatter'; +import { formatDate } from '../common/formatter'; +import { getConverter } from '../common/converter'; import {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; const ReportFilterForm = ({ setItems }) => { @@ -14,13 +15,17 @@ const ReportFilterForm = ({ setItems }) => { const query = new URLSearchParams({ deviceId, from, to, mail }); const response = await fetch(`/api/reports/route?${query.toString()}`, { headers }); if (response.ok) { + const data = await response.json(); - let formattedData = data.map((obj)=>{ - return Object.assign(obj, - {speed: Number(getConverter('speed')(obj.speed, speedUnit))}, - {fixTime: formatDate(obj.fixTime)} - ); - }) + + let formattedData = data.map(obj => { + return Object.assign( + obj, + {speed: Number(getConverter('speed')(obj.speed, speedUnit))}, + {fixTime: formatDate(obj.fixTime)} + ); + }); + setItems(formattedData); } } @@ -46,7 +51,7 @@ const ChartReportPage = () => { const [type, setType] = useState('speed'); return ( - + diff --git a/modern/src/reports/ReportLayoutPage.js b/modern/src/reports/ReportLayoutPage.js index 53b7039..51e4101 100644 --- a/modern/src/reports/ReportLayoutPage.js +++ b/modern/src/reports/ReportLayoutPage.js @@ -1,7 +1,6 @@ import React from 'react'; import { Grid, Paper, makeStyles, FormControl, InputLabel, Select, MenuItem } from '@material-ui/core'; import MainToolbar from '../MainToolbar'; -import { chartTypes } from '../common/chartTypes'; import t from '../common/localization'; const useStyles = makeStyles(theme => ({ @@ -24,7 +23,7 @@ const useStyles = makeStyles(theme => ({ }, })); -const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, setType, showChartType, children }) => { +const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, type, setType, showChartType, children }) => { const classes = useStyles(); return (
@@ -39,10 +38,10 @@ const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, setType {t('reportChartType')} - setType(e.target.value)}> + {t('positionSpeed')} + {t('positionAccuracy')} + {t('positionAltitude')} -- cgit v1.2.3