Skip to content

Commit

Permalink
Fix ts types
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Dec 11, 2023
1 parent 47408d9 commit d4bfec7
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 62 deletions.
60 changes: 23 additions & 37 deletions frontend/src/domain/entities/mission/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import { OPENLAYERS_PROJECTION, WSG84_PROJECTION } from '@mtes-mct/monitor-ui'
import { random } from 'lodash'
import { Feature } from 'ol'
import { GeoJSON } from 'ol/format'
import {OPENLAYERS_PROJECTION, WSG84_PROJECTION} from '@mtes-mct/monitor-ui'

Check failure on line 1 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Replace `OPENLAYERS_PROJECTION,·WSG84_PROJECTION` with `·OPENLAYERS_PROJECTION,·WSG84_PROJECTION·`
import {random} from 'lodash'

Check failure on line 2 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Replace `random` with `·random·`
import {Feature} from 'ol'

Check failure on line 3 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Replace `Feature` with `·Feature·`
import {GeoJSON} from 'ol/format'

Check failure on line 4 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Replace `GeoJSON` with `·GeoJSON·`
import Point from 'ol/geom/Point'
import { transform } from 'ol/proj'

import { Mission } from './types'
import { getMissionStatus } from './utils'
import { getMissionColor } from '../../../features/map/layers/Mission/MissionLayer/styles'
import { getMissionActionInfractionsFromMissionActionFormValues } from '../../../features/SideWindow/MissionForm/ActionList/utils'
import { booleanToInt, getDate, getDateTime } from '../../../utils'
import { MissionAction } from '../../types/missionAction'
import { getNumberOfInfractions, getNumberOfInfractionsWithRecord } from '../controls'
import { MonitorFishLayer } from '../layers/types'
import { OpenLayersGeometryType } from '../map/constants'

import type { MissionWithActions } from './types'
import type { MissionActionFormValues, MissionMainFormValues } from '../../../features/SideWindow/MissionForm/types'
import type { MultiPolygon } from 'ol/geom'

import MissionStatus = Mission.MissionStatus
import MissionActionType = MissionAction.MissionActionType
import MissionType = Mission.MissionType
import MissionSource = Mission.MissionSource
import {transform} from 'ol/proj'

Check failure on line 6 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Replace `transform` with `·transform·`

import type {MissionWithActions} from './types'

Check failure on line 8 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

There should be at least one empty line between import groups

Check failure on line 8 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

`./types` type import should occur after import of `../map/constants`

Check failure on line 8 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Replace `MissionWithActions` with `·MissionWithActions·`
import {Mission} from './types'

Check failure on line 9 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Replace `Mission` with `·Mission·`
import {getMissionStatus} from './utils'

Check failure on line 10 in frontend/src/domain/entities/mission/index.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Replace `getMissionStatus` with `·getMissionStatus·`
import {getMissionColor} from '../../../features/map/layers/Mission/MissionLayer/styles'
import {getMissionActionInfractionsFromMissionActionFormValues} from '../../../features/SideWindow/MissionForm/ActionList/utils'
import {booleanToInt, getDate, getDateTime} from '../../../utils'
import {MissionAction} from '../../types/missionAction'
import {getNumberOfInfractions, getNumberOfInfractionsWithRecord} from '../controls'
import {MonitorFishLayer} from '../layers/types'
import {OpenLayersGeometryType} from '../map/constants'
import type {MissionMainFormValues} from '../../../features/SideWindow/MissionForm/types'
import type {MultiPolygon} from 'ol/geom'
import MissionStatus = Mission.MissionStatus;
import MissionActionType = MissionAction.MissionActionType;
import MissionType = Mission.MissionType;
import MissionSource = Mission.MissionSource;

export function getMissionFeaturePointId(id: number) {
return `${MonitorFishLayer.MISSION_PIN_POINT}:${id}`
Expand Down Expand Up @@ -80,10 +78,6 @@ export type MissionMainFormValuesWithId = MissionMainFormValues & {
id: number
}

export type MissionActionFormValuesWithMissionId = MissionActionFormValues & {
missionId: number
}

export const getMissionFeatureZone = (mission: Mission.Mission | MissionMainFormValuesWithId): Feature => {
const geoJSON = new GeoJSON()
const geometry = geoJSON.readGeometry(mission.geom, {
Expand All @@ -106,16 +100,8 @@ export const getMissionFeatureZone = (mission: Mission.Mission | MissionMainForm
return feature
}

export const getMissionActionFeatures = (
mainFormValues: MissionMainFormValuesWithId,
actionsFormValues: MissionActionFormValues[]
): Feature[] =>
actionsFormValues
.map(action => getMissionActionFeature({ ...action, missionId: mainFormValues.id }))
.filter((action): action is Feature => !!action)

export const getMissionActionFeature = (
action: MissionAction.MissionAction | MissionActionFormValuesWithMissionId
action: MissionAction.MissionAction
): Feature | undefined => {
if (!action.longitude || !action.latitude) {
return undefined
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/domain/types/missionAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export namespace MissionAction {
id: number
internalReferenceNumber: string | undefined
ircs: string | undefined
isAdministrativeControl?: boolean
isComplianceWithWaterRegulationsControl?: boolean
isAdministrativeControl: boolean | undefined
isComplianceWithWaterRegulationsControl: boolean | undefined
isFromPoseidon: boolean | undefined
isSafetyEquipmentAndStandardsComplianceControl?: boolean
isSeafarersControl?: boolean
isSafetyEquipmentAndStandardsComplianceControl: boolean | undefined
isSeafarersControl: boolean | undefined
latitude: number | undefined
licencesAndLogbookObservations: string | undefined
licencesMatchActivity: ControlCheck | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { GeoJSON as GeoJSONType } from '../../types/GeoJSON'
import type { Port } from '../../types/port'

export const getLastControlCircleGeometry =
(ports: Port.Port[], actionFormValues: MissionActionFormValues) => (): GeoJSONType.Geometry | undefined => {
(ports: Port.Port[], actionFormValues: MissionActionFormValues | MissionAction.MissionAction) => (): GeoJSONType.Geometry | undefined => {
if (!isLandControl(actionFormValues) && !isAirOrSeaControl(actionFormValues)) {
return undefined
}
Expand All @@ -34,7 +34,7 @@ export const getLastControlCircleGeometry =
* Get latitude and longitude from controls
* @return - the [longitude, latitude] coordinates array
*/
function getCoordinatesOfControl(ports: Port.Port[], action: MissionActionFormValues): [number, number] | undefined {
function getCoordinatesOfControl(ports: Port.Port[], action: MissionActionFormValues | MissionAction.MissionAction): [number, number] | undefined {
if (
action.actionType === MissionAction.MissionActionType.AIR_CONTROL ||
action.actionType === MissionAction.MissionActionType.SEA_CONTROL
Expand All @@ -51,11 +51,11 @@ function getCoordinatesOfControl(ports: Port.Port[], action: MissionActionFormVa
return undefined
}

export function isLandControl(action: MissionActionFormValues) {
export function isLandControl(action: MissionActionFormValues | MissionAction.MissionAction) {
return action.actionType === MissionAction.MissionActionType.LAND_CONTROL && action.portLocode
}

export function isAirOrSeaControl(action: MissionActionFormValues) {
export function isAirOrSeaControl(action: MissionActionFormValues | MissionAction.MissionAction) {
return (
(action.actionType === MissionAction.MissionActionType.AIR_CONTROL ||
action.actionType === MissionAction.MissionActionType.SEA_CONTROL) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const DateLabel = styled.div`
`

const InnerWrapper = styled.div<{
$isOpen: boolean
$isOpen: boolean | undefined
$isSelected: boolean
$type: MissionAction.MissionActionType
}>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function getActionTitle(itemTitle: string, details: string | undefined, p
* - ⚠️ When `withPendingInfractions` is true, returned infractions will include infractions without `natinf`.
*/
export function getMissionActionInfractionsFromMissionActionFormValues(
missionActionFormValues: MissionActionFormValues,
missionActionFormValues: MissionAction.MissionAction | MissionActionFormValues,
withPendingInfractions: boolean = false
): Array<MissionAction.Infraction> {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const updateSpeciesOnboard =

const updateMissionLocation =
(dispatch, ports: Port.Port[] | undefined) =>
async (isGeometryComputedFromControls: boolean | undefined, missionAction: MissionActionFormValues | undefined) => {
async (isGeometryComputedFromControls: boolean | undefined, missionAction: MissionActionFormValues | MissionAction.MissionAction | undefined) => {
if (!missionAction || !ports || !isGeometryComputedFromControls) {
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { sortBy } from 'lodash'
import {sortBy} from 'lodash'

import { missionActionApi } from '../../../../api/missionAction'
import { useGetPortsQuery } from '../../../../api/port'
import { MissionAction } from '../../../../domain/types/missionAction'
import { isAirOrSeaControl, isLandControl } from '../../../../domain/use_cases/mission/getLastControlCircleGeometry'
import { useMainAppDispatch } from '../../../../hooks/useMainAppDispatch'
import { useMainAppSelector } from '../../../../hooks/useMainAppSelector'
import { formikUsecase } from '../formikUsecases'
import {missionActionApi} from '../../../../api/missionAction'
import {useGetPortsQuery} from '../../../../api/port'
import {MissionAction} from '../../../../domain/types/missionAction'
import {isAirOrSeaControl, isLandControl} from '../../../../domain/use_cases/mission/getLastControlCircleGeometry'
import {useMainAppDispatch} from '../../../../hooks/useMainAppDispatch'
import {useMainAppSelector} from '../../../../hooks/useMainAppSelector'
import {formikUsecase} from '../formikUsecases'

import type { MissionActionFormValues, MissionMainFormValues } from '../types'
import type {MissionMainFormValues} from '../types'

export function useGetMainFormFormikUsecases() {
const dispatch = useMainAppDispatch()
Expand Down Expand Up @@ -40,7 +40,7 @@ export function useGetMainFormFormikUsecases() {
return
}

const sortedValidControlsByDateTimeDesc: MissionActionFormValues[] = sortBy(
const sortedValidControlsByDateTimeDesc = sortBy(
validControls,
({ actionDatetimeUtc }) => actionDatetimeUtc
).reverse()
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/features/SideWindow/MissionForm/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { MissionActionFormValues, MissionMainFormValues } from './types'
import type { LegacyControlUnit } from '../../../domain/types/legacyControlUnit'

import MissionActionType = MissionAction.MissionActionType
import {validateMissionForms} from "./utils/validateMissionForms";

export function areMissionFormsValuesValid(
mainFormValues: MissionMainFormValues | undefined,
Expand Down Expand Up @@ -118,9 +119,15 @@ export function getMissionFormInitialValues(
throw new FrontendError('`missionType` is undefined.')
}

const [, { nextActionsFormValues, nextMainFormValues }] = validateMissionForms(
mission,
missionActions,
false
)

return {
initialActionsFormValues: missionActions,
initialMainFormValues: mission
initialActionsFormValues: nextActionsFormValues,
initialMainFormValues: nextMainFormValues
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { MainFormLiveSchema } from '../MainForm/schemas'
import { areMissionFormsValuesValid } from '../utils'

import type { MissionActionFormValues, MissionMainFormValues } from '../types'
import {Mission} from "../../../../domain/entities/mission/types";

export function validateMissionForms(
mainFormValues: MissionMainFormValues,
actionsFormValues: MissionActionFormValues[],
mainFormValues: MissionMainFormValues | Mission.Mission,
actionsFormValues: MissionActionFormValues[] | MissionAction.MissionAction[],
isClosureValidation: boolean
): [
boolean,
Expand Down

0 comments on commit d4bfec7

Please sign in to comment.