From eb66706736e3557d78ffa12025c9d863f0023e95 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 3 Dec 2024 14:00:25 -0500 Subject: [PATCH] Changing to use isValidGPSInputNew --- .../app/components/groups/EditGroupModalComponent.tsx | 4 ---- .../app/components/meters/CreateMeterModalComponent.tsx | 3 --- .../app/components/meters/EditMeterModalComponent.tsx | 9 ++++----- src/client/app/utils/calibration.ts | 3 ++- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/client/app/components/groups/EditGroupModalComponent.tsx b/src/client/app/components/groups/EditGroupModalComponent.tsx index f4acd338c..a7e17b52e 100644 --- a/src/client/app/components/groups/EditGroupModalComponent.tsx +++ b/src/client/app/components/groups/EditGroupModalComponent.tsx @@ -298,10 +298,6 @@ export default function EditGroupModalComponent(props: EditGroupModalComponentPr latitude: gpsValues[latitudeIndex] }; } else if ((gpsInput as string).length !== 0) { - // GPS not okay and there since non-zero length value. - // TODO isValidGPSInput currently pops up an alert so not doing it here, may change - // so leaving code commented out. - // showErrorNotification(translate('input.gps.range') + groupState.gps + '.'); showErrorNotification(message); inputOk = false; } diff --git a/src/client/app/components/meters/CreateMeterModalComponent.tsx b/src/client/app/components/meters/CreateMeterModalComponent.tsx index c75d97941..4e57a3dc2 100644 --- a/src/client/app/components/meters/CreateMeterModalComponent.tsx +++ b/src/client/app/components/meters/CreateMeterModalComponent.tsx @@ -134,9 +134,6 @@ export default function CreateMeterModalComponent(props: CreateMeterModalProps): }; } else if (gpsInput.length !== 0) { // GPS not okay. Only true if some input. - // TODO isValidGPSInput currently pops up an alert so not doing it here, may change - // so leaving code commented out. - // showErrorNotification(translate('input.gps.range') + state.gps + '.'); showErrorNotification(message); inputOk = false; } diff --git a/src/client/app/components/meters/EditMeterModalComponent.tsx b/src/client/app/components/meters/EditMeterModalComponent.tsx index 59afc37a7..eec06fbf1 100644 --- a/src/client/app/components/meters/EditMeterModalComponent.tsx +++ b/src/client/app/components/meters/EditMeterModalComponent.tsx @@ -22,7 +22,7 @@ import { tooltipBaseStyle } from '../../styles/modalStyle'; import { TrueFalseType } from '../../types/items'; import { MeterData, MeterTimeSortType, MeterType } from '../../types/redux/meters'; import { UnitRepresentType } from '../../types/redux/units'; -import { GPSPoint, isValidGPSInput } from '../../utils/calibration'; +import { GPSPoint, isValidGPSInputNew } from '../../utils/calibration'; import { AreaUnitType } from '../../utils/getAreaUnitConversion'; import { getGPSString, nullToEmptyString } from '../../utils/input'; import { showErrorNotification } from '../../utils/notifications'; @@ -105,7 +105,8 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr // If the user input a value then gpsInput should be a string. // null came from the DB and it is okay to just leave it - Not a string. if (typeof gpsInput === 'string') { - if (isValidGPSInput(gpsInput)) { + const {validGps, message} = isValidGPSInputNew(gpsInput); + if (validGps) { // Clearly gpsInput is a string but TS complains about the split so cast. const gpsValues = (gpsInput as string).split(',').map((value: string) => parseFloat(value)); // It is valid and needs to be in this format for routing. @@ -116,9 +117,7 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr // gpsInput must be of type string but TS does not think so so cast. } else if ((gpsInput as string).length !== 0) { // GPS not okay. - // TODO isValidGPSInput currently tops up an alert so not doing it here, may change - // so leaving code commented out. - // showErrorNotification(translate('input.gps.range') + state.gps + '.'); + showErrorNotification(message); inputOk = false; } } diff --git a/src/client/app/utils/calibration.ts b/src/client/app/utils/calibration.ts index 6cba8579c..08b951e85 100644 --- a/src/client/app/utils/calibration.ts +++ b/src/client/app/utils/calibration.ts @@ -78,7 +78,8 @@ export interface Dimensions { export function itemMapInfoOk(itemID: number, type: DataType, map: MapMetadata, gps?: GPSPoint): boolean { if (map === undefined) { return false; } if ((gps === null || gps === undefined) || map.origin === undefined || map.opposite === undefined) { return false; } - if (!isValidGPSInput(`${gps.latitude},${gps.longitude}`)) { + const {validGps} = isValidGPSInputNew(`${gps.latitude},${gps.longitude}`); + if (!validGps) { logToServer('error', `Found invalid ${type === DataType.Meter ? 'meter' : 'group'} gps stored in database, id = ${itemID}`)(); return false; }