Skip to content

Commit

Permalink
Add quantity when species are seized
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Aug 30, 2024
1 parent e5adbe6 commit efc272e
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ data class MissionAction(
val isDeleted: Boolean,
val hasSomeGearsSeized: Boolean,
val hasSomeSpeciesSeized: Boolean,
val speciesQuantitySeized: Int? = null,
val completedBy: String? = null,
val completion: Completion,
val isAdministrativeControl: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data class AddMissionActionDataInput(
var vesselTargeted: ControlCheck? = null,
var hasSomeGearsSeized: Boolean = false,
var hasSomeSpeciesSeized: Boolean = false,
var speciesQuantitySeized: Int? = null,
var completedBy: String? = null,
var completion: Completion,
val isFromPoseidon: Boolean? = null,
Expand Down Expand Up @@ -102,6 +103,7 @@ data class AddMissionActionDataInput(
isDeleted = false,
hasSomeGearsSeized = hasSomeGearsSeized,
hasSomeSpeciesSeized = hasSomeSpeciesSeized,
speciesQuantitySeized = speciesQuantitySeized,
completedBy = completedBy,
completion = completion,
isFromPoseidon = isFromPoseidon ?: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ data class MissionActionDataOutput(
val vesselTargeted: ControlCheck? = null,
val hasSomeGearsSeized: Boolean,
val hasSomeSpeciesSeized: Boolean,
val speciesQuantitySeized: Int? = null,
val completedBy: String? = null,
val completion: Completion,
val isFromPoseidon: Boolean,
Expand Down Expand Up @@ -112,6 +113,7 @@ data class MissionActionDataOutput(
vesselTargeted = missionAction.vesselTargeted,
hasSomeGearsSeized = missionAction.hasSomeGearsSeized,
hasSomeSpeciesSeized = missionAction.hasSomeSpeciesSeized,
speciesQuantitySeized = missionAction.speciesQuantitySeized,
completedBy = missionAction.completedBy,
completion = missionAction.completion,
isFromPoseidon = missionAction.isFromPoseidon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class MissionActionEntity(
val hasSomeGearsSeized: Boolean,
@Column(name = "has_some_species_seized")
val hasSomeSpeciesSeized: Boolean,
@Column(name = "species_quantity_seized")
val speciesQuantitySeized: Int? = null,
@Column(name = "completed_by")
val completedBy: String? = null,
@Enumerated(EnumType.STRING)
Expand Down Expand Up @@ -200,6 +202,7 @@ class MissionActionEntity(
isDeleted = missionAction.isDeleted,
hasSomeGearsSeized = missionAction.hasSomeGearsSeized,
hasSomeSpeciesSeized = missionAction.hasSomeSpeciesSeized,
speciesQuantitySeized = missionAction.speciesQuantitySeized,
completedBy = missionAction.completedBy,
completion = missionAction.completion,
isAdministrativeControl = missionAction.isAdministrativeControl,
Expand Down Expand Up @@ -278,6 +281,7 @@ class MissionActionEntity(
isDeleted = isDeleted,
hasSomeGearsSeized = hasSomeGearsSeized,
hasSomeSpeciesSeized = hasSomeSpeciesSeized,
speciesQuantitySeized = speciesQuantitySeized,
completedBy = completedBy,
completion = completion,
isFromPoseidon = isFromPoseidon,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE mission_actions
ADD COLUMN species_quantity_seized integer;
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ context('Side Window > Mission Form > Land Control', () => {
// Appréhensions
cy.fill('Appréhension d’engin(s)', true)
cy.fill('Appréhension d’espèce(s)', true)
cy.fill('Quantités saisies (kg)', 6289.5)
cy.fill('Appréhension du navire', true)

// Infractions
Expand Down Expand Up @@ -199,6 +200,7 @@ context('Side Window > Mission Form > Land Control', () => {
{ controlledWeight: null, declaredWeight: 13.46, nbFish: null, speciesCode: 'BLI', underSized: false },
{ controlledWeight: null, declaredWeight: null, nbFish: null, speciesCode: 'COD', underSized: false }
],
speciesQuantitySeized: 6289.5,
speciesSizeControlled: false,
speciesWeightControlled: true,
unitWithoutOmegaGauge: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ context('Side Window > Mission Form > Sea Control', () => {
// Appréhension et déroutement
cy.fill('Appréhension d’engin(s)', true)
cy.fill('Appréhension d’espèce(s)', true)
cy.fill('Quantités saisies (kg)', 6289.5)
cy.fill('Appréhension et déroutement du navire', true)

// Infractions
Expand Down Expand Up @@ -259,6 +260,7 @@ context('Side Window > Mission Form > Sea Control', () => {
speciesOnboard: [
{ controlledWeight: 20, declaredWeight: 10, nbFish: null, speciesCode: 'COD', underSized: true }
],
speciesQuantitySeized: 6289.5,
speciesSizeControlled: false,
speciesWeightControlled: true,
unitWithoutOmegaGauge: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DatePickerField } from '@features/Mission/components/MissionForm/ActionForm/shared/DatePickerField'
import { FormikSpeciesQuantitySeized } from '@features/Mission/components/MissionForm/ActionForm/shared/FormikSpeciesQuantitySeized'
import { UpdateMissionActionCompletionEffect } from '@features/Mission/components/MissionForm/ActionForm/shared/UpdateMissionActionCompletionEffect'
import { useIsMissionEnded } from '@features/Mission/components/MissionForm/hooks/useIsMissionEnded'
import { FormikCheckbox, FormikEffect, FormikTextarea, Icon } from '@mtes-mct/monitor-ui'
Expand Down Expand Up @@ -63,6 +64,7 @@ export function LandControlForm({ initialValues, onChange }: LandControlFormProp
<SeizureFieldsetGroup isLight legend="Appréhensions">
<FormikCheckbox label="Appréhension d’engin(s)" name="hasSomeGearsSeized" />
<FormikCheckbox label="Appréhension d’espèce(s)" name="hasSomeSpeciesSeized" />
<FormikSpeciesQuantitySeized />
<FormikCheckbox label="Appréhension du navire" name="seizureAndDiversion" />
</SeizureFieldsetGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ActionFormHeader } from '@features/Mission/components/MissionForm/ActionForm/shared/ActionFormHeader'
import { DatePickerField } from '@features/Mission/components/MissionForm/ActionForm/shared/DatePickerField'
import { FormikSpeciesQuantitySeized } from '@features/Mission/components/MissionForm/ActionForm/shared/FormikSpeciesQuantitySeized'
import { UpdateMissionActionCompletionEffect } from '@features/Mission/components/MissionForm/ActionForm/shared/UpdateMissionActionCompletionEffect'
import { useIsMissionEnded } from '@features/Mission/components/MissionForm/hooks/useIsMissionEnded'
import { FormikCheckbox, FormikEffect, FormikTextarea, Icon } from '@mtes-mct/monitor-ui'
Expand Down Expand Up @@ -63,6 +64,7 @@ export function SeaControlForm({ initialValues, onChange }: SeaControlFormProps)
<SeizureFieldsetGroup isLight legend="Appréhension et déroutement">
<FormikCheckbox label="Appréhension d’engin(s)" name="hasSomeGearsSeized" />
<FormikCheckbox label="Appréhension d’espèce(s)" name="hasSomeSpeciesSeized" />
<FormikSpeciesQuantitySeized />
<FormikCheckbox label="Appréhension et déroutement du navire" name="seizureAndDiversion" />
</SeizureFieldsetGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { HIDDEN_ERROR } from '@features/Mission/components/MissionForm/constants'
import { MissionAction } from '@features/Mission/missionAction.types'
import { customDayjs } from '@mtes-mct/monitor-ui'
import { mainStore } from '@store/index'
import { mainStore } from '@store'
import { array, boolean, number, object, string } from 'yup'

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -108,6 +108,12 @@ export const LandControlFormCompletionSchema = LandControlFormLiveSchema.concat(
speciesSizeControlled: boolean().required(HIDDEN_ERROR),
separateStowageOfPreservedSpecies: string().required(HIDDEN_ERROR),

// Quantités saisies
speciesQuantitySeized: number().when('hasSomeSpeciesSeized', {
is: (hasSomeSpeciesSeized?: boolean) => hasSomeSpeciesSeized === true,
then: schema => schema.required(HIDDEN_ERROR)
}),

// Engins à bord
gearOnboard: array().of(GearOnboardSchema).required(HIDDEN_ERROR).min(1, HIDDEN_ERROR),

Expand Down Expand Up @@ -146,6 +152,12 @@ export const SeaControlFormCompletionSchema = SeaControlFormLiveSchema.concat(
// Engins à bord
gearOnboard: array().of(GearOnboardSchema).required(HIDDEN_ERROR).min(1, HIDDEN_ERROR),

// Quantités saisies
speciesQuantitySeized: number().when('hasSomeSpeciesSeized', {
is: (hasSomeSpeciesSeized?: boolean) => hasSomeSpeciesSeized === true,
then: schema => schema.required(HIDDEN_ERROR)
}),

// Qualité du contrôle
vesselTargeted: string().required(HIDDEN_ERROR),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FormikNumberInput } from '@mtes-mct/monitor-ui'
import { useFormikContext } from 'formik'
import styled from 'styled-components'

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

export function FormikSpeciesQuantitySeized() {
const { values } = useFormikContext<MissionActionFormValues>()

return (
!!values.hasSomeSpeciesSeized && (
<StyledFormikNumberInput isRequired label="Quantités saisies (kg)" name="speciesQuantitySeized" />
)
)
}

const StyledFormikNumberInput = styled(FormikNumberInput)`
margin-top: 12px;
margin-left: 24px;
width: 160px;
`
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe('features/Mission/components/MissionForm/utils.getMissionActionsDataFro
underSized: false
}
],
speciesQuantitySeized: undefined,
speciesSizeControlled: undefined,
speciesWeightControlled: undefined,
unitWithoutOmegaGauge: false,
Expand Down Expand Up @@ -262,6 +263,7 @@ describe('features/Mission/components/MissionForm/utils.getMissionActionsDataFro
underSized: false
}
],
speciesQuantitySeized: undefined,
speciesSizeControlled: undefined,
speciesWeightControlled: undefined,
unitWithoutOmegaGauge: false,
Expand Down Expand Up @@ -344,6 +346,7 @@ describe('features/Mission/components/MissionForm/utils.getMissionActionsDataFro
underSized: false
}
],
speciesQuantitySeized: undefined,
speciesSizeControlled: undefined,
speciesWeightControlled: undefined,
unitWithoutOmegaGauge: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const dummyAction = {
underSized: false
}
],
speciesQuantitySeized: undefined,
speciesSizeControlled: undefined,
speciesWeightControlled: undefined,
unitWithoutOmegaGauge: false,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/features/Mission/missionAction.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export namespace MissionAction {
speciesInfractions: Infraction[]
speciesObservations: string | undefined
speciesOnboard: SpeciesControl[]
speciesQuantitySeized: number | undefined
speciesSizeControlled: boolean | undefined
speciesWeightControlled: boolean | undefined
unitWithoutOmegaGauge: boolean | undefined
Expand Down

0 comments on commit efc272e

Please sign in to comment.