Skip to content

Commit 126bd84

Browse files
authored
Merge pull request #440 from MTES-MCT/feature/436-front-apply-mission-action-v2-to-front-ulam--pam
Feature/436 front apply mission action v2 to front ulam pam
2 parents 69546cd + d1b6e87 commit 126bd84

File tree

121 files changed

+1856
-1057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1856
-1057
lines changed

backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/BaseMissionEnvActionDataOutput.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2
33
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTargetTypeEnum
44
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VehicleTypeEnum
55
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType
6+
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel
67
import org.locationtech.jts.geom.Geometry
78

89
interface BaseMissionEnvActionDataOutput {
@@ -20,7 +21,7 @@ interface BaseMissionEnvActionDataOutput {
2021
val actionNumberOfControls: Int?
2122
val actionTargetType: ActionTargetTypeEnum?
2223
val vehicleType: VehicleTypeEnum?
23-
val infractions: List<InfractionEnvDataByOutput>?
24+
val infractions: List<InfractionsByVessel>?
2425
val coverMissionZone: Boolean?
2526
val formattedControlPlans: Any?
2627
val availableControlTypesForInfraction: List<ControlType>?

backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/InfractionEnvDataOutput.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2
22

33
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.*
44
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType
5+
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.Infraction
56
import java.util.*
67

78
class InfractionEnvDataByOutput(
8-
key: String,
9-
data: List<InfractionEnvDataOutput>
9+
val vesselIdentifier: String? = null,
10+
val vesselType: VesselTypeEnum? = null,
11+
val controlTypesWithInfraction: List<ControlType>? = null,
12+
val targetAddedByUnit: Boolean? = null,
13+
val identityControlledPerson: String? = null,
14+
val infractions: List<Infraction>
1015
)
1116

1217
class InfractionEnvTargetOutput(

backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionEnvActionDataOutput.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2
33
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTargetTypeEnum
44
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VehicleTypeEnum
55
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.*
6+
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel
67
import org.locationtech.jts.geom.Geometry
78
import java.time.Instant
89

@@ -25,7 +26,7 @@ class MissionEnvActionDataOutput(
2526
override val actionNumberOfControls: Int? = null,
2627
override val actionTargetType: ActionTargetTypeEnum? = null,
2728
override val vehicleType: VehicleTypeEnum? = null,
28-
override val infractions: List<InfractionEnvDataByOutput>? = listOf(),
29+
override val infractions: List<InfractionsByVessel>? = listOf(),
2930
override val coverMissionZone: Boolean? = null,
3031
override val controlSecurity: ControlSecurityEntity? = null,
3132
override val controlGensDeMer: ControlGensDeMerEntity? = null,

backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionEnvActionOutput.kt

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType
77
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType
88
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionActionEntity
99
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity
10+
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.Infraction
11+
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel
1012

1113
class MissionEnvActionOutput(
1214
override val id: String,
@@ -72,13 +74,21 @@ class MissionEnvActionOutput(
7274
)
7375
}
7476

75-
private fun getInfractionGroupBy(action: MissionEnvActionEntity): List<InfractionEnvDataByOutput> {
76-
val infractions = action.envInfractions?.map { InfractionEnvDataOutput.fromInfractionEnvEntity(it) }?: listOf()
77-
val infractions1 = action.navInfractions?.map{ InfractionEnvDataOutput.fromInfractionNavEntity(it)}?: listOf()
77+
private fun getInfractionGroupBy(action: MissionEnvActionEntity): List<InfractionsByVessel> {
78+
val envInfractions = action.envInfractions?.map { Infraction.fromEnvInfractionEntity(it) }?: listOf()
79+
val navInfractions = action.navInfractions?.map{ Infraction.fromInfractionEntity(it)}?: listOf()
7880

79-
return (infractions+ infractions1)
81+
return (envInfractions+ navInfractions)
82+
.filter { it.target?.vesselIdentifier == null && it.target?.identityControlledPerson == null}
8083
.groupBy { it.target?.vesselIdentifier ?: it.target?.identityControlledPerson }
81-
.map { (key, values) -> InfractionEnvDataByOutput(key = key?:"", data = values)}
84+
.map { (vesselIdentifier, infractions) ->
85+
InfractionsByVessel(
86+
vesselIdentifier = vesselIdentifier,
87+
vesselType = infractions.firstOrNull()?.target?.vesselType,
88+
infractions = infractions,
89+
identityControlledPerson = infractions.firstOrNull()?.target?.identityControlledPerson
90+
)
91+
}
8292
}
8393
}
8494
}

backend/src/main/resources/graphql/controls.graphqls

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type ControlNavigation {
3636
unitHasConfirmed: Boolean
3737
observations: String
3838
infractions: [Infraction]
39+
hasBeenDone: Boolean
3940
}
4041

4142
type ControlSecurity {
@@ -45,6 +46,7 @@ type ControlSecurity {
4546
unitHasConfirmed: Boolean
4647
observations: String
4748
infractions: [Infraction]
49+
hasBeenDone: Boolean
4850
}
4951

5052
type ControlAdministrative {
@@ -57,6 +59,7 @@ type ControlAdministrative {
5759
compliantSecurityDocuments: ControlResult
5860
observations: String
5961
infractions: [Infraction]
62+
hasBeenDone: Boolean
6063
}
6164

6265
type ControlGensDeMer {
@@ -69,6 +72,7 @@ type ControlGensDeMer {
6972
knowledgeOfFrenchLawAndLanguage: ControlResult
7073
observations: String
7174
infractions: [Infraction]
75+
hasBeenDone: Boolean
7276
}
7377

7478
input ControlNavigationInput {

backend/src/main/resources/graphql/mission-action.graphqls

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type MissionEnvActionDataOutput {
5050
vehicleType: VehicleTypeEnum
5151
coverMissionZone: Boolean
5252
controlsToComplete: [ControlType]
53-
infractions:[InfractionEnvDataByOutput]
53+
infractions:[InfractionByTarget]
5454
availableControlTypesForInfraction: [ControlType]
5555
}
5656

frontend/src/features/common/components/elements/dates/date-picker.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ const DatePicker: FC<DatePickerProps> = ({ allowedRange, ...props }: DatePickerP
3434
const handleChange = (date?: Date) => {
3535
const correctedDate = date ? postprocessDateFromPicker(date) : undefined
3636
const validation = validate(allowedRange, date)
37-
38-
if (validation?.ok && props.onChange) {
39-
props.onChange(correctedDate)
37+
if (validation?.ok) {
4038
setError(undefined)
4139
} else {
4240
setError(validation?.message)
4341
}
42+
if (props.onChange) {
43+
props.onChange(correctedDate)
44+
}
4445
}
4546

4647
return <MonitorUIDatePicker {...props} defaultValue={value} onChange={handleChange} error={error || props.error} />

frontend/src/features/common/components/elements/dates/daterange-picker.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,10 @@ const DateRangePicker: FC<DateRangePickerProps> = ({
5151
}, [selectedRange, allowedRange])
5252

5353
const handleChange = (date?: Date, field: 'startDate' | 'endDate') => {
54-
if (date) {
55-
field === 'startDate' ? setStartDate(date) : setEndDate(date)
56-
const correctedRange = [
57-
field === 'startDate' ? date : startDate,
58-
field === 'endDate' ? date : endDate
59-
] as DateRange
54+
field === 'startDate' ? setStartDate(date) : setEndDate(date)
55+
const correctedRange = [field === 'startDate' ? date : startDate, field === 'endDate' ? date : endDate] as DateRange
6056

61-
onChange(correctedRange)
62-
}
57+
onChange(correctedRange)
6358
}
6459

6560
return (

frontend/src/features/common/types/control-types.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ export enum ControlType {
2222

2323
type ControlModel = {
2424
id: string
25-
amountOfControls: number
26-
unitShouldConfirm?: boolean
2725
unitHasConfirmed?: boolean
26+
unitShouldConfirm?: boolean
27+
hasBeenDone?: boolean
28+
amountOfControls: number
2829
observations?: string
2930
infractions?: Infraction[]
3031
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Accent, Button, Icon, Size, THEME } from '@mtes-mct/monitor-ui'
2+
import { isNil } from 'lodash'
3+
import { useEffect, useState } from 'react'
4+
import { Stack } from 'rsuite'
5+
6+
const activeStyle = {
7+
color: 'white',
8+
borderColor: THEME.color.blueGray,
9+
backgroundColor: THEME.color.blueGray
10+
}
11+
12+
const inactiveStyle = {
13+
color: THEME.color.charcoal,
14+
borderColor: THEME.color.blueGray,
15+
backgroundColor: THEME.color.blueGray25
16+
}
17+
18+
type YesNoToogleProps = {
19+
initValue?: boolean
20+
onSubmit?: (response: boolean) => void
21+
}
22+
23+
const YesNoToogle: React.FC<YesNoToogleProps> = ({ initValue, onSubmit }) => {
24+
const [value, setValue] = useState<boolean>()
25+
26+
const handleResponse = (response: boolean) => {
27+
setValue(response)
28+
if (onSubmit) onSubmit(response)
29+
}
30+
31+
useEffect(() => {
32+
if (isNil(value)) return
33+
setValue(initValue)
34+
}, [initValue])
35+
36+
return (
37+
<Stack direction={'row'}>
38+
<Button
39+
Icon={Icon.Confirm}
40+
size={Size.NORMAL}
41+
accent={Accent.PRIMARY}
42+
onClick={() => handleResponse(true)}
43+
style={value === true ? activeStyle : inactiveStyle}
44+
>
45+
Oui
46+
</Button>
47+
<Button
48+
Icon={Icon.Reject}
49+
size={Size.NORMAL}
50+
accent={Accent.PRIMARY}
51+
onClick={() => handleResponse(false)}
52+
style={{ borderLeft: 'none', ...(value === false ? activeStyle : inactiveStyle) }}
53+
>
54+
Non
55+
</Button>
56+
</Stack>
57+
)
58+
}
59+
60+
export default YesNoToogle

frontend/src/v2/features/common/hooks/use-abstract-formik-form.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function useAbstractFormik<T, M>(
4545
) => {
4646
const valueToSubmit = beforeSubmit(value, errors)
4747
setInitValue(value)
48-
if (onSubmit) await onSubmit(valueToSubmit)
48+
if (onSubmit && valueToSubmit) await onSubmit(valueToSubmit)
4949
}
5050

5151
return {

0 commit comments

Comments
 (0)