From f863f37a9a4b375a6201732ab54474895fc8379d Mon Sep 17 00:00:00 2001
From: das31 <31259710+das31@users.noreply.github.com>
Date: Fri, 3 Feb 2023 20:11:00 -0500
Subject: [PATCH] CEC-3595-invalid-locations (#276)
* CEC-3595-invalid-locations
* fix ci
* added validate function
* resolve comments:
---
src/components/DigitalTwin/index.js | 4 ++++
src/components/VehicleMap/index.jsx | 3 ++-
src/utils/locations.js | 22 ++++++++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 src/utils/locations.js
diff --git a/src/components/DigitalTwin/index.js b/src/components/DigitalTwin/index.js
index a0c1141..8367a10 100644
--- a/src/components/DigitalTwin/index.js
+++ b/src/components/DigitalTwin/index.js
@@ -1,6 +1,7 @@
import React from "react";
import { LocalDateTimeString } from "../../utils/dates";
+import { ValidateLocationByParam } from "../../utils/locations"
import useStyles from "../useStyles";
const keyValueTemplate = (key, value) => (
@@ -83,6 +84,9 @@ const DigitalTwin = (props) => {
Location
{Object.entries(location).map((value) => {
+ if (ValidateLocationByParam(value[0], value[1]) === false) {
+ return keyValueTemplate(value[0], "Invalid")
+ }
if (value[0] === "altitude") {
return keyValueTemplate(value[0], value[1]);
} else {
diff --git a/src/components/VehicleMap/index.jsx b/src/components/VehicleMap/index.jsx
index 2069e51..ca1151d 100644
--- a/src/components/VehicleMap/index.jsx
+++ b/src/components/VehicleMap/index.jsx
@@ -7,6 +7,7 @@ import { Button } from "@material-ui/core";
import { useUserContext } from "../Contexts/UserContext";
import { useVehicleContext, VehicleProvider } from "../Contexts/VehicleContext";
import { VehiclePopUp } from "./popup";
+import { ValidateLocationData } from "../../utils/locations"
import GreenMarkerIcon from "../../assets/green-marker.png";
import GrayMarkerIcon from "../../assets/gray-marker.png";
import { logger } from "../../services/monitoring";
@@ -44,7 +45,7 @@ const Component = () => {
const retrieveAndStoreLocations = (accessToken) => {
return getLocations(accessToken)
.then((result) => {
- if (result.data != null) {
+ if (result.data != null && ValidateLocationData(result.data) !== false) {
const points = result.data.map((point) => [
point.latitude,
point.longitude,
diff --git a/src/utils/locations.js b/src/utils/locations.js
new file mode 100644
index 0000000..a308375
--- /dev/null
+++ b/src/utils/locations.js
@@ -0,0 +1,22 @@
+export const ValidateLocationData = (location) => {
+ if (Math.abs(location.latitude) > 90 || Math.abs(location.longitude) > 180) {
+ return false;
+ }
+ if (location.altitude === 1401) {
+ return false;
+ }
+ return true;
+}
+
+export const ValidateLocationByParam = (parameter, value) => {
+ switch (parameter) {
+ case "latitude":
+ return Math.abs(value) <= 90;
+ case "longitude":
+ return Math.abs(value) <= 180;
+ case "altitude":
+ return value !== 1401;
+ default:
+ return false;
+ }
+}