From cb9728775b0e5eca8c705c0e2c61f9171b7068d9 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 20 Dec 2021 21:14:53 -0600 Subject: Upgraded http-proxy-middleware to 2.0.1 and fixed reports --- modern/.env | 2 +- modern/package.json | 1 + modern/src/common/formatter.js | 4 ++-- modern/src/map/Map.js | 5 +---- modern/src/reports/EventReportPage.js | 4 ++-- modern/src/reports/RouteReportPage.js | 2 +- modern/src/reports/StopReportPage.js | 6 +++--- modern/src/reports/SummaryReportPage.js | 4 ++-- modern/src/reports/TripReportPage.js | 2 +- modern/src/setupProxy.js | 9 +++++---- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/modern/.env b/modern/.env index 0a33603..a7cccf2 100644 --- a/modern/.env +++ b/modern/.env @@ -1,2 +1,2 @@ SKIP_PREFLIGHT_CHECK=true -REACT_APP_URL_NAME='http://trackermap.local' +REACT_APP_URL_NAME='etbsa.net' diff --git a/modern/package.json b/modern/package.json index 4ac9184..7fa085c 100644 --- a/modern/package.json +++ b/modern/package.json @@ -13,6 +13,7 @@ "@tmcw/togeojson": "^4.5.0", "@turf/circle": "^6.5.0", "@turf/turf": "^6.4.0", + "http-proxy-middleware": "^2.0.1", "mapbox-gl": "^1.13.1", "maplibre-gl": "^1.15.0", "material-ui-dropzone": "^3.5.0", diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index f8a55da..ad0ffa2 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -4,10 +4,10 @@ export const formatBoolean = (value, t) => (value ? t('sharedYes') : t('sharedNo export const formatNumber = (value, precision = 1) => Number(value.toFixed(precision)); -export const formatDate = (value, locale) => new Intl.DateTimeFormat(locale, { +export const formatDate = (value, locale = 'es') => value ? new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short', -}).format(Date.parse(value)); +}).format(new Date(value)) : ''; export const formatPosition = (value, key, t, locale = 'es') => { if (value != null && typeof value === 'object') { diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js index 8c9bf51..326d8d0 100644 --- a/modern/src/map/Map.js +++ b/modern/src/map/Map.js @@ -87,8 +87,6 @@ const Map = ({ children }) => { const [mapReady, setMapReady] = useState(false); const mapboxAccessToken = useAttributePreference('mapboxAccessToken'); - const mapTilerKey = useAttributePreference('mapTilerKey'); - const locationIqKey = useAttributePreference('locationIqKey', 'pk.0f147952a41c555a5b70614039fd148b'); useEffect(() => { maplibregl.accessToken = mapboxAccessToken; @@ -96,14 +94,13 @@ const Map = ({ children }) => { useEffect(() => { switcher.updateStyles([ - { id: 'locationIqStreets', title: t('mapLocationIqStreets'), uri: styleLocationIq('streets', locationIqKey) }, { id: 'osm', title: t('mapOsm'), uri: styleOsm() }, { id: 'carto', title: t('mapCarto'), uri: styleCarto() }, { id: 'gmapsStreets', title: t('mapGmapsStreets'), uri: styleGmapsStreets() }, { id: 'gmapsSatellite', title: t('mapGmapsSatellite'), uri: styleGmapsSatellite() }, { id: 'gmapsHybrid', title: t('mapGmapsHybrid'), uri: styleGmapsHybrid() }, ], 'gmapsStreets'); - }, [locationIqKey]); + }, []); useEffect(() => { const listener = (ready) => setMapReady(ready); diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js index b76ee95..45d13a2 100644 --- a/modern/src/reports/EventReportPage.js +++ b/modern/src/reports/EventReportPage.js @@ -5,7 +5,7 @@ import { } from '@material-ui/core'; import { useTheme } from '@material-ui/core/styles'; import { useSelector } from 'react-redux'; -import { formatDate } from '../common/formatter'; +import { formatDate, formatPosition } from '../common/formatter'; import ReportFilter from './ReportFilter'; import ReportLayout from './ReportLayout'; import { prefixString } from '../common/stringUtils'; @@ -83,7 +83,7 @@ const EventReportPage = () => { const columns = [{ headerName: t('positionFixTime'), - field: 'serverTime', + field: 'eventTime', type: 'dateTime', width: theme.dimensions.columnWidthDate, valueFormatter: ({ value }) => formatDate(value), diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js index 3be2107..a748334 100644 --- a/modern/src/reports/RouteReportPage.js +++ b/modern/src/reports/RouteReportPage.js @@ -3,7 +3,7 @@ import { Paper } from '@material-ui/core'; import { DataGrid } from '@material-ui/data-grid'; import { useTheme } from '@material-ui/core/styles'; import { - formatDistance, formatSpeed, formatBoolean, formatDate, formatCoordinate, + formatDistance, formatSpeed, formatBoolean, formatDate, formatCoordinate, formatPosition, } from '../common/formatter'; import ReportFilter from './ReportFilter'; import ReportLayout from './ReportLayout'; diff --git a/modern/src/reports/StopReportPage.js b/modern/src/reports/StopReportPage.js index aa668d5..f84b7e6 100644 --- a/modern/src/reports/StopReportPage.js +++ b/modern/src/reports/StopReportPage.js @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { DataGrid } from '@material-ui/data-grid'; import { useTheme } from '@material-ui/core/styles'; import { - formatDistance, formatHours, formatDate, formatVolume, + formatDistance, formatHours, formatDate, formatVolume, formatPosition, } from '../common/formatter'; import ReportFilter from './ReportFilter'; import ReportLayout from './ReportLayout'; @@ -68,13 +68,13 @@ const StopReportPage = () => { field: 'duration', type: 'string', width: theme.dimensions.columnWidthString, - valueFormatter: ({ value }) => formatHours(value), + valueFormatter: ({ value }) => formatHours(value, t), }, { headerName: t('reportEngineHours'), field: 'engineHours', type: 'string', width: theme.dimensions.columnWidthString, - valueFormatter: ({ value }) => formatHours(value), + valueFormatter: ({ value }) => formatHours(value, t), }, { headerName: t('reportSpentFuel'), field: 'spentFuel', diff --git a/modern/src/reports/SummaryReportPage.js b/modern/src/reports/SummaryReportPage.js index d993d2e..2199d49 100644 --- a/modern/src/reports/SummaryReportPage.js +++ b/modern/src/reports/SummaryReportPage.js @@ -59,7 +59,7 @@ const SummaryReportPage = () => { field: 'startTime', type: 'dateTime', width: theme.dimensions.columnWidthDate, - valueFormatter: ({ value }) => formatDate(value, 'YYYY-MM-DD'), + valueFormatter: ({ value }) => formatDate(value), }, { headerName: t('sharedDistance'), field: 'distance', @@ -95,7 +95,7 @@ const SummaryReportPage = () => { field: 'engineHours', type: 'string', width: theme.dimensions.columnWidthNumber, - valueFormatter: ({ value }) => formatHours(value), + valueFormatter: ({ value }) => formatHours(value, t), }, { headerName: t('reportSpentFuel'), field: 'spentFuel', diff --git a/modern/src/reports/TripReportPage.js b/modern/src/reports/TripReportPage.js index 632da7c..91c165d 100644 --- a/modern/src/reports/TripReportPage.js +++ b/modern/src/reports/TripReportPage.js @@ -99,7 +99,7 @@ const TripReportPage = () => { field: 'duration', type: 'string', width: theme.dimensions.columnWidthString, - valueFormatter: ({ value }) => formatHours(value), + valueFormatter: ({ value }) => formatHours(value, t), }, { headerName: t('reportSpentFuel'), field: 'spentFuel', diff --git a/modern/src/setupProxy.js b/modern/src/setupProxy.js index bc0daf0..7161414 100644 --- a/modern/src/setupProxy.js +++ b/modern/src/setupProxy.js @@ -1,8 +1,9 @@ /* eslint-disable import/no-extraneous-dependencies */ -const proxy = require('http-proxy-middleware'); +const { createProxyMiddleware } = require('http-proxy-middleware'); + module.exports = (app) => { - app.use(proxy('/api/socket', { target: `wss://${process.env.REACT_APP_URL_NAME}`, changeOrigin: true, ws: true })); - app.use(proxy('/api', { target: `https://${process.env.REACT_APP_URL_NAME}`, changeOrigin: true })); -}; \ No newline at end of file + app.use('/api/socket', createProxyMiddleware({ target: `wss://${process.env.REACT_APP_URL_NAME}`, changeOrigin: true, ws: true, protocolRewrite: 'wss' })); + app.use('/api', createProxyMiddleware({ target: `https://${process.env.REACT_APP_URL_NAME}`, changeOrigin: true, protocolRewrite: 'https', headers: { "Connection": "keep-alive" } })); +}; -- cgit v1.2.3