Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Signalement] Lors de l'écriture d'un signalement, le raffraichissement de l'app efface les données saisies dans le formulaire #3002

Merged
merged 7 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions frontend/cypress/e2e/side_window/reporting_list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,14 @@ context('Reportings', () => {

// When
cy.get('[data-cy="side-window-edit-reporting"]').eq(1).click()
cy.get('[data-cy="new-reporting-title"]').type(
'{backspace}{backspace}{backspace}{backspace}{backspace}{backspace} km'
)
cy.get('[data-cy="new-reporting-select-natinf"]').click()
cy.wait(200)
cy.get('.rs-search-box-input').type('maille{enter}')
cy.wait(200)
cy.get('[data-cy="new-reporting-create-button"]').click()
cy.fill('Titre', 'Suspicion de chalutage dans les 3 km')
cy.fill('Natinf', 'maille')
cy.clickButton('Valider')

// Then
cy.wait('@updateReporting').then(({ request, response }) => {
expect(request.body.natinfCode).equal(23581)
expect(request.body.title).contains('Suspicion de chalutage dans les 3 km')
expect(request.body.title).contains('Suspicion de chalutage dans les 3 km')
expect(response && response.statusCode).equal(200)
})
cy.wait(200)
Expand Down Expand Up @@ -182,10 +177,9 @@ context('Reportings', () => {

function modifyReportingToObservation(rowNumber, numberOfReportings) {
cy.get('[data-cy="side-window-edit-reporting"]').eq(rowNumber).click()
cy.get('[data-cy="new-reporting-select-observation-reporting-type"]').click()
cy.get('[data-cy="new-reporting-author-trigram"]').type('{backspace}{backspace}{backspace}LTH')
cy.wait(500)
cy.get('[data-cy="new-reporting-create-button"]').click()
cy.fill('Type', 'Observation')
cy.fill('Saisi par', '{backspace}{backspace}{backspace}LTH')
cy.clickButton('Valider')

// Then
cy.wait('@updateReporting').then(({ request, response }) => {
Expand Down
51 changes: 23 additions & 28 deletions frontend/cypress/e2e/vessel_sidebar/reporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,23 @@ context('Vessel sidebar reporting tab', () => {
cy.wait(100)

// Create an new Observation
cy.get('*[data-cy="vessel-sidebar-open-reporting"]').click()
cy.get('[data-cy="new-reporting-select-observation-reporting-type"]').click()
cy.get('*[data-cy="new-reporting-reporting-actor-UNIT"]').click()
cy.get('*[data-cy="new-reporting-select-unit"]').click()
cy.get('[data-key="10338"] > .rs-picker-select-menu-item').click({ force: true })
cy.get('*[data-cy="new-reporting-author-contact"]').type('Jean Bon (0612365896)')
cy.get('*[data-cy="new-reporting-title"]').type('Observation: Sortie non autorisée')
cy.get('*[data-cy="new-reporting-description"]').type(
'Ce navire ne devrait pas être en mer, mais ceci est une observation.'
)
cy.get('*[data-cy="new-reporting-author-trigram"]').type('NTP')
cy.clickButton('Ouvrir un signalement')
cy.fill('Type', 'Observation')
cy.fill('Origine', 'Unité')
cy.fill("Choisir l'unité", 'OFB SD 56 (Office Français de la Biodiversité)')
cy.fill('Nom et contact (numéro, mail…) de l’émetteur', 'Jean Bon (0612365896)')
cy.fill('Titre', 'Observation: Sortie non autorisée')
cy.fill('Description', 'Ce navire ne devrait pas être en mer, mais ceci est une observation.')
cy.fill('Saisi par', 'NTP')
cy.intercept('*reporting*').as('createReporting')
cy.get('*[data-cy="new-reporting-create-button"]').scrollIntoView().click()
cy.clickButton('Valider')
cy.wait('@createReporting')

cy.intercept('*update*').as('updateReporting')
cy.get('*[data-cy^="edit-reporting-card"]').first().click({ timeout: 10000 })
cy.get('*[data-cy="new-reporting-select-infraction-reporting-type"]').click({ timeout: 10000 })
cy.get('*[data-cy="new-reporting-select-natinf"]').click()
cy.get('[data-key="7059"] > .rs-picker-select-menu-item').click({ force: true })
cy.get('*[data-cy="new-reporting-create-button"]').scrollIntoView().click()
cy.fill('Natinf', '7059')
cy.clickButton('Valider')
cy.wait('@updateReporting')
cy.wait(50)

Expand Down Expand Up @@ -158,20 +154,19 @@ context('Vessel sidebar reporting tab', () => {
})

function createReporting() {
cy.get('*[data-cy="vessel-sidebar-open-reporting"]').click()
cy.get('*[data-cy="new-reporting-reporting-actor-UNIT"]').click()
cy.get('*[data-cy="new-reporting-select-unit"]').click()
cy.get('[data-key="10338"] > .rs-picker-select-menu-item').click({ force: true })
cy.get('*[data-cy="new-reporting-author-contact"]').type('Jean Bon (0612365896)')
cy.get('*[data-cy="new-reporting-title"]').type('Sortie non autorisée')
cy.get('*[data-cy="new-reporting-description"]').type(
"Ce navire ne devrait pas être en mer, il n'a plus de points sur son permis"
)
cy.get('*[data-cy="new-reporting-author-trigram"]').type('LTH')
cy.get('*[data-cy="new-reporting-select-natinf"]').click()
cy.get('[data-key="2608"] > .rs-picker-select-menu-item').click({ force: true })
cy.intercept('*reporting*').as('createReporting')
cy.get('*[data-cy="new-reporting-create-button"]').scrollIntoView().click()

cy.clickButton('Ouvrir un signalement')

cy.fill('Origine', 'Unité')
cy.fill("Choisir l'unité", 'OFB SD 56 (Office Français de la Biodiversité)')
cy.fill('Nom et contact (numéro, mail…) de l’émetteur', 'Jean Bon (0612365896)')
cy.fill('Titre', 'Sortie non autorisée')
cy.fill('Description', "Ce navire ne devrait pas être en mer, il n'a plus de points sur son permis")
cy.fill('Natinf', '2608')
cy.fill('Saisi par', 'LTH')

cy.clickButton('Valider')
cy.wait('@createReporting')
}
})
6 changes: 3 additions & 3 deletions frontend/src/api/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { monitorfishApiKy } from './api'
import { ApiError } from '../libs/ApiError'

import type {
EditedReporting,
InfractionSuspicionReporting,
PendingAlertReporting,
Reporting,
ReportingCreation,
ReportingUpdate
ReportingCreation
} from '../domain/types/reporting'

export const ARCHIVE_REPORTING_ERROR_MESSAGE = "Nous n'avons pas pu archiver le signalement"
Expand Down Expand Up @@ -95,7 +95,7 @@ async function addReportingFromAPI(newReporting: ReportingCreation): Promise<Rep
*
* @throws {@link ApiError}
*/
async function updateReportingFromAPI(id: number, nextReporting: ReportingUpdate): Promise<Reporting> {
async function updateReportingFromAPI(id: number, nextReporting: EditedReporting): Promise<Reporting> {
try {
return await monitorfishApiKy
.put(`/bff/v1/reportings/${id}/update`, {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/domain/shared_slices/Vessel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ const vesselSlice = createSlice({
}
})

if (Vessel.getVesselFeatureId(state.selectedVesselIdentity) === action.payload.vesselFeatureId) {
if (
state.selectedVesselIdentity &&
Vessel.getVesselFeatureId(state.selectedVesselIdentity) === action.payload.vesselFeatureId
) {
let reportings: ReportingType[] = []

if (state.selectedVessel?.reportings?.length) {
Expand Down
37 changes: 16 additions & 21 deletions frontend/src/domain/types/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,43 @@ export type BaseReportingCreation = Omit<

export type ReportingCreation = BaseReportingCreation & {
type: ReportingType.INFRACTION_SUSPICION | ReportingType.OBSERVATION
value: InfractionSuspicion | Observation
value: EditedReporting
}

export type Reporting = InfractionSuspicionReporting | ObservationReporting | PendingAlertReporting

export type EditableReporting = InfractionSuspicionReporting | ObservationReporting

export type EditedReporting = Partial<InfractionSuspicion | Observation> & {
type: ReportingType.INFRACTION_SUSPICION | ReportingType.OBSERVATION
}

export type CurrentAndArchivedReportingsOfSelectedVessel = {
archived: Reporting[]
current: Reporting[]
}

export type InfractionSuspicion = {
authorContact: string | null
authorTrigram: string | null
controlUnit: LegacyControlUnit.LegacyControlUnit | null
controlUnitId: number | null
description: string
authorContact: string | undefined
authorTrigram: string | undefined
controlUnit: LegacyControlUnit.LegacyControlUnit | undefined
controlUnitId: number | undefined
description: string | undefined
dml: string
natinfCode: number
reportingActor: keyof typeof ReportingOriginActor
seaFront: SeaFront
title: string
type: string
type: ReportingType.INFRACTION_SUSPICION
}

export type Observation = {
authorContact: string | null
authorTrigram: string | null
controlUnit: LegacyControlUnit.LegacyControlUnit | null
controlUnitId: number | null
description: string
reportingActor: keyof typeof ReportingOriginActor
title: string
type: string
}

export type ReportingUpdate = {
authorContact: string | undefined
authorTrigram: string | undefined
controlUnitId: number | null
controlUnit: LegacyControlUnit.LegacyControlUnit | undefined
controlUnitId: number | undefined
description: string | undefined
natinfCode: number | null
reportingActor: keyof typeof ReportingOriginActor
title: string
type: ReportingType
type: ReportingType.OBSERVATION
}
2 changes: 1 addition & 1 deletion frontend/src/features/MainWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export function MainWindow() {
<MapButtons />
<RightMenuOnHoverArea />
{isVesselListDisplayed && <VesselList namespace="homepage" />}
{isVesselSidebarOpen && <VesselSidebar />}
</LegacyRsuiteComponentsWrapper>
{isVesselSidebarOpen && <VesselSidebar />}

{isControlUnitDialogDisplayed && <ControlUnitDialog />}
{isControlUnitListDialogDisplayed && <ControlUnitListDialog />}
Expand Down
Loading
Loading