Skip to content

Commit

Permalink
Remove duplicate action
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Mar 28, 2024
1 parent cd366a1 commit 70e2c4f
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 131 deletions.
82 changes: 0 additions & 82 deletions frontend/cypress/e2e/side_window/mission_form/action_list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,88 +34,6 @@ context('Side Window > Mission Form > Action List', () => {
cy.get('*[data-cy="action-list-item"]').eq(0).should('contain', 'Une observation.')
})

it('Should send the expected data to the API when duplicating a mission action', () => {
editSideWindowMissionListMissionWithId(4, SeaFrontGroup.MEMN)

cy.intercept('POST', '/api/v1/missions/4', {
body: {
id: 1
},
statusCode: 201
}).as('updateMission4')
cy.intercept('POST', '/bff/v1/mission_actions').as('createMissionAction')
cy.get('*[data-cy="action-list-item"]').click()

cy.wait(250)

cy.clickButton('Dupliquer l’action')

cy.wait(250)

cy.waitForLastRequest(
'@createMissionAction',
{
body: {
actionType: 'SEA_CONTROL',
closedBy: null,
controlQualityComments: null,
controlUnits: [],
emitsAis: null,
emitsVms: 'NOT_APPLICABLE',
externalReferenceNumber: null,
facade: 'MEMN',
faoAreas: ['27.8.a'],
feedbackSheetRequired: false,
flagState: 'FR',
flightGoals: [],
gearInfractions: [],
gearOnboard: [],
hasSomeGearsSeized: false,
hasSomeSpeciesSeized: false,
id: null,
internalReferenceNumber: 'U_W0NTFINDME',
ircs: null,
latitude: 53.35,
licencesAndLogbookObservations: null,
licencesMatchActivity: 'NOT_APPLICABLE',
logbookInfractions: [],
logbookMatchesActivity: 'NOT_APPLICABLE',
longitude: -10.85,
missionId: 4,
numberOfVesselsFlownOver: null,
otherComments: 'Commentaires post contrôle',
otherInfractions: [],
portLocode: null,
segments: [],
seizureAndDiversion: false,
seizureAndDiversionComments: null,
separateStowageOfPreservedSpecies: 'NO',
speciesInfractions: [],
speciesObservations: null,
speciesOnboard: [],
speciesSizeControlled: null,
speciesWeightControlled: null,
unitWithoutOmegaGauge: false,
userTrigram: 'JKL',
vesselId: 2,
vesselName: 'MALOTRU',
vesselTargeted: 'YES'
}
},
5
)
.its('response.statusCode')
.should('eq', 201)

// And we delete this action

editSideWindowMissionListMissionWithId(4, SeaFrontGroup.MEMN)

cy.clickButton('Supprimer l’action', { index: 1 })

cy.wait(250)
})

it('Should send the expected data to the API when deleting a mission action', () => {
editSideWindowMissionListMissionWithId(34, SeaFrontGroup.MEMN)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import type { Promisable } from 'type-fest'

type FishActionCardProps = Readonly<{
missionAction: MissionActionFormValues
onDuplicate: () => Promisable<void>
onRemove: () => Promisable<void>
}>
export function FishActionCard({ missionAction, onDuplicate, onRemove }: FishActionCardProps) {
export function FishActionCard({ missionAction, onRemove }: FishActionCardProps) {
const natinfsAsOptions = useGetNatinfsAsOptions()

const isControlAction =
Expand Down Expand Up @@ -119,15 +118,6 @@ export function FishActionCard({ missionAction, onDuplicate, onRemove }: FishAct
<p>{actionLabel}</p>
</ActionLabel>

<RightAlignedIconButton
accent={Accent.TERTIARY}
color={THEME.color.slateGray}
Icon={Icon.Duplicate}
iconSize={20}
onClick={onDuplicate}
title="Dupliquer l’action"
withUnpropagatedClick
/>
<RightAlignedIconButton
accent={Accent.TERTIARY}
color={THEME.color.maximumRed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type ActionListProps = Readonly<{
missionId: number | undefined
missionTypes: Mission.MissionType[] | undefined
onAdd: (actionType: MissionAction.MissionActionType) => Promisable<void>
onDuplicate: (actionIndex: number) => Promisable<void>
onRemove: (actionIndex: number) => Promisable<void>
onSelect: (actionIndex: number) => Promisable<void>
}>
Expand All @@ -33,7 +32,6 @@ export function ActionList({
missionId,
missionTypes = [],
onAdd,
onDuplicate,
onRemove,
onSelect
}: ActionListProps) {
Expand Down Expand Up @@ -128,7 +126,6 @@ export function ActionList({
// eslint-disable-next-line react/no-array-index-key
key={index}
missionAction={action as MissionActionFormValues}
onDuplicate={() => onDuplicate(action.index!!)}
onRemove={() => onRemove(action.index!!)}
/>
</ActionCard>
Expand Down
35 changes: 0 additions & 35 deletions frontend/src/features/Mission/components/MissionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import { assertNotNullish } from '@utils/assertNotNullish'
import { getMissionStatus } from 'domain/entities/mission/utils'
import { SideWindowMenuKey } from 'domain/entities/sideWindow/constants'
import { omit } from 'lodash/fp'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import styled from 'styled-components'
import { FrontendErrorBoundary } from 'ui/FrontendErrorBoundary'
Expand Down Expand Up @@ -334,39 +333,6 @@ export function MissionForm() {
]
)

const duplicateAction = useCallback(
async (actionIndex: number) => {
/**
* If a debounce function is not yet executed, stop there to avoid race condition.
* /!\ This can leads to save the debounced action update to the wrong action index
*/
if (updateEditedActionFormValues.isPending()) {
setTimeout(() => duplicateAction(actionIndex), DEBOUNCE_DELAY)

return
}

const actionCopy: MissionActionFormValues = omit(['id'], actionsFormValues[actionIndex])
setEditedActionIndex(0)

const createdId = await dispatch(
autoSaveMissionAction(actionCopy, missionIdRef.current, mainFormValues.isClosed, isAutoSaveEnabled)
)

const nextActionsWithIdFormValues = [{ ...actionCopy, id: createdId }, ...actionsFormValues]
setActionsFormValues(nextActionsWithIdFormValues)
updateReduxSliceDraft()
},
[
dispatch,
updateEditedActionFormValues,
updateReduxSliceDraft,
actionsFormValues,
mainFormValues.isClosed,
isAutoSaveEnabled
]
)

const updateEditedActionIndex = useCallback(
(nextActionIndex: number | undefined) => {
/**
Expand Down Expand Up @@ -488,7 +454,6 @@ export function MissionForm() {
missionId={missionIdRef.current}
missionTypes={mainFormValues.missionTypes}
onAdd={addAction}
onDuplicate={duplicateAction}
onRemove={removeAction}
onSelect={updateEditedActionIndex}
/>
Expand Down

0 comments on commit 70e2c4f

Please sign in to comment.