From 59f3d392e3a7ee8439a0d2d7748d6e93c2be8e9e Mon Sep 17 00:00:00 2001 From: aleckvincent Date: Mon, 30 Sep 2024 15:33:51 +0200 Subject: [PATCH 01/33] feat(365)- display du bouton "ajouter une infraction pour cette cible" en fonction du type de target --- .../env-infraction-summary.test.tsx | 22 +++++++++++++ .../infractions/env-infraction-summary.tsx | 33 ++++++++++--------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx index 77117c638..18607bb88 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx @@ -29,12 +29,27 @@ const infractionByTargetMock = (infractions: Infraction[]) => ({ targetAddedByUnit: false }) +const infractionByTargetCompanyMock = (infractions: Infraction[]) => ({ + vesselIdentifier: null, + vesselType: null, + infractions, + controlTypesWithInfraction: [ControlType.ADMINISTRATIVE], + targetAddedByUnit: false +}) + const props = infractionByTarget => ({ infractionByTarget, onAddInfractionForTarget: vi.fn(), onEditInfractionForTarget: vi.fn(), onDeleteInfraction: vi.fn() }) + +const propsInfractionCompany = infractionByTarget => ({ + infractionByTarget, + onAddInfractionForTarget: vi.fn(), + onEditInfractionForTarget: vi.fn(), + onDeleteInfraction: vi.fn() +}) describe('EnvInfractionSummary', () => { describe('testing rendering', () => { test('renders the component', async () => { @@ -92,4 +107,11 @@ describe('EnvInfractionSummary', () => { expect(onDeleteInfraction).toHaveBeenCalled() }) }) + + describe('rendering button "Ajouter une infraction pour cette cible"', () => { + test('should not render button "Ajouter une infraction pour cette cible" if is not a vessel', async () => { + render() + expect(screen.queryByText('infraction pour cette cible')).not.toBeInTheDocument() + }) + }) }) diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx index 30abd87eb..ffc7dac7d 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx @@ -29,21 +29,24 @@ const EnvInfractionSummary: React.FC = ({ {`${vesselTypeToHumanString(infractionByTarget?.vesselType)} - ${infractionByTarget?.vesselIdentifier}`} - - - + {infractionByTarget?.vesselType !== null && ( + + + + )} + {infractionByTarget?.infractions.map((infraction: Infraction) => ( From 9c5127e54a3cbec4fc41167b86ef726d5b896dde Mon Sep 17 00:00:00 2001 From: aleckvincent Date: Mon, 30 Sep 2024 15:43:58 +0200 Subject: [PATCH 02/33] feat(365)- une tuile par infraction --- .../infractions/env-infraction-existing-targets.tsx | 5 +---- .../elements/infractions/env-infraction-summary.tsx | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-existing-targets.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-existing-targets.tsx index c43e0227c..371f21bfc 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-existing-targets.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-existing-targets.tsx @@ -72,10 +72,7 @@ const EnvInfractionExistingTargets: React.FC =
{selectedVessel === infractionByTarget.vesselIdentifier ? ( diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx index ffc7dac7d..b9dc21ef2 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx @@ -50,7 +50,11 @@ const EnvInfractionSummary: React.FC = ({ {infractionByTarget?.infractions.map((infraction: Infraction) => ( - + From a3db448a0b9cc2cc672347121707ec7c827857b7 Mon Sep 17 00:00:00 2001 From: aleckvincent Date: Mon, 30 Sep 2024 15:46:24 +0200 Subject: [PATCH 03/33] feat(365)- remove useless props in test --- .../elements/infractions/env-infraction-summary.test.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx index 18607bb88..40cc89a6b 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx @@ -44,12 +44,6 @@ const props = infractionByTarget => ({ onDeleteInfraction: vi.fn() }) -const propsInfractionCompany = infractionByTarget => ({ - infractionByTarget, - onAddInfractionForTarget: vi.fn(), - onEditInfractionForTarget: vi.fn(), - onDeleteInfraction: vi.fn() -}) describe('EnvInfractionSummary', () => { describe('testing rendering', () => { test('renders the component', async () => { From 2ba9a8801c310313f22265e71696880bb92115e0 Mon Sep 17 00:00:00 2001 From: aleckvincent Date: Tue, 1 Oct 2024 17:00:03 +0200 Subject: [PATCH 04/33] feat(365)- check with action targetType --- .../elements/actions/action-control-env.tsx | 1 + .../env-infraction-add-new-target.tsx | 2 +- .../env-infraction-existing-targets.tsx | 6 +- .../env-infraction-summary.test.tsx | 17 ++- .../infractions/env-infraction-summary.tsx | 129 +++++++++--------- ...v-infraction-target-added-by-unit-form.tsx | 10 +- 6 files changed, 94 insertions(+), 71 deletions(-) diff --git a/frontend/src/features/pam/mission/components/elements/actions/action-control-env.tsx b/frontend/src/features/pam/mission/components/elements/actions/action-control-env.tsx index 6054f9ac4..eaf438d61 100644 --- a/frontend/src/features/pam/mission/components/elements/actions/action-control-env.tsx +++ b/frontend/src/features/pam/mission/components/elements/actions/action-control-env.tsx @@ -184,6 +184,7 @@ const ActionControlEnv: React.FC = ({ action }) => { diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-add-new-target.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-add-new-target.tsx index b3d30f09d..09481f258 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-add-new-target.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-add-new-target.tsx @@ -86,7 +86,7 @@ const EnvInfractionAddNewTarget: React.FC = ({ avai Icon={Icon.Plus} role={'add-target'} > - Ajouter une nouvelle cible avec infraction + Ajouter une infraction diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-existing-targets.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-existing-targets.tsx index 371f21bfc..dbc04c996 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-existing-targets.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-existing-targets.tsx @@ -10,15 +10,18 @@ import EnvInfractionTargetAddedByUnitForm from './env-infraction-target-added-by import Text from '../../../../../common/components/ui/text.tsx' import useDeleteInfraction from '../../../hooks/use-delete-infraction.tsx' import useAddOrUpdateInfractionEnv from '../../../hooks/use-add-update-infraction-env.tsx' +import { ActionTargetTypeEnum } from '@common/types/env-mission-types.ts' export interface EnvInfractionExistingTargetProps { availableControlTypesForInfraction?: ControlType[] infractionsByTarget?: InfractionByTarget[] + actionTargetType?: ActionTargetTypeEnum } const EnvInfractionExistingTargets: React.FC = ({ availableControlTypesForInfraction, - infractionsByTarget + infractionsByTarget, + actionTargetType }) => { const { missionId, actionId } = useParams() @@ -116,6 +119,7 @@ const EnvInfractionExistingTargets: React.FC = ) : ( ) => { setFormData(infraction as Infraction) diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx index 40cc89a6b..c7fb7ce45 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.test.tsx @@ -1,7 +1,7 @@ import { render, screen, fireEvent } from '../../../../../../test-utils.tsx' import EnvInfractionSummary from './env-infraction-summary.tsx' import { ControlType } from '@common/types/control-types.ts' -import { InfractionTypeEnum, VesselTypeEnum } from '@common/types/env-mission-types.ts' +import { ActionTargetTypeEnum, InfractionTypeEnum, VesselTypeEnum } from '@common/types/env-mission-types.ts' import { Infraction } from '@common/types/infraction-types.ts' const infractionMock = { @@ -41,7 +41,16 @@ const props = infractionByTarget => ({ infractionByTarget, onAddInfractionForTarget: vi.fn(), onEditInfractionForTarget: vi.fn(), - onDeleteInfraction: vi.fn() + onDeleteInfraction: vi.fn(), + actionTargetType: ActionTargetTypeEnum.VEHICLE +}) + +const propsCompany = infractionByTarget => ({ + infractionByTarget, + onAddInfractionForTarget: vi.fn(), + onEditInfractionForTarget: vi.fn(), + onDeleteInfraction: vi.fn(), + actionTargetType: ActionTargetTypeEnum.COMPANY }) describe('EnvInfractionSummary', () => { @@ -103,8 +112,8 @@ describe('EnvInfractionSummary', () => { }) describe('rendering button "Ajouter une infraction pour cette cible"', () => { - test('should not render button "Ajouter une infraction pour cette cible" if is not a vessel', async () => { - render() + test('should not render button "Ajouter une infraction pour cette cible" if action target type is not VEHICLE', async () => { + render() expect(screen.queryByText('infraction pour cette cible')).not.toBeInTheDocument() }) }) diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx index b9dc21ef2..81a65ee80 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-summary.tsx @@ -6,54 +6,31 @@ import { controlTitle, vesselTypeToHumanString } from '../../../utils/control-ut import { Infraction, InfractionByTarget } from '@common/types/infraction-types.ts' import InfractionTypeTag from '../../ui/infraction-type-tag.tsx' import NatinfsTag from '../../ui/natinfs-tag.tsx' +import { ActionTargetTypeEnum } from '@common/types/env-mission-types.ts' interface EnvInfractionSummaryProps { infractionByTarget?: InfractionByTarget onAddInfractionForTarget: (infraction?: Partial) => void onEditInfractionForTarget: (infraction: Infraction) => void onDeleteInfraction: (infractionId: string) => void + actionTargetType?: ActionTargetTypeEnum } const EnvInfractionSummary: React.FC = ({ infractionByTarget, onAddInfractionForTarget, onEditInfractionForTarget, - onDeleteInfraction + onDeleteInfraction, + actionTargetType }) => { return ( - - - - - {`${vesselTypeToHumanString(infractionByTarget?.vesselType)} - ${infractionByTarget?.vesselIdentifier}`} - - - {infractionByTarget?.vesselType !== null && ( - - - - )} - - - {infractionByTarget?.infractions.map((infraction: Infraction) => ( @@ -65,44 +42,70 @@ const EnvInfractionSummary: React.FC = ({ : controlTitle(infraction.controlType)} + + + + + + + {actionTargetType === ActionTargetTypeEnum.VEHICLE && ( - - - - - - - - + + + )} + + + + + + + + + + + + + + + {infraction.controlType !== null && ( + + + + onEditInfractionForTarget(infraction)} + /> + + + onDeleteInfraction(infraction.id)} + /> - {infraction.controlType !== null && ( - - - - onEditInfractionForTarget(infraction)} - /> - - - onDeleteInfraction(infraction.id)} - /> - - - - )} - + )} + + ))} ) diff --git a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-target-added-by-unit-form.tsx b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-target-added-by-unit-form.tsx index b8431fe64..1240bf004 100644 --- a/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-target-added-by-unit-form.tsx +++ b/frontend/src/features/pam/mission/components/elements/infractions/env-infraction-target-added-by-unit-form.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react' import { Stack } from 'rsuite' -import { Select, TextInput } from '@mtes-mct/monitor-ui' +import { Select, TextInput, THEME } from '@mtes-mct/monitor-ui' import { ControlType } from '@common/types/control-types.ts' import { Infraction } from '@common/types/infraction-types.ts' import InfractionForm from './infraction-form.tsx' @@ -52,7 +52,13 @@ const EnvInfractionTargetAddedByUnitForm: React.FC + onChange('controlType', nextValue)} - /> - - - - - + {formData?.controlType === null ? ( + + + + + + ) : ( + <> + Ajout d’une infraction pour cette cible + + +