Files
grafana/public/app/features/migrate-to-cloud/api/index.ts
Josh Hunt 7448f22f91 E2C: Create Snapshot frontend (#89901)
* First pass at using new async apis

* async api tweaks

* clean up async api usage

* Update public/app/features/migrate-to-cloud/onprem/Page.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Update public/app/features/migrate-to-cloud/onprem/Page.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* fix syntax

---------

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
2024-07-03 11:42:00 +01:00

66 lines
1.7 KiB
TypeScript

export * from './endpoints.gen';
import { BaseQueryFn, EndpointDefinition } from '@reduxjs/toolkit/dist/query';
import { generatedAPI } from './endpoints.gen';
export const cloudMigrationAPI = generatedAPI.enhanceEndpoints({
addTagTypes: ['cloud-migration-session', 'cloud-migration-snapshot'],
endpoints: {
// Cloud-side - create token
createCloudMigrationToken: suppressErrorsOnQuery,
// List Cloud Configs
getSessionList: {
providesTags: ['cloud-migration-session'] /* should this be a -list? */,
},
// Create Cloud Config
createSession(endpoint) {
suppressErrorsOnQuery(endpoint);
endpoint.invalidatesTags = ['cloud-migration-session'];
},
// Get one Cloud Config
getSession: {
providesTags: ['cloud-migration-session'],
},
// Delete one Cloud Config
deleteSession: {
invalidatesTags: ['cloud-migration-session', 'cloud-migration-snapshot'],
},
// Snapshot management
getSnapshot: {
providesTags: ['cloud-migration-snapshot'],
},
getShapshotList: {
providesTags: ['cloud-migration-snapshot'],
},
createSnapshot: {
invalidatesTags: ['cloud-migration-snapshot'],
},
uploadSnapshot: {
invalidatesTags: ['cloud-migration-snapshot'],
},
getDashboardByUid: suppressErrorsOnQuery,
},
});
function suppressErrorsOnQuery<QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType>(
endpoint: EndpointDefinition<QueryArg, BaseQuery, TagTypes, ResultType>
) {
if (!endpoint.query) {
return;
}
const originalQuery = endpoint.query;
endpoint.query = (...args) => {
const baseQuery = originalQuery(...args);
baseQuery.showErrorAlert = false;
return baseQuery;
};
}