From f8bb2fb5dfd801b7c49a3a3b66042e94dc7640dc Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Sun, 13 Dec 2020 19:31:39 +0530 Subject: Refactored all the reports components to make them more generic --- modern/src/reports/ChartReportPage.js | 73 ++++++++++++++--------------------- 1 file changed, 30 insertions(+), 43 deletions(-) (limited to 'modern/src/reports/ChartReportPage.js') diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js index 6177341b..543c8a9e 100644 --- a/modern/src/reports/ChartReportPage.js +++ b/modern/src/reports/ChartReportPage.js @@ -1,14 +1,14 @@ import React, { useState } from 'react'; -import { Box, Paper, FormControl, InputLabel, Select, MenuItem } from '@material-ui/core'; -import ReportFilter from './ReportFilter'; +import { FormControl, InputLabel, Select, MenuItem } from '@material-ui/core'; import ReportLayoutPage from './ReportLayoutPage'; +import ReportFilter from './ReportFilter'; +import Graph from './Graph'; import { useAttributePreference } from '../common/preferences'; import { formatDate } from '../common/formatter'; import { speedConverter } from '../common/converter'; -import {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; import t from '../common/localization'; -const ReportFilterForm = ({ setItems, type, setType }) => { +const Filter = ({ children, setItems }) => { const speedUnit = useAttributePreference('speedUnit'); @@ -16,9 +16,7 @@ const ReportFilterForm = ({ setItems, type, setType }) => { const query = new URLSearchParams({ deviceId, from, to, mail }); const response = await fetch(`/api/reports/route?${query.toString()}`, { headers }); if (response.ok) { - const positions = await response.json(); - let formattedPositions = positions.map(position => { return { speed: Number(speedConverter(position.speed, speedUnit)), @@ -27,59 +25,48 @@ const ReportFilterForm = ({ setItems, type, setType }) => { fixTime: formatDate(position.fixTime) } }); - setItems(formattedPositions); } } - return ( <> - - {t('reportChartType')} - - + {children} ) -}; +} + +const ChartType = ({ type, setType }) => { -const CustomizedAxisTick = ({ x, y, payload }) =>{ - const parts = payload.value.split(' '); return ( - - {parts[0]} - {parts[1]} - - ); + + {t('reportChartType')} + + + ) } -const ChartReportPage = () => { +const ChartReportPage = () => { + const [items, setItems] = useState([]); const [type, setType] = useState('speed'); return ( - - - - - - } height={60} /> - - - - - - - - - - - ); -}; + <> + + + + }> + + + + ) +} export default ChartReportPage; -- cgit v1.2.3