From 449e5e3190d22704a2cb4d7c5ce3e90eaaf16153 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Sun, 8 Nov 2020 12:15:17 +0530 Subject: Report Layout Unification with seperate report layout component --- modern/src/reports/EventReportPage.js | 171 +++++++++++++++------------------- modern/src/reports/ReportFilter.js | 3 +- modern/src/reports/ReportView.js | 47 ++++++++++ modern/src/reports/RouteReportPage.js | 116 +++++++++-------------- 4 files changed, 167 insertions(+), 170 deletions(-) create mode 100644 modern/src/reports/ReportView.js diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js index fb037597..cb3a06aa 100644 --- a/modern/src/reports/EventReportPage.js +++ b/modern/src/reports/EventReportPage.js @@ -1,111 +1,88 @@ import React, { useState } from 'react'; -import MainToolbar from '../MainToolbar'; -import { Grid, TableContainer, Table, TableRow, TableCell, TableHead, TableBody, Paper, makeStyles } from '@material-ui/core'; +import { TableContainer, Table, TableRow, TableCell, TableHead, TableBody, Paper } from '@material-ui/core'; import { FormControl, InputLabel, Select, MenuItem } from '@material-ui/core'; import t from '../common/localization'; import { formatPosition } from '../common/formatter'; import ReportFilter from './ReportFilter'; - -const useStyles = makeStyles(theme => ({ - root: { - height: '100%', - display: 'flex', - flexDirection: 'column', - }, - content: { - flex: 1, - overflow: 'auto', - padding: theme.spacing(2), - }, - form: { - padding: theme.spacing(1, 2, 2), - }, -})); +import ReportView from './ReportView'; const EventReportPage = () => { - const classes = useStyles(); - const [data, setData] = useState([]); - const [eventType, setEventType] = useState(['allEvents']); - const handleSubmit = async (deviceId, from, to) => { - const query = new URLSearchParams({ - deviceId, - from: from.toISOString(), - to: to.toISOString(), - }); - eventType.map(t=>query.append('type',t)); - const response = await fetch(`/api/reports/events?${query.toString()}`, { headers: { Accept: 'application/json' } }) + const ReportFilterForm = ({ onResult }) => { + const [eventType, setEventType] = useState(['allEvents']); + + const handleSubmit = async (deviceId, from, to) => { + const query = new URLSearchParams({ + deviceId, + from: from.toISOString(), + to: to.toISOString(), + }); + eventType.map(t=>query.append('type',t)); + const response = await fetch(`/api/reports/events?${query.toString()}`, { headers: { Accept: 'application/json' } }); + if(response.ok) { + onResult(await response.json()); + } + } + return ( + + + {t('reportEventTypes')} + + + + ); + } + + const ReportListView = ({items}) => { - if(response.ok) { - const data = await response.json(); - setData(data); - } + return ( + + + + + {t('positionFixTime')} + {t('sharedType')} + {t('sharedGeofence')} + {t('sharedMaintenance')} + + + + {items.map((item) => ( + + + {formatPosition(item, 'serverTime')} + + {item.type} + {} + {} + + ))} + +
+
+ ); } - return ( -
- -
- - - - - - {t('reportEventTypes')} - - - - - - - - - - - {t('positionFixTime')} - {t('sharedType')} - {t('sharedGeofence')} - {t('sharedMaintenance')} - - - - {data.map((item) => ( - - - {formatPosition(item, 'serverTime')} - - {item.type} - {} - {} - - ))} - -
-
-
-
-
-
- ); + return ; } export default EventReportPage; diff --git a/modern/src/reports/ReportFilter.js b/modern/src/reports/ReportFilter.js index 6fe6a529..0d3223ff 100644 --- a/modern/src/reports/ReportFilter.js +++ b/modern/src/reports/ReportFilter.js @@ -5,7 +5,6 @@ import { useSelector } from 'react-redux'; import moment from 'moment'; const ReportFilter = (props) => { - const { reportType } = props; const devices = useSelector((state) => Object.values(state.devices.items)); const [deviceId, setDeviceId] = useState(); const [period, setPeriod] = useState('today'); @@ -61,7 +60,7 @@ const ReportFilter = (props) => { {props.children} - + {t('reportPeriod')}