From c37869b66da935a3d749924be5b82ebe1df41eab Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 25 Dec 2024 19:18:16 +0100 Subject: [PATCH] fix(coords): issue over coords toFixed(2) - 2 number over the decimal only for every coords --- .../layout/mission-page-header-wrapper.tsx | 1 - .../features/common/hooks/use-coordinate.tsx | 10 ++++++++-- .../mission-action-item-env-control.tsx | 1 - .../mission-action-item-nav-control.tsx | 2 +- .../use-mission-action-anti-pollution.tsx | 4 +++- .../hooks/use-mission-action-fish-control.tsx | 4 +++- ...mission-action-generic-date-observation.tsx | 18 ++++++++++-------- .../use-mission-action-illegal-immigration.tsx | 4 +++- .../hooks/use-mission-action-nav-control.tsx | 4 +++- .../hooks/use-mission-action-rescue.tsx | 4 +++- 10 files changed, 34 insertions(+), 18 deletions(-) diff --git a/frontend/src/v2/features/common/components/layout/mission-page-header-wrapper.tsx b/frontend/src/v2/features/common/components/layout/mission-page-header-wrapper.tsx index 584fda790..506ce017a 100644 --- a/frontend/src/v2/features/common/components/layout/mission-page-header-wrapper.tsx +++ b/frontend/src/v2/features/common/components/layout/mission-page-header-wrapper.tsx @@ -36,7 +36,6 @@ const MissionPageHeaderWrapper: React.FC = ({ onClickExport, exportLoading }) => { - //const exportRapportEnabled = useIsMissionCompleteForStats(mission?.id) const { formatMissionName } = useDate() const exportRapportEnabled = mission?.completenessForStats?.status === CompletenessForStatsStatusEnum.COMPLETE diff --git a/frontend/src/v2/features/common/hooks/use-coordinate.tsx b/frontend/src/v2/features/common/hooks/use-coordinate.tsx index ec0d8e149..9410ecc19 100644 --- a/frontend/src/v2/features/common/hooks/use-coordinate.tsx +++ b/frontend/src/v2/features/common/hooks/use-coordinate.tsx @@ -1,4 +1,5 @@ interface CoordinateHook { + getCoords: (lat?: number, lng?: number) => [number?, number?] extractLatLngFromMultiPoint: (value?: string) => [number?, number?] } @@ -12,14 +13,19 @@ export function useCoordinate(): CoordinateHook { const latitude = parseFloat(match[2]) const longitude = parseFloat(match[1]) if (!isNaN(latitude) && !isNaN(longitude)) { - lat = latitude - lng = longitude + lat = Number(latitude.toFixed(2)) + lng = Number(longitude.toFixed(2)) } } return [lat, lng] } + const getCoords = (lat?: number, lng?: number): [number?, number?] => { + return [lat ? Number(lat.toFixed(2)) : 0, lng ? Number(lng.toFixed(2)) : 0] + } + return { + getCoords, extractLatLngFromMultiPoint } } diff --git a/frontend/src/v2/features/mission-action/components/elements/mission-action-item-env-control.tsx b/frontend/src/v2/features/mission-action/components/elements/mission-action-item-env-control.tsx index cc60ff327..ca9d09bb7 100644 --- a/frontend/src/v2/features/mission-action/components/elements/mission-action-item-env-control.tsx +++ b/frontend/src/v2/features/mission-action/components/elements/mission-action-item-env-control.tsx @@ -142,7 +142,6 @@ const MissionActionItemEnvControl: React.FC = diff --git a/frontend/src/v2/features/mission-action/components/elements/mission-action-item-nav-control.tsx b/frontend/src/v2/features/mission-action/components/elements/mission-action-item-nav-control.tsx index 7a1678952..aefca8dc1 100644 --- a/frontend/src/v2/features/mission-action/components/elements/mission-action-item-nav-control.tsx +++ b/frontend/src/v2/features/mission-action/components/elements/mission-action-item-nav-control.tsx @@ -3,8 +3,8 @@ import { FormikEffect, FormikTextarea } from '@mtes-mct/monitor-ui' import { Formik } from 'formik' import { FC } from 'react' import { Stack } from 'rsuite' -import { MissionActionOutput } from 'src/v2/features/common/types/mission-action-output' import { FormikSelectVesselSize } from '../../../common/components/ui/formik-select-vessel-size' +import { MissionActionOutput } from '../../../common/types/mission-action-output' import MissionControlNavForm from '../../../mission-control/components/elements/mission-control-nav-form' import MissionControlNavSummary from '../../../mission-control/components/ui/mission-control-nav-summary' import { useMissionActionNavControl } from '../../hooks/use-mission-action-nav-control' diff --git a/frontend/src/v2/features/mission-action/hooks/use-mission-action-anti-pollution.tsx b/frontend/src/v2/features/mission-action/hooks/use-mission-action-anti-pollution.tsx index fcf29ccc8..51028209f 100644 --- a/frontend/src/v2/features/mission-action/hooks/use-mission-action-anti-pollution.tsx +++ b/frontend/src/v2/features/mission-action/hooks/use-mission-action-anti-pollution.tsx @@ -1,5 +1,6 @@ import { FormikErrors } from 'formik' import { useAbstractFormik } from '../../common/hooks/use-abstract-formik-form' +import { useCoordinate } from '../../common/hooks/use-coordinate' import { useDate } from '../../common/hooks/use-date' import { AbstractFormikSubFormHook } from '../../common/types/abstract-formik-hook' import { MissionActionOutput } from '../../common/types/mission-action-output' @@ -10,13 +11,14 @@ export function useMissionActionAntiPollution( action: MissionActionOutput, onChange: (newAction: MissionActionOutput) => Promise ): AbstractFormikSubFormHook { + const { getCoords } = useCoordinate() const value = action?.data as MissionNavActionDataOutput const { preprocessDateForPicker, postprocessDateFromPicker } = useDate() const fromFieldValueToInput = (data: MissionNavActionDataOutput): ActionAntiPollutionInput => { const endDate = preprocessDateForPicker(data.endDateTimeUtc) const startDate = preprocessDateForPicker(data.startDateTimeUtc) - return { ...data, dates: [startDate, endDate], geoCoords: [data.latitude, data.longitude] } + return { ...data, dates: [startDate, endDate], geoCoords: getCoords(data.latitude, data.longitude) } } const fromInputToFieldValue = (value: ActionAntiPollutionInput): MissionNavActionDataOutput => { diff --git a/frontend/src/v2/features/mission-action/hooks/use-mission-action-fish-control.tsx b/frontend/src/v2/features/mission-action/hooks/use-mission-action-fish-control.tsx index cc11d6efe..4de36d605 100644 --- a/frontend/src/v2/features/mission-action/hooks/use-mission-action-fish-control.tsx +++ b/frontend/src/v2/features/mission-action/hooks/use-mission-action-fish-control.tsx @@ -1,5 +1,6 @@ import { FormikErrors } from 'formik' import { useAbstractFormik } from '../../common/hooks/use-abstract-formik-form' +import { useCoordinate } from '../../common/hooks/use-coordinate' import { useDate } from '../../common/hooks/use-date' import { AbstractFormikSubFormHook } from '../../common/types/abstract-formik-hook' import { MissionActionOutput } from '../../common/types/mission-action-output' @@ -11,6 +12,7 @@ export function useMissionActionFishControl( onChange: (newAction: MissionActionOutput, debounceTime?: number) => Promise, isMissionFinished?: boolean ): AbstractFormikSubFormHook { + const { getCoords } = useCoordinate() const value = action?.data as MissionFishActionDataOutput const { preprocessDateForPicker, postprocessDateFromPicker } = useDate() @@ -21,7 +23,7 @@ export function useMissionActionFishControl( ...data, dates: [startDate, endDate], isMissionFinished: !!isMissionFinished, - geoCoords: [data.latitude, data.longitude] //TODO: Check coords 2 number after the comma unless, it will trigger a diff + geoCoords: getCoords(data.latitude, data.longitude) } } diff --git a/frontend/src/v2/features/mission-action/hooks/use-mission-action-generic-date-observation.tsx b/frontend/src/v2/features/mission-action/hooks/use-mission-action-generic-date-observation.tsx index 2f2b0dec6..fbae1d969 100644 --- a/frontend/src/v2/features/mission-action/hooks/use-mission-action-generic-date-observation.tsx +++ b/frontend/src/v2/features/mission-action/hooks/use-mission-action-generic-date-observation.tsx @@ -2,7 +2,8 @@ import { FormikErrors } from 'formik' import { useAbstractFormik } from '../../common/hooks/use-abstract-formik-form' import { useDate } from '../../common/hooks/use-date' import { AbstractFormikSubFormHook } from '../../common/types/abstract-formik-hook' -import { MissionActionDataOutput, MissionActionOutput } from '../../common/types/mission-action-output' +import { MissionActionData } from '../../common/types/mission-action-data' +import { MissionActionOutput } from '../../common/types/mission-action-output' import { ActionGenericDateObservationInput } from '../types/action-type' export function useMissionActionGenericDateObservation( @@ -11,25 +12,26 @@ export function useMissionActionGenericDateObservation( ): AbstractFormikSubFormHook { const { preprocessDateForPicker, postprocessDateFromPicker } = useDate() - const fromFieldValueToInput = (data: MissionActionDataOutput): ActionGenericDateObservationInput => { + const fromFieldValueToInput = (data: MissionActionData): ActionGenericDateObservationInput => { const endDate = preprocessDateForPicker(data.endDateTimeUtc) const startDate = preprocessDateForPicker(data.startDateTimeUtc) return { ...data, dates: [startDate, endDate] } } - const fromInputToFieldValue = (value: ActionGenericDateObservationInput): MissionActionDataOutput => { + const fromInputToFieldValue = (value: ActionGenericDateObservationInput): MissionActionData => { const { dates, ...newData } = value const endDateTimeUtc = postprocessDateFromPicker(dates[1]) const startDateTimeUtc = postprocessDateFromPicker(dates[0]) return { ...newData, startDateTimeUtc, endDateTimeUtc } } - const { initValue, handleSubmit, isError } = useAbstractFormik< - MissionActionDataOutput, - ActionGenericDateObservationInput - >(action.data, fromFieldValueToInput, fromInputToFieldValue) + const { initValue, handleSubmit, isError } = useAbstractFormik( + action.data, + fromFieldValueToInput, + fromInputToFieldValue + ) - const onSubmit = async (valueToSubmit?: MissionActionDataOutput) => { + const onSubmit = async (valueToSubmit?: MissionActionData) => { if (!valueToSubmit) return await onChange({ ...action, data: valueToSubmit }) } diff --git a/frontend/src/v2/features/mission-action/hooks/use-mission-action-illegal-immigration.tsx b/frontend/src/v2/features/mission-action/hooks/use-mission-action-illegal-immigration.tsx index b1de74b90..1d205f8ab 100644 --- a/frontend/src/v2/features/mission-action/hooks/use-mission-action-illegal-immigration.tsx +++ b/frontend/src/v2/features/mission-action/hooks/use-mission-action-illegal-immigration.tsx @@ -1,6 +1,7 @@ import { FormikErrors } from 'formik' import { boolean, number, object } from 'yup' import { useAbstractFormik } from '../../common/hooks/use-abstract-formik-form' +import { useCoordinate } from '../../common/hooks/use-coordinate' import { useDate } from '../../common/hooks/use-date' import { AbstractFormikSubFormHook } from '../../common/types/abstract-formik-hook' import { MissionActionOutput } from '../../common/types/mission-action-output' @@ -12,6 +13,7 @@ export function useMissionActionIllegalImmigration( onChange: (newAction: MissionActionOutput) => Promise, isMissionFinished?: boolean ): AbstractFormikSubFormHook { + const { getCoords } = useCoordinate() const value = action?.data as MissionNavActionDataOutput const { preprocessDateForPicker, postprocessDateFromPicker } = useDate() @@ -22,7 +24,7 @@ export function useMissionActionIllegalImmigration( ...data, dates: [startDate, endDate], isMissionFinished: !!isMissionFinished, - geoCoords: [data.latitude, data.longitude] + geoCoords: getCoords(data.latitude, data.longitude) } } diff --git a/frontend/src/v2/features/mission-action/hooks/use-mission-action-nav-control.tsx b/frontend/src/v2/features/mission-action/hooks/use-mission-action-nav-control.tsx index 38bad9d26..717f557a0 100644 --- a/frontend/src/v2/features/mission-action/hooks/use-mission-action-nav-control.tsx +++ b/frontend/src/v2/features/mission-action/hooks/use-mission-action-nav-control.tsx @@ -2,6 +2,7 @@ import { VesselSizeEnum } from '@common/types/env-mission-types' import { FormikErrors } from 'formik' import { boolean, mixed, object, string } from 'yup' import { useAbstractFormik } from '../../common/hooks/use-abstract-formik-form' +import { useCoordinate } from '../../common/hooks/use-coordinate' import { useDate } from '../../common/hooks/use-date' import { AbstractFormikSubFormHook } from '../../common/types/abstract-formik-hook' import { MissionActionOutput } from '../../common/types/mission-action-output' @@ -13,6 +14,7 @@ export function useMissionActionNavControl( onChange: (newAction: MissionActionOutput) => Promise, isMissionFinished?: boolean ): AbstractFormikSubFormHook { + const { getCoords } = useCoordinate() const value = action?.data as MissionNavActionDataOutput const { preprocessDateForPicker, postprocessDateFromPicker } = useDate() @@ -23,7 +25,7 @@ export function useMissionActionNavControl( ...data, dates: [startDate, endDate], isMissionFinished: !!isMissionFinished, - geoCoords: [data.latitude, data.longitude] + geoCoords: getCoords(data.latitude, data.longitude) } } diff --git a/frontend/src/v2/features/mission-action/hooks/use-mission-action-rescue.tsx b/frontend/src/v2/features/mission-action/hooks/use-mission-action-rescue.tsx index 53c04af1d..c6677bf8f 100644 --- a/frontend/src/v2/features/mission-action/hooks/use-mission-action-rescue.tsx +++ b/frontend/src/v2/features/mission-action/hooks/use-mission-action-rescue.tsx @@ -1,6 +1,7 @@ import { FormikErrors } from 'formik' import { array, boolean, date, number, object } from 'yup' import { useAbstractFormik } from '../../common/hooks/use-abstract-formik-form' +import { useCoordinate } from '../../common/hooks/use-coordinate' import { useDate } from '../../common/hooks/use-date' import { AbstractFormikSubFormHook } from '../../common/types/abstract-formik-hook' import { MissionActionOutput } from '../../common/types/mission-action-output' @@ -13,6 +14,7 @@ export function useMissionActionRescue( onChange: (newAction: MissionActionOutput) => Promise, isMissionFinished?: boolean ): AbstractFormikSubFormHook { + const { getCoords } = useCoordinate() const value = action?.data as MissionNavActionDataOutput const { preprocessDateForPicker, postprocessDateFromPicker } = useDate() @@ -25,7 +27,7 @@ export function useMissionActionRescue( rescueType, dates: [startDate, endDate], isMissionFinished: !!isMissionFinished, - geoCoords: [data.latitude ?? 0, data.longitude ?? 0] + geoCoords: getCoords(data.latitude, data.longitude) } }