import React, { useState } from 'react'; import { DataGrid } from '@material-ui/data-grid'; import t from '../common/localization'; import { formatPosition, formatDistance } from '../common/formatter'; import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; import { useAttributePreference } from '../common/preferences'; const Filter = ({ setItems }) => { 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())); } } } } return ; }; const RouteReportPage = () => { const distanceUnit = useAttributePreference('distanceUnit'); const columns = [ { headerName: t('positionFixTime'), field: 'fixTime', width: 200, valueFormatter: params => formatPosition(params.value, 'fixTime'), }, { headerName: t('positionLatitude'), field: 'latitude', width: 130, valueFormatter: params => formatPosition(params.value, 'latitude'), }, { headerName: t('positionLongitude'), field: 'longitude', width: 130, valueFormatter: params => formatPosition(params.value, 'longitude'), }, { headerName: t('positionSpeed'), field: 'speed', width: 130, valueFormatter: params => formatPosition(params.value, 'speed'), }, { headerName: t('positionAddress'), field: 'address', width: 130, valueFormatter: params => formatPosition(params.value, 'address'), }, { headerName: t('positionIgnition'), field: 'ignition', width: 130, valueFormatter: params => params.getValue('attributes').ignition ? 'Yes' : 'No', }, { headerName: t('deviceTotalDistance'), hide: true, field: 'totalDistance', width: 160, valueFormatter: params => formatDistance(params.getValue('attributes').totalDistance, distanceUnit), }, ] const [items, setItems] = useState([]); return ( }> ); }; export default RouteReportPage;