From b217a08d311a7c21e88594894c01651c31cbf18e Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Thu, 5 Nov 2020 17:04:13 +0530 Subject: adding custome field to Report Filter on the basis of report type --- modern/src/reports/EventReportPage.js | 6 +- modern/src/reports/ReportFilter.js | 33 ++++++++++- modern/src/reports/RouteReportPage.js | 105 ++++------------------------------ 3 files changed, 46 insertions(+), 98 deletions(-) (limited to 'modern/src') diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js index fce9597f..6aaf4c55 100644 --- a/modern/src/reports/EventReportPage.js +++ b/modern/src/reports/EventReportPage.js @@ -25,13 +25,13 @@ const EventReportPage = () => { const classes = useStyles(); const [data, setData] = useState([]); - const handleSubmit = async (deviceId, from, to) => { + const handleSubmit = async (deviceId, from, to, type) => { const query = new URLSearchParams({ deviceId, from: from.toISOString(), to: to.toISOString(), }); - + type.map(t=>query.append('type',t)); const response = await fetch(`/api/reports/events?${query.toString()}`, { headers: { Accept: 'application/json' } }) if(response.ok) { @@ -47,7 +47,7 @@ const EventReportPage = () => { - + diff --git a/modern/src/reports/ReportFilter.js b/modern/src/reports/ReportFilter.js index be48413b..032b1976 100644 --- a/modern/src/reports/ReportFilter.js +++ b/modern/src/reports/ReportFilter.js @@ -5,11 +5,13 @@ 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'); const [from, setFrom] = useState(moment().subtract(1, 'hour')); const [to, setTo] = useState(moment()); + const [eventType, setEventType] = useState(['allEvents']); const handleShow = () => { let selectedFrom; @@ -45,8 +47,10 @@ const ReportFilter = (props) => { break; } - props.handleSubmit(deviceId, selectedFrom, selectedTo); - + if(reportType && reportType === 'event') + props.handleSubmit(deviceId, selectedFrom, selectedTo, eventType); + else + props.handleSubmit(deviceId, selectedFrom, selectedTo); } return ( @@ -59,6 +63,31 @@ const ReportFilter = (props) => { ))} + {reportType && reportType === 'event' && ( + + {t('reportEventTypes')} + + + )} {t('reportPeriod')} setDeviceId(e.target.value)}> - {devices.map((device) => ( - {device.name} - ))} - - - - {t('reportPeriod')} - - - {period === 'custom' && - setFrom(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL))} - fullWidth /> - } - {period === 'custom' && - setTo(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL))} - fullWidth /> - } - - - + -- cgit v1.2.3