Skip to content

Commit

Permalink
Remove index file
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed May 21, 2024
1 parent 236aada commit 83d2604
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useGetPortsQuery } from '@api/port'
import { updateMissionGeometry } from '@features/Mission/components/MissionForm/useCases/updateMissionGeometry'
import { updateOtherControlsCheckboxes } from '@features/Mission/components/MissionForm/useCases/updateOtherControlsCheckboxes'
import { useGetMissionQuery } from '@features/Mission/monitorfishMissionApi'
import { isAirOrSeaControl, isLandControl } from '@features/Mission/useCases/getLastControlCircleGeometry'
import { useMainAppDispatch } from '@hooks/useMainAppDispatch'
import { useMainAppSelector } from '@hooks/useMainAppSelector'
import { skipToken } from '@reduxjs/toolkit/query'
import { sortBy } from 'lodash'

import { formUsecase } from '../useCases'

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

export function useGetMainFormFormikUsecases() {
Expand All @@ -22,7 +22,7 @@ export function useGetMainFormFormikUsecases() {
* When updating a control unit, we must reset the "Other controls" field checkboxes
*/
updateMissionActionOtherControlsCheckboxes: (mission: MissionMainFormValues, previousIsControlUnitPAM: boolean) =>
formUsecase.updateOtherControlsCheckboxes(dispatch)(mission, previousIsControlUnitPAM),
updateOtherControlsCheckboxes(dispatch)(mission, previousIsControlUnitPAM),

/**
* When updating the mission location from the mission, we use the `RTK-Query` cache object to access the `missionAction` form.
Expand Down Expand Up @@ -53,7 +53,7 @@ export function useGetMainFormFormikUsecases() {
return false
}

await formUsecase.updateMissionLocation(
await updateMissionGeometry(
dispatch,
getPortsApiQuery.data,
getMissionApiQuery.data?.envActions ?? [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useGetPortsQuery } from '@api/port'
import { useGetFleetSegmentsQuery } from '@features/FleetSegment/apis'
import { initMissionGeometry } from '@features/Mission/components/MissionForm/useCases/initMissionGeometry'
import { updateActionFAOAreas } from '@features/Mission/components/MissionForm/useCases/updateActionFAOAreas'
import { updateActionGearsOnboard } from '@features/Mission/components/MissionForm/useCases/updateActionGearsOnboard'
import { updateActionSegments } from '@features/Mission/components/MissionForm/useCases/updateActionSegments'
import { updateActionSpeciesOnboard } from '@features/Mission/components/MissionForm/useCases/updateActionSpeciesOnboard'
import { updateMissionGeometry } from '@features/Mission/components/MissionForm/useCases/updateMissionGeometry'
import { MissionAction } from '@features/Mission/missionAction.types'
import { useGetMissionQuery } from '@features/Mission/monitorfishMissionApi'
import { useMainAppDispatch } from '@hooks/useMainAppDispatch'
Expand All @@ -9,7 +15,6 @@ import { useFormikContext } from 'formik'
import { useMemo } from 'react'

import { getFleetSegmentsAsOption } from '../ActionForm/shared/utils'
import { formUsecase } from '../useCases'

import type { MissionActionFormValues } from '../types'
import type { Option } from '@mtes-mct/monitor-ui'
Expand All @@ -32,15 +37,15 @@ export function useGetMissionActionFormikUsecases() {
)

const updateSegments = (missionActionValues: MissionActionFormValues) =>
formUsecase.updateSegments(dispatch, setMissionActionFieldValue, fleetSegmentsAsOptions)(missionActionValues)
updateActionSegments(dispatch, setMissionActionFieldValue, fleetSegmentsAsOptions)(missionActionValues)

/**
* Update FAO Areas and segments from the control coordinates or port input
*/
async function updateFAOAreasAndSegments(missionActionValues: MissionActionFormValues) {
const faoAreas = await formUsecase.updateFAOAreas(dispatch, setMissionActionFieldValue)(missionActionValues)
const faoAreas = await updateActionFAOAreas(dispatch, setMissionActionFieldValue)(missionActionValues)

await formUsecase.updateSegments(
await updateActionSegments(
dispatch,
setMissionActionFieldValue,
fleetSegmentsAsOptions
Expand All @@ -62,20 +67,17 @@ export function useGetMissionActionFormikUsecases() {
return
}

const gearOnboard = await formUsecase.updateGearsOnboard(
const gearOnboard = await updateActionGearsOnboard(
dispatch,
setMissionActionFieldValue,
gearsByCode
)(missionActionValues)

const speciesOnboard = await formUsecase.updateSpeciesOnboard(
dispatch,
setMissionActionFieldValue
)(missionActionValues)
const speciesOnboard = await updateActionSpeciesOnboard(dispatch, setMissionActionFieldValue)(missionActionValues)

const faoAreas = await formUsecase.updateFAOAreas(dispatch, setMissionActionFieldValue)(missionActionValues)
const faoAreas = await updateActionFAOAreas(dispatch, setMissionActionFieldValue)(missionActionValues)

await formUsecase.updateSegments(
await updateActionSegments(
dispatch,
setMissionActionFieldValue,
fleetSegmentsAsOptions
Expand All @@ -92,7 +94,7 @@ export function useGetMissionActionFormikUsecases() {
* The mission location is equal to the current action geometry modified.
*/
const updateMissionLocation = (missionActionValues: MissionActionFormValues) =>
formUsecase.updateMissionLocation(
updateMissionGeometry(
dispatch,
getPortsApiQuery.data,
getMissionApiQuery.data?.envActions ?? [],
Expand All @@ -102,8 +104,7 @@ export function useGetMissionActionFormikUsecases() {
/**
* When updating the mission location from an action, we use the `RTK-Query` cache object to access the `mission` form.
*/
const initMissionLocation = () =>
formUsecase.initMissionLocation(dispatch)(draft?.mainFormValues.isGeometryComputedFromControls)
const initMissionLocation = () => initMissionGeometry(dispatch)(draft?.mainFormValues.isGeometryComputedFromControls)

return {
initMissionLocation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dummyAction } from '@features/Mission/components/MissionForm/useCases/__tests__/__mocks__/dummyAction'
import { updateMissionLocation } from '@features/Mission/components/MissionForm/useCases/updateMissionLocation'
import { updateMissionGeometry } from '@features/Mission/components/MissionForm/useCases/updateMissionGeometry'
import { EnvMissionAction } from '@features/Mission/envMissionAction.types'
import { expect, jest } from '@jest/globals'
import { customDayjs } from '@mtes-mct/monitor-ui'
Expand All @@ -9,7 +9,7 @@ const mockDispatch = jest.fn()
describe('features/Mission/components/MissionForm/useCases.updateMissionLocation()', () => {
it('Should update the mission location When there is no other actions', () => {
// When
updateMissionLocation(mockDispatch, [], [], [])(true, dummyAction)
updateMissionGeometry(mockDispatch, [], [], [])(true, dummyAction)

// Then
expect(mockDispatch).toHaveBeenCalled()
Expand All @@ -20,7 +20,7 @@ describe('features/Mission/components/MissionForm/useCases.updateMissionLocation
const olderAction = { ...dummyAction, actionDatetimeUtc: '2018-12-08T08:27:00Z' }

// When
updateMissionLocation(mockDispatch, [], [], [olderAction])(true, dummyAction)
updateMissionGeometry(mockDispatch, [], [], [olderAction])(true, dummyAction)

// Then
expect(mockDispatch).toHaveBeenCalled()
Expand All @@ -31,7 +31,7 @@ describe('features/Mission/components/MissionForm/useCases.updateMissionLocation
const newerAction = { ...dummyAction, actionDatetimeUtc: customDayjs().toISOString() }

// When
updateMissionLocation(mockDispatch, [], [], [newerAction])(true, dummyAction)
updateMissionGeometry(mockDispatch, [], [], [newerAction])(true, dummyAction)

// Then
expect(mockDispatch).toHaveBeenCalledTimes(0)
Expand All @@ -47,7 +47,7 @@ describe('features/Mission/components/MissionForm/useCases.updateMissionLocation
}

// When
updateMissionLocation(mockDispatch, [], [newerEnvAction], [])(true, dummyAction)
updateMissionGeometry(mockDispatch, [], [newerEnvAction], [])(true, dummyAction)

// Then
expect(mockDispatch).toHaveBeenCalledTimes(0)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { convertToGeoJSONGeometryObject } from '../../../../../domain/entities/l

import type { GeoJSON } from '../../../../../domain/types/GeoJSON'

export const initMissionLocation = dispatch => async (isGeometryComputedFromControls: boolean | undefined) => {
export const initMissionGeometry = dispatch => async (isGeometryComputedFromControls: boolean | undefined) => {
if (!isGeometryComputedFromControls) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { faoAreasApi } from '@api/faoAreas'

import type { MissionActionFormValues } from '@features/Mission/components/MissionForm/types'

export const updateFAOAreas =
export const updateActionFAOAreas =
(dispatch, setFieldValue: (field: string, value: any) => void) =>
async (missionAction: MissionActionFormValues): Promise<string[]> => {
const { data: computedVesselFaoAreas } = await dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { MainRootState } from '@store'
import type { AnyAction } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'

export const updateGearsOnboard =
export const updateActionGearsOnboard =
(
dispatch: ThunkDispatch<MainRootState, undefined, AnyAction>,
setFieldValue: (field: string, value: any) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getFleetSegments } from '../../../../../domain/use_cases/vessel/getFlee
import type { MissionActionFormValues } from '@features/Mission/components/MissionForm/types'
import type { Option } from '@mtes-mct/monitor-ui'

export const updateSegments =
export const updateActionSegments =
(
dispatch,
setFieldValue: (field: string, value: any) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { vesselApi } from '@features/Vessel/apis'
import type { RiskFactor } from '../../../../../domain/entities/vessel/riskFactor/types'
import type { MissionActionFormValues } from '@features/Mission/components/MissionForm/types'

export const updateSpeciesOnboard =
export const updateActionSpeciesOnboard =
(dispatch, setFieldValue: (field: string, value: any) => void) =>
async (missionAction: MissionActionFormValues): Promise<MissionAction.SpeciesControl[]> => {
if (!missionAction.internalReferenceNumber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { first, orderBy } from 'lodash'
import type { Port } from '../../../../../domain/types/port'
import type { MissionActionFormValues } from '@features/Mission/components/MissionForm/types'

export const updateMissionLocation =
export const updateMissionGeometry =
(
dispatch,
ports: Port.Port[] | undefined,
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/features/Mission/useCases/deleteMissionAction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { missionActionApi } from '@api/missionAction'
import { portApi } from '@api/port'
import { missionFormActions } from '@features/Mission/components/MissionForm/slice'
import { formUsecase } from '@features/Mission/components/MissionForm/useCases'
import { initMissionGeometry } from '@features/Mission/components/MissionForm/useCases/initMissionGeometry'
import { updateMissionGeometry } from '@features/Mission/components/MissionForm/useCases/updateMissionGeometry'
import { validateMissionForms } from '@features/Mission/components/MissionForm/utils/validateMissionForms'
import { EnvMissionAction } from '@features/Mission/envMissionAction.types'
import { monitorfishMissionApi } from '@features/Mission/monitorfishMissionApi'
Expand Down Expand Up @@ -51,13 +52,13 @@ export const deleteMissionAction =
)

if (nextControlActionsWithGeometry.length === 0) {
await formUsecase.initMissionLocation(dispatch)(isGeometryComputedFromControls)
await initMissionGeometry(dispatch)(isGeometryComputedFromControls)
} else {
const { data: ports } = await dispatch(portApi.endpoints.getPorts.initiate())
const missionId = getState().missionForm.draft?.mainFormValues?.id
const { actions, envActions } = await getActions(missionId)
const { actions, envActions } = await getMissionActions(missionId)

await formUsecase.updateMissionLocation(
await updateMissionGeometry(
dispatch,
ports,
envActions,
Expand All @@ -78,7 +79,7 @@ export const deleteMissionAction =
}
}

async function getActions(missionId: number | undefined): Promise<{
async function getMissionActions(missionId: number | undefined): Promise<{
actions: MissionAction.MissionAction[]
envActions: EnvMissionAction.MissionAction[]
}> {
Expand Down

0 comments on commit 83d2604

Please sign in to comment.