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

[Mission] Pré-remplir une infraction avec les données du signalement #1198

Merged

Conversation

claire2212
Copy link
Collaborator

@claire2212 claire2212 commented Feb 13, 2024

Lorsqu'un signalement est rattaché à une mission on peut créer un contrôle depuis ce signalement. Certaines données étaient déjà recopiées du signalement au contrôle, j'ai ajouté le nom, l'immatriculation et la taille du navire.
Si plusieurs cibles ont été renseignées dans le signalement on créé plusieurs infractions pré-remplies avec les infos des cibles.

Migration pour mettre à jour les tailles de navires dans une infraction (validé avec le CACEM):

  • -de 12m -> 11
  • entre 12 et 24 m -> 23
  • entre 24 et 46 m -> 45
  • plus de 46 m -> 46

Related Pull Requests & Issues


  • Tests E2E (Cypress)

Summary by CodeRabbit

  • New Features

    • Enhanced the mission form UI to handle new infractions and controls with updated vessel size and type inputs.
    • Added new test cases for creating and deleting missions with specific actions in the Side Window Mission Form.
  • Refactor

    • Changed vesselSize property from an enum to a numeric value across various components and tests to improve flexibility in specifying vessel sizes.
    • Updated SQL scripts for better categorization and handling of vessel sizes in database records.
    • Refined the UI components for infraction forms, including the addition of numeric inputs for vessel size and selectors for vessel type.
  • Bug Fixes

    • Corrected variable naming and updated selectors in Cypress tests to ensure accurate mission deletion testing.
  • Style

    • Added data-cy attributes to specific form components for improved testability.

@claire2212 claire2212 added the feat. enhancement Amélioration/évolution d'une fonctionnalité label Feb 13, 2024
@claire2212 claire2212 self-assigned this Feb 13, 2024
@claire2212 claire2212 marked this pull request as draft February 15, 2024 09:13
@claire2212 claire2212 force-pushed the claire/pre-fill-control-with-reporting-target-details branch 2 times, most recently from 5714739 to 2c80e60 Compare February 16, 2024 07:46
@claire2212 claire2212 marked this pull request as ready for review February 16, 2024 09:09
@claire2212 claire2212 force-pushed the claire/pre-fill-control-with-reporting-target-details branch from d16f95c to 817b020 Compare February 21, 2024 13:17
Copy link

coderabbitai bot commented Feb 21, 2024

Walkthrough

This set of changes primarily focuses on the transition from using an enumerated type (VesselSizeEnum) to a more flexible Number type for representing vessel sizes across various components and database layers in the application. Additionally, it introduces functionality to pre-fill certain control form fields with information from related reports, enhancing user experience by streamlining data entry processes. The modifications span across backend and frontend, including database migrations, API adjustments, and user interface updates.

Changes

Files Summary
.../domain/entities/.../InfractionEntity.kt
.../infrastructure/api/adapters/.../MissionEnvActionControlInfractionDataInput.kt
frontend/src/domain/entities/missions.ts
.../MissionForm/.../InfractionForm/InfractionFormHeaderVehicle.tsx
.../MissionForm/Schemas/Infraction.ts
.../Missions.helpers.ts
Changed vesselSize property from VesselSizeEnum? to Number?.
.../db/migration/internal/V0.116__update_infraction_vessel_size_type.sql
.../db/testdata/V666.10__insert_dummy_env_actions.sql
Updated SQL scripts for vessel size information in env_actions table.
.../infrastructure/api/endpoints/bff/LegacyMissionsITests.kt
.../infrastructure/database/repositories/JpaMissionRepositoryITests.kt
Updated test cases to use integer values for vesselSize instead of VesselSizeEnum.
frontend/cypress/e2e/side_window/mission_form/... Updated E2E tests with new assertions and added tests for new functionalities.
frontend/src/features/missions/MissionForm/... Updated components to handle new Number type for vesselSize and added pre-filling functionality.

Assessment against linked issues

Objective Addressed Explanation
Pre-fill certain fields in a control form with information from a related report (#1146)
Update documentation to reflect pre-filling functionality (#1146) Documentation updates were not mentioned in the summary of changes.
Evaluate the risk and feasibility of automating the pre-filling of the control point (#1146) The summary does not indicate an evaluation of risks or feasibility related to automating the control point pre-filling.
Request testing of the pre-filling functionality for other information fields (#1146) There's no explicit mention of a request for testing the pre-filling functionality beyond what's implemented.

A Rabbit's Ode to Code

In fields of green, beneath the sky so blue,
A rabbit hopped, with changes fresh and new.
🐇💻 From enum to Number, a leap so bold,
In lines of code, a story told.

With every hop, a bug squashed flat,
🌟 In tests and forms, our rabbit sat.
A cheer for pre-fill, a leap towards grace,
In the land of code, it found its place.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4967110 and 817b020.
Files selected for processing (17)
  • backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/mission/envAction/envActionControl/infraction/InfractionEntity.kt (1 hunks)
  • backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/MissionEnvActionControlInfractionDataInput.kt (2 hunks)
  • backend/src/main/resources/db/migration/internal/V0.116__update_infraction_vessel_size_type.sql (1 hunks)
  • backend/src/main/resources/db/testdata/V666.10__insert_dummy_env_actions.sql (1 hunks)
  • backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/LegacyMissionsITests.kt (4 hunks)
  • backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt (2 hunks)
  • frontend/cypress/e2e/side_window/mission_form/attach_actions_to_reportings_in_mission.spec.ts (2 hunks)
  • frontend/cypress/e2e/side_window/mission_form/delete_mission.spec.ts (2 hunks)
  • frontend/cypress/e2e/side_window/mission_form/mission_actions.spec.ts (1 hunks)
  • frontend/src/domain/entities/missions.ts (3 hunks)
  • frontend/src/features/missions/MissionForm/ActionCards/ReportingCard.tsx (3 hunks)
  • frontend/src/features/missions/MissionForm/ActionForm/ControlForm/InfractionForm/InfractionForm.tsx (1 hunks)
  • frontend/src/features/missions/MissionForm/ActionForm/ControlForm/InfractionForm/InfractionFormHeaderVehicle.tsx (2 hunks)
  • frontend/src/features/missions/MissionForm/ActionForm/ControlForm/InfractionForm/VesselTypeSelector.tsx (1 hunks)
  • frontend/src/features/missions/MissionForm/ActionForm/ControlForm/InfractionsForm.tsx (2 hunks)
  • frontend/src/features/missions/MissionForm/Schemas/Infraction.ts (2 hunks)
  • frontend/src/features/missions/Missions.helpers.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • frontend/src/features/missions/MissionForm/ActionForm/ControlForm/InfractionForm/VesselTypeSelector.tsx
Additional comments: 18
backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/mission/envAction/envActionControl/infraction/InfractionEntity.kt (1)
  • 15-15: The change from VesselSizeEnum? to Number? for vesselSize aligns with the PR's objectives to implement a new vessel size categorization system. Ensure that the handling of vesselSize throughout the application is compatible with this change to maintain type safety and functionality.
backend/src/main/resources/db/migration/internal/V0.116__update_infraction_vessel_size_type.sql (1)
  • 2-26: The SQL migration script correctly updates vesselSize values within env_actions to align with the new vessel size categories. Ensure thorough testing on a backup of the production database to confirm the script's effectiveness and to prevent unintended side effects.
frontend/src/features/missions/MissionForm/ActionForm/ControlForm/InfractionForm/InfractionFormHeaderVehicle.tsx (1)
  • 12-16: The replacement of VesselSizeSelector with FormikNumberInput for vessel size input and the addition of vessel type handling logic align with the PR's objectives and enhance the form's functionality. Ensure thorough testing to verify the user experience, focusing on the usability of the FormikNumberInput for vessel size input.

Also applies to: 30-36

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/MissionEnvActionControlInfractionDataInput.kt (1)
  • 20-20: The update of vesselSize to Number? in MissionEnvActionControlInfractionDataInput is consistent with the PR's objectives for the new vessel size categorization system. Ensure compatibility with this change across the application to maintain data handling integrity.
frontend/src/features/missions/MissionForm/Schemas/Infraction.ts (1)
  • 40-40: The update of the vesselSize validation to Yup.number().nullable() aligns with the transition to numeric vessel sizes and is crucial for form validation. Ensure thorough testing to confirm that the validation behaves as expected and does not introduce usability issues.
frontend/cypress/e2e/side_window/mission_form/attach_actions_to_reportings_in_mission.spec.ts (1)
  • 128-137: The new test case for creating a control with infraction from a reporting is well-structured and follows Cypress best practices. Ensure that the createMissionWithAttachedReportingAndAttachedAction utility function correctly sets up the necessary preconditions for this test.
frontend/src/domain/entities/missions.ts (1)
  • 298-298: The change from VesselSizeEnum to a Number type for vesselSize in NewInfraction aligns with the PR objectives and TypeScript best practices. Ensure this change is consistently applied across the codebase where vessel sizes are handled.
backend/src/main/resources/db/testdata/V666.10__insert_dummy_env_actions.sql (3)
  • 8-8: The update to vesselSize to use numeric values in the CONTROL action type aligns with the PR objectives. Ensure this script is thoroughly tested in a development or staging environment to confirm the correct application of changes.
  • 11-11: The update to vesselSize to numeric values and adjustments to vesselType in another CONTROL action type entry are consistent with the PR's goals. Verify the script's execution in a test environment to ensure data integrity.
  • 13-13: The changes to vesselSize and vesselType in this CONTROL action type entry are in line with the PR's objectives of standardizing vessel sizes. Confirm that these updates are accurately reflected in the database after running the script.
frontend/src/features/missions/Missions.helpers.ts (2)
  • 14-15: The addition of NewInfraction and Infraction types enhances the type safety and clarity of the code by explicitly defining the structure of infraction-related data. This is a positive change that aligns with best practices for TypeScript development.
  • 29-29: The modification in the infractionFactory function to accept an optional Partial<Infraction> parameter and return a NewInfraction is a good practice. It allows for the creation of infraction objects with default values while also enabling customization through partial overrides. This approach improves code reusability and maintainability.
frontend/cypress/e2e/side_window/mission_form/mission_actions.spec.ts (1)
  • 43-43: Updating the assertion for vesselSize from comparing with a string to comparing with the number 45 aligns with the changes made in the application logic, where vessel sizes are now handled as numeric values instead of strings. This change ensures that the test accurately reflects the application's behavior and is a good practice for maintaining test reliability.
backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/LegacyMissionsITests.kt (4)
  • 181-181: The change from VesselSizeEnum.FROM_12_TO_24m to a direct integer value 23 for vesselSize in test assertions correctly aligns with the PR's objective to transition to numeric representation for vessel sizes. This update is consistent and correctly implemented in the context of the test setup.
  • 447-447: The update of vesselSize to 23 in this test assertion is consistent with the PR's objective and the new vessel size categorization system. It's important to ensure that all related test cases are similarly updated to reflect this change across the codebase.
  • 495-495: Changing the vesselSize to a direct integer value 23 in this test assertion is in line with the PR's enhancements. This modification ensures that the test reflects the new way of handling vessel sizes, contributing to the overall consistency and accuracy of the test suite.
  • 745-745: The modification of vesselSize to 23 here is correctly implemented, aligning with the PR's goal of transitioning to a numeric representation for vessel sizes. This change is crucial for maintaining the integrity and relevance of the test suite in light of the updated domain model.
backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt (1)
  • 862-862: The change from using VesselSizeEnum to directly setting vesselSize as an integer (23) aligns with the PR objectives to handle vessel sizes as integers for standardized categorization. This update is crucial for consistency with the new vessel size handling approach across the application. However, it's essential to ensure that all related tests and application logic are updated to reflect this change, avoiding potential mismatches or errors in data handling.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 817b020 and c6f4f53.
Files selected for processing (1)
  • frontend/src/features/missions/MissionForm/ActionForm/ControlForm/InfractionForm/InfractionFormHeaderVehicle.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/src/features/missions/MissionForm/ActionForm/ControlForm/InfractionForm/InfractionFormHeaderVehicle.tsx

WHERE
action_type = 'CONTROL'
AND jsonb_array_length(t.value->'infractions') > 0
AND mission_id > 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il y a un souci avec la mission 0 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on a des missions avec des id négatifs (qui viennent de Poséidon)

@@ -31,8 +32,8 @@ export function InfractionsForm({ canAddInfraction, envActionIndex, form, push,
}

const handleDuplicateInfraction = index => () => {
const numberOfInfractions = form?.values.envActions[envActionIndex]?.infractions.length || 0
const selectedInfraction = form?.values.envActions[envActionIndex]?.infractions[index] as Infraction
const numberOfInfractions = infractions.length || 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'ai l'impression que infractionsn'est pas typé. En l'occurence, je pense qu'il faut écrire infractions?.length

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je type la variable plutôt et met un tableau vide par défaut:
const infractions: Array<Infraction> = form?.values.envActions[envActionIndex]?.infractions ?? []

@claire2212 claire2212 force-pushed the claire/pre-fill-control-with-reporting-target-details branch from c6f4f53 to e19fe32 Compare March 4, 2024 17:27
@claire2212 claire2212 requested a review from thoomasbro March 4, 2024 17:35
Copy link
Collaborator

@VincentAntoine VincentAntoine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK pour la partie migration, testé sur les données de prod sur les cas de contrôles avec :

  • une infraction avec vesselSize=null
  • une infraction avec vesselSize=FROM_24_TO_46m
  • deux infractions avec vesselSize identiques
  • deux infractions avec vesselSize différents

Le résultat est OK dans tous les cas.

@claire2212 claire2212 merged commit 35cb16c into main Mar 6, 2024
19 checks passed
@claire2212 claire2212 deleted the claire/pre-fill-control-with-reporting-target-details branch March 6, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat. enhancement Amélioration/évolution d'une fonctionnalité
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signalements – Pré-remplir le contrôle avec les coordonnées du signalement rattaché ?
3 participants