From 9442262779e4ed2e236317b4c7d68128334954ac Mon Sep 17 00:00:00 2001 From: Clara Ni Date: Fri, 3 Jan 2025 10:59:02 +0100 Subject: [PATCH 1/2] front: set up specific tag for projects, studies and scenari Signed-off-by: Clara Ni --- front/src/common/api/osrdEditoastApi.ts | 82 ++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 7 deletions(-) diff --git a/front/src/common/api/osrdEditoastApi.ts b/front/src/common/api/osrdEditoastApi.ts index 6b49ed8775c..d6ba13e11b0 100644 --- a/front/src/common/api/osrdEditoastApi.ts +++ b/front/src/common/api/osrdEditoastApi.ts @@ -42,24 +42,92 @@ const osrdEditoastApi = generatedEditoastApi.enhanceEndpoints({ // we don't want to invalidate the trainschedule tag here to prevent multiple calls invalidatesTags: ['timetable', 'scenarios'], }, - // Invalidate the children count and last update timestamp + + // Project handling + getProjects: { + providesTags: (result) => [ + { type: 'projects', id: 'LIST' }, + ...(result?.results || []).map((project) => ({ + type: 'projects' as const, + id: project.id, + })), + ], + }, + getProjectsByProjectId: { + providesTags: (_result, _error, args) => [{ type: 'projects', id: args.projectId }], + }, + postProjects: { + invalidatesTags: [{ type: 'projects', id: 'LIST' }], + }, + patchProjectsByProjectId: { + invalidatesTags: (_result, _error, args) => [{ type: 'projects', id: args.projectId }], + }, + deleteProjectsByProjectId: { + invalidatesTags: [{ type: 'projects', id: 'LIST' }], + }, + + // Studies handling + getProjectsByProjectIdStudies: { + providesTags: (result) => [ + { type: 'studies', id: 'LIST' }, + ...(result?.results || []).map(({ id }) => ({ + type: 'studies' as const, + id, + })), + ], + }, + getProjectsByProjectIdStudiesAndStudyId: { + providesTags: (_result, _error, args) => [{ type: 'studies', id: args.studyId }], + }, postProjectsByProjectIdStudies: { - invalidatesTags: ['studies', 'projects'], + invalidatesTags: (_result, _error, args) => [ + { type: 'projects', id: args.projectId }, + { type: 'studies', id: 'LIST' }, + ], }, patchProjectsByProjectIdStudiesAndStudyId: { - invalidatesTags: ['studies', 'projects'], + invalidatesTags: (_result, _error, args) => [ + { type: 'projects', id: args.projectId }, + { type: 'studies', id: args.studyId }, + ], }, deleteProjectsByProjectIdStudiesAndStudyId: { - invalidatesTags: ['studies', 'projects'], + invalidatesTags: (_result, _error, args) => [ + { type: 'projects', id: args.projectId }, + { type: 'studies', id: 'LIST' }, + ], + }, + + // Scenari handling + getProjectsByProjectIdStudiesAndStudyIdScenarios: { + providesTags: (result) => [ + { type: 'scenarios', id: 'LIST' }, + ...(result?.results || []).map(({ id }) => ({ + type: 'scenarios' as const, + id, + })), + ], + }, + getProjectsByProjectIdStudiesAndStudyIdScenariosScenarioId: { + providesTags: (_result, _error, args) => [{ type: 'scenarios', id: args.scenarioId }], }, postProjectsByProjectIdStudiesAndStudyIdScenarios: { - invalidatesTags: ['scenarios', 'studies', 'projects'], + invalidatesTags: (_result, _error, args) => [ + { type: 'studies', id: args.studyId }, + { type: 'scenarios', id: 'LIST' }, + ], }, patchProjectsByProjectIdStudiesAndStudyIdScenariosScenarioId: { - invalidatesTags: ['scenarios', 'studies', 'projects'], + invalidatesTags: (_result, _error, args) => [ + { type: 'studies', id: args.studyId }, + { type: 'scenarios', id: args.scenarioId }, + ], }, deleteProjectsByProjectIdStudiesAndStudyIdScenariosScenarioId: { - invalidatesTags: ['scenarios', 'studies', 'projects'], + invalidatesTags: (_result, _error, args) => [ + { type: 'studies', id: args.studyId }, + { type: 'scenarios', id: 'LIST' }, + ], }, }, }); From 503601a78771c819009c22c9a9716007f30cf980 Mon Sep 17 00:00:00 2001 From: Clara Ni Date: Fri, 3 Jan 2025 12:32:17 +0100 Subject: [PATCH 2/2] front: fetch scenari before deleting study to avoid 404 Signed-off-by: Clara Ni --- front/src/applications/operationalStudies/views/Project.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/src/applications/operationalStudies/views/Project.tsx b/front/src/applications/operationalStudies/views/Project.tsx index 3173f6e9147..997796c2a05 100644 --- a/front/src/applications/operationalStudies/views/Project.tsx +++ b/front/src/applications/operationalStudies/views/Project.tsx @@ -94,10 +94,11 @@ const Project = () => { toggleSelection: toggleStudySelection, deleteItems, } = useMultiSelection(async (studyId) => { + const { data: scenarios } = await getScenarios({ projectId: projectId!, studyId }); + deleteStudy({ projectId: projectId!, studyId }); // For each scenario in the selected studies, clean the local storage if a manchette is saved - const { data: scenarios } = await getScenarios({ projectId: projectId!, studyId }); if (scenarios) { scenarios.results.forEach((scenario) => { cleanScenarioLocalStorage(scenario.timetable_id);