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

Cnh/replace simulation conf reducer by slice #5583

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

kmer2016
Copy link
Contributor

@kmer2016 kmer2016 commented Nov 2, 2023

close #5273
close #5274

Key Updates:

  • Introduction of Contexts: We have added two new contexts, useOsrdConfAction and useOsrdConfSelectors. These enable components that utilize osrdconf to accurately select the appropriate selectors/actions (either stdcmConf or simulationConf).
  • wrapping stdcm and operational-studies routes with the the osrdConf context passing the right parameters.

Pre-Merge Tasks:

Currently, components can only utilize osrdConf actions/selectors if they are encapsulated within OsrdConfContextLayout. This limitation causes issues in components that require access to osrdConf from the store but are not appropriately wrapped. For instance, the Home component in the application editor, which utilizes getInfraID, is not encapsulated in osrdConf. To address these issues:

  • We need to incorporate an infraID field for osrdConf within the map slice.
  • The editor's matching route should be wrapped with the OsrdConfContextLayout, using the correct parameters.
    These adjustments must be applied consistently across all osrdConf fields usages outside the stdcm/* and operational-studies routes.
    Additionally, it's worth mentioning the presence of functions like buildCommonConfReducers and buildCommonConfSelectors, which broadly generate reducers and selectors for managing osrdConf parameters. it can help to generate osrdconf parameters needed inside others slices.

Testing

  • test component which use selectors/actions of stdcm/simulation slice inside modal
  • test destination/origin component as they have been refactored.
  • test store persistence
  • Check if need to save projectId, studyId and scenarioId into store anymore

@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch from f412a90 to 8ca2619 Compare November 3, 2023 11:42
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Attention: 1781 lines in your changes are missing coverage. Please review.

Comparison is base (84d57c2) 27.30% compared to head (a4085f5) 26.85%.

Files Patch % Lines
front/src/common/osrdContext.tsx 38.79% 71 Missing ⚠️
...ainschedule/components/ManageTrainSchedule/Map.tsx 0.00% 68 Missing ⚠️
...lications/editor/tools/pointEdition/components.tsx 0.00% 55 Missing and 1 partial ⚠️
...mulationResult/components/SimulationResultsMap.tsx 0.00% 55 Missing and 1 partial ⚠️
front/src/main/app.jsx 0.00% 45 Missing ⚠️
front/src/common/Map/Layers/GeoJSONs.tsx 0.00% 42 Missing and 1 partial ⚠️
...ools/routeEdition/components/EditRouteMetadata.tsx 0.00% 40 Missing and 1 partial ⚠️
...ainSchedule/helpers/adjustConfWithTrainToModify.ts 0.00% 40 Missing ⚠️
...ManageTrainSchedule/SubmitConfAddTrainSchedule.tsx 0.00% 36 Missing ⚠️
...or/tools/routeEdition/components/EditRoutePath.tsx 0.00% 33 Missing and 1 partial ⚠️
... and 100 more
Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #5583      +/-   ##
============================================
- Coverage     27.30%   26.85%   -0.46%     
  Complexity     2136     2136              
============================================
  Files           952      952              
  Lines        124900   124095     -805     
  Branches       2690     2574     -116     
============================================
- Hits          34106    33327     -779     
- Misses        89189    89279      +90     
+ Partials       1605     1489     -116     
Flag Coverage Δ
core 78.88% <ø> (ø)
editoast 75.36% <ø> (ø)
front 8.69% <13.41%> (-0.79%) ⬇️
gateway 2.54% <ø> (ø)
tests 81.77% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch 3 times, most recently from 1dea74a to d1a9dfa Compare November 13, 2023 06:56
@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch from d1a9dfa to 0b38d8d Compare November 14, 2023 17:50
@Uriel-Sautron Uriel-Sautron force-pushed the cnh/replace-simulationConf-reducer-by-slice branch 2 times, most recently from 775bf41 to 3709829 Compare November 27, 2023 15:41
@Uriel-Sautron Uriel-Sautron force-pushed the cnh/replace-simulationConf-reducer-by-slice branch from 3709829 to 0648532 Compare December 7, 2023 10:55
@Uriel-Sautron Uriel-Sautron marked this pull request as ready for review December 7, 2023 10:58
@Uriel-Sautron Uriel-Sautron requested a review from a team as a code owner December 7, 2023 10:58
Copy link
Contributor

@SharglutDev SharglutDev left a comment

Choose a reason for hiding this comment

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

Thank you for this amazing work ! Reviewed only the code for now, will test it asap.

Left comments. 90% of them are related with this recent front guideline for type imports.

front/src/common/osrdContext.tsx Outdated Show resolved Hide resolved
front/src/common/osrdContext.tsx Outdated Show resolved Hide resolved
front/src/main/app.jsx Outdated Show resolved Hide resolved
front/src/reducers/osrdconf/stdcmConf/index.ts Outdated Show resolved Hide resolved
front/src/applications/stdcm/views/StdcmRequestModal.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@SharglutDev SharglutDev left a comment

Choose a reason for hiding this comment

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

Tested the app in operational studies, stdcm with modals, store is still updated and persistent, good job !

One more request regarding one of my previous comment : you can remove the updateFeatureInfoClick action in the map reducer (the one updating an id), its only used at one place in the code and doesn't do anything as there isn't any selector for the related state. (approved by @nicolaswurtz)

@Uriel-Sautron Uriel-Sautron force-pushed the cnh/replace-simulationConf-reducer-by-slice branch 2 times, most recently from 494ac32 to 7bee515 Compare December 15, 2023 14:53
Copy link
Contributor

@SharglutDev SharglutDev left a comment

Choose a reason for hiding this comment

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

Lgtm, thank you for the hard work ! I approve for my part but I'll let @clarani check it too in case I missed something
(Good luck for the many many conflicts :) )

front/src/reducers/infra/index.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

Here are some comments, I'm still reviewing the PR

front/src/reducers/infra/index.ts Outdated Show resolved Hide resolved
front/src/reducers/infra/__tests__/infraTestBuilder.ts Outdated Show resolved Hide resolved
front/src/reducers/infra/selectors.ts Outdated Show resolved Hide resolved
front/src/reducers/map/index.ts Outdated Show resolved Hide resolved
front/src/reducers/map/index.ts Show resolved Hide resolved
front/src/reducers/user/index.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

I've just finished to review the reducers files ! :)

front/src/reducers/osrdconf/stdcmConf/selectors.ts Outdated Show resolved Hide resolved
front/src/reducers/osrdconf/stdcmConf/index.ts Outdated Show resolved Hide resolved
front/src/reducers/osrdconf/stdcmConf/index.ts Outdated Show resolved Hide resolved
front/src/reducers/osrdconf/stdcmConf/index.ts Outdated Show resolved Hide resolved
front/src/reducers/osrdconf/osrdConfCommon/selectors.ts Outdated Show resolved Hide resolved
front/src/reducers/osrdconf/osrdConfCommon/selectors.ts Outdated Show resolved Hide resolved
@Uriel-Sautron Uriel-Sautron force-pushed the cnh/replace-simulationConf-reducer-by-slice branch 2 times, most recently from 620f926 to c6025b1 Compare December 21, 2023 11:08
@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch 2 times, most recently from a7edc71 to 0456f1a Compare December 27, 2023 10:03
Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

Thanks, here are some global comments:

  • check the imports to 'Store' (it is invalid, the import should occur from 'store')
  • rename the following types to pascal case and remove the -Type:
    • OperationalStudiesConfSliceType (=> OperationalStudiesConfSlice)
    • OperationalStudiesConfSliceActionsType
    • OperationalStudiesConfSelectorsType
    • mapSliceActionsType
    • StdcmConfSliceType
    • StdcmConfSelectorsType
    • editorSliceType
    • EditorSliceActionsType (=> EditorSliceAction)
    • EditorActionsType (=> EditorAction)
    • EditorSelectorsType
    • mapViewerSliceType
    • MapViewerStateType
    • CommonConfReducersType
    • InfraStateReducersType (=> InfraStateReducer)
    • InfraStateType
    • MapViewerSelectorsType
    • ... (maybe I forgot some)
  • stdcmMode is not used anymore, so you can remove it from the store

front/src/reducers/index.ts Outdated Show resolved Hide resolved
front/src/reducers/index.ts Outdated Show resolved Hide resolved
front/src/reducers/osrdconf/stdcmConf/index.ts Outdated Show resolved Hide resolved
@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch from 0456f1a to 060f913 Compare December 29, 2023 11:08
Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

Some other comments:

  • do you think it would be relevant to throw an error if we use useInfraId and infraId is undefined ? This way, we can type it as number
  • when using useOsrdActions(), no need to cast now (see 20 occurences approximately). If we use an action specific to a slice, we can directly import it (no need to go through useOsrdActions())
  • same thing for useOsrdConfSelectors()

@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch 3 times, most recently from 41606da to 9d1478e Compare December 29, 2023 12:59
Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

Some last comments:

  • can you also remove the cast for all the useOsrdConfActions()

@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch 2 times, most recently from 0ffe514 to 20868f5 Compare December 29, 2023 16:28
Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

Almost good, I only found a warning when testing. Once this warning is solved, we can merge this PR 🎉
image

@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch from a0a609d to 3b02142 Compare January 2, 2024 11:56
@kmer2016
Copy link
Contributor Author

kmer2016 commented Jan 2, 2024

Apparently, the warning is linked to our store becoming increasingly large and, by default, Redux traverses the entire store to check the immutability of each field. Therefore, this check can take some time. If this time exceeds the threshold of 32ms, it triggers the warning.
To resolve this simply, we can adjust the ImmutableStateInvariantMiddleware middleware:

  • either we disable it
  • we increase the threshold at which the warning is displayed.

I opted for the first solution because, as mentioned here, in any case, we use Immer to create our store slices (using createSlice), so we are already ensured of having immutable fields. Therefore, it's not really necessary to check the entire store each time. And as indicated by one of the maintainers here, disabling this option can improve performance.

Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

LGTM, tested and it's more fluid now ✅
I tried to check everything, we will have to stay vigilant about it in the coming days

@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch from 3b02142 to d7ce070 Compare January 3, 2024 09:57
…ebase dev

- fix osrdConfContext

- add mapInfraID in map store

- add infraID in props TracksGeographic

- add infraID in props common/Map/Layers/Routes

- add infraID in props common/Map/Layers/OperationalPoints

- add infraID in props common/Map/Layers/Catenaries

- add infraID in props BufferStops, Detectors, LineSearchLayer, NeutralSections, Signals, SpeedLimits, Switches, SNCF_PSL

- add infraID in props common/Map/Layers/GeoJSONs and add editorInfraID in editor slice

- remove eslint warning

- create commonState builder

- change osrdConfContext to osrdContext

- create mapViewer slice

- fix eslint error

- fix error after rebase

- add test mapViewer

- fix review's comments

front: change type snakeCase to PascalCase and extends InfraStateType to StdcmConf and OperationalStudyConf

front: create and use useOsrdConfSelector

front: create and use useInfraID

front: create and use useOsrdConfActions

front: create and use useUpdateInfraID

front: move featureInfoClick from infra reducer to osrdConf reducer

front: rename/harmonize

front: remove stdcmMode from store

front: fix

front: remove unnecessary condition

front: typo

front: fix

front: remove unised cast

front: disable immutableCheck
@kmer2016 kmer2016 force-pushed the cnh/replace-simulationConf-reducer-by-slice branch from d7ce070 to a4085f5 Compare January 3, 2024 10:23
@kmer2016 kmer2016 added this pull request to the merge queue Jan 3, 2024
Merged via the queue into dev with commit fffca59 Jan 3, 2024
18 of 19 checks passed
@kmer2016 kmer2016 deleted the cnh/replace-simulationConf-reducer-by-slice branch January 3, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace osrdConf.stdcmConf by stdcmConf in store replace osrdConf.simulationConf by simulationConf in store
6 participants