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

front: remove useless requests when deleting projects, studies, scenari #10091

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ const Project = () => {
toggleSelection: toggleStudySelection,
deleteItems,
} = useMultiSelection<StudyWithScenarios>(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);
Expand Down
82 changes: 75 additions & 7 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
],
},
},
});
Expand Down
Loading