Skip to content

Commit

Permalink
feat: add tags to dashboard api to manage api refresh calls
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault committed Oct 24, 2024
1 parent 3356329 commit 27332e0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions frontend/src/api/dashboardsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,28 @@ const GET_DASHBOARD_ERROR_MESSAGE = "Nous n'avons pas pu récupérer le tableau
export const dashboardsAPI = monitorenvPrivateApi.injectEndpoints({
endpoints: build => ({
getDashboard: build.query<Dashboard.DashboardFromApi, string>({
providesTags: (_, __, id) => [{ id, type: 'Dashboards' }],
query: id => `/v1/dashboards/${id}`,
transformErrorResponse: response => new FrontendApiError(GET_DASHBOARD_ERROR_MESSAGE, response),
transformResponse: (response: Dashboard.DashboardFromApi) => response
}),
getDashboards: build.query<Dashboard.Dashboard[], void>({
getDashboards: build.query<Dashboard.DashboardFromApi[], void>({
providesTags: result =>
result
? // successful query
[...result.map(({ id }) => ({ id, type: 'Dashboards' as const })), { id: 'LIST', type: 'Dashboards' }]
: // an error occurred, but we still want to refetch this query when `{ type: 'Missions', id: 'LIST' }` is invalidated
[{ id: 'LIST', type: 'Dashboards' }],
query: () => '/v1/dashboards',
transformErrorResponse: response => new FrontendApiError(GET_DASHBOARDS_ERROR_MESSAGE, response),
transformResponse: (response: Dashboard.Dashboard[]) => response
transformResponse: (response: Dashboard.DashboardFromApi[]) => response
}),
getExtratedArea: build.query<Dashboard.ExtractedAreaFromApi, GeoJSON.Geometry>({
query: geometry => `/v1/dashboards/extract?geometry=${geoJsonToWKT(geometry)}`,
transformErrorResponse: response => new FrontendApiError(GET_EXTRACTED_AREAS_ERROR_MESSAGE, response)
}),
save: build.query<Dashboard.DashboardFromApi, Dashboard.DashboardToApi>({
save: build.mutation<Dashboard.DashboardFromApi, Dashboard.DashboardToApi>({
invalidatesTags: (_, __, { id }) => [{ id, type: 'Dashboards' }],
query: mission => ({
body: mission,
method: 'PUT',
Expand Down

0 comments on commit 27332e0

Please sign in to comment.