Skip to content

Commit

Permalink
Contrôles - On ne peut pas supprimer une infraction dans le formulai…
Browse files Browse the repository at this point in the history
…re (#3393)

## Linked issues

- Reprise de MTES-MCT/monitorenv#1557
- Resolve #3342

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron authored Jul 12, 2024
2 parents 8f184d4 + acd8d63 commit 58b46f4
Showing 3 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ class SecurityConfig(
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http
.csrf { it.disable() }
.cors { it.configurationSource(corsConfigurationSource()) }
.authorizeHttpRequests { authorize ->
if (oidcProperties.enabled == null || oidcProperties.enabled == false) {
logger.warn(
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { editSideWindowMission } from './utils'
import { SeafrontGroup } from '../../../../src/constants/seafront'
import { ALL_SEAFRONT_GROUP, SeafrontGroup } from '../../../../src/constants/seafront'
import { customDayjs } from '../../utils/customDayjs'
import { getUtcDateInMultipleFormats } from '../../utils/getUtcDateInMultipleFormats'
import { editSideWindowMissionListMissionWithId, openSideWindowMissionList } from '../mission_list/utils'
@@ -452,4 +452,21 @@ context('Side Window > Mission Form > Sea Control Edition', () => {
// Then, the form is valid but incomplete (the completed by field is missing)
cy.get('button:contains("Enregistrer")').should('not.be.disabled')
})

it('Should delete an existing infraction', () => {
// Given
openSideWindowMissionList()
cy.getDataCy(`side-window-sub-menu-${ALL_SEAFRONT_GROUP}`).click()
cy.fill('Etat des données', ['Complétées'])
cy.get('.Table').find(`.TableBodyRow[data-id="2"]`).clickButton('Éditer la mission')
cy.get('*[data-cy="action-list-item"]').click()
cy.wait(500)
cy.contains('Autre infraction 2').should('exist')

// When
cy.clickButton("Supprimer l'infraction", { index: 4 })

// Then
cy.contains('Autre infraction 2').should('not.exist')
})
})
Original file line number Diff line number Diff line change
@@ -29,21 +29,27 @@ export function FormikMultiInfractionPicker({ addButtonLabel, label }: FormikMul

const natinfsAsOptions = useGetNatinfsAsOptions()

const infractionsWithLabelAndGroup = useMemo(() => {
const infractionsWithLabelGroupAndIndex = useMemo(() => {
const allInfractions = [
...(values.gearInfractions?.map(infraction => ({ ...infraction, group: InfractionCategory.GEAR_INFRACTIONS })) ??
[]),
...(values.logbookInfractions?.map(infraction => ({
...(values.gearInfractions?.map((infraction, index) => ({
...infraction,
group: InfractionCategory.LOGBOOK_INFRACTION
group: InfractionCategory.GEAR_INFRACTIONS,
index
})) ?? []),
...(values.otherInfractions?.map(infraction => ({
...(values.logbookInfractions?.map((infraction, index) => ({
...infraction,
group: InfractionCategory.OTHER_INFRACTIONS
group: InfractionCategory.LOGBOOK_INFRACTION,
index
})) ?? []),
...(values.speciesInfractions?.map(infraction => ({
...(values.otherInfractions?.map((infraction, index) => ({
...infraction,
group: InfractionCategory.SPECIES_INFRACTIONS
group: InfractionCategory.OTHER_INFRACTIONS,
index
})) ?? []),
...(values.speciesInfractions?.map((infraction, index) => ({
...infraction,
group: InfractionCategory.SPECIES_INFRACTIONS,
index
})) ?? [])
]
if (!allInfractions.length) {
@@ -153,15 +159,16 @@ export function FormikMultiInfractionPicker({ addButtonLabel, label }: FormikMul
return (
<Wrapper isLight legend={label}>
<FrontendErrorBoundary>
{infractionsWithLabelAndGroup.length > 0 && (
{infractionsWithLabelGroupAndIndex.length > 0 && (
<StyledRow>
{infractionsWithLabelAndGroup.map((infraction, index) => (
// eslint-disable-next-line react/no-array-index-key
<Fragment key={`${infraction.group}-infraction-${index}`}>
{infractionsWithLabelGroupAndIndex.map((infraction, index) => (
<Fragment key={`${infraction.group}-infraction-${infraction.index}`}>
{index !== editedIndex && (
<>
<Infraction data={infraction} index={index} onDelete={remove} onEdit={setEditedIndex} />
{index + 1 < infractionsWithLabelAndGroup.length && <FieldsetGroupSeparator marginBottom={12} />}
<Infraction data={infraction} index={infraction.index} onDelete={remove} onEdit={setEditedIndex} />
{index + 1 < infractionsWithLabelGroupAndIndex.length && (
<FieldsetGroupSeparator marginBottom={12} />
)}
</>
)}

@@ -174,7 +181,9 @@ export function FormikMultiInfractionPicker({ addButtonLabel, label }: FormikMul
onCancel={closeInfractionForm}
onSubmit={update}
/>
{infractionsWithLabelAndGroup.length > index + 1 && <FieldsetGroupSeparator marginBottom={12} />}
{infractionsWithLabelGroupAndIndex.length > index + 1 && (
<FieldsetGroupSeparator marginBottom={12} />
)}
</>
)}
</Fragment>
@@ -183,7 +192,7 @@ export function FormikMultiInfractionPicker({ addButtonLabel, label }: FormikMul
)}
{!isNewInfractionFormOpen && (
<>
{infractionsWithLabelAndGroup.length > 0 && <FieldsetGroupSeparator />}
{infractionsWithLabelGroupAndIndex.length > 0 && <FieldsetGroupSeparator />}
<Button accent={Accent.SECONDARY} Icon={Icon.Plus} isFullWidth onClick={openNewInfractionForm}>
{addButtonLabel}
</Button>
@@ -192,7 +201,7 @@ export function FormikMultiInfractionPicker({ addButtonLabel, label }: FormikMul

{isNewInfractionFormOpen && (
<>
{infractionsWithLabelAndGroup.length > 0 && <FieldsetGroupSeparator marginBottom={12} />}
{infractionsWithLabelGroupAndIndex.length > 0 && <FieldsetGroupSeparator marginBottom={12} />}
<Row>
<InfractionForm
initialValues={{} as MissionAction.Infraction}

0 comments on commit 58b46f4

Please sign in to comment.