Alerting: Move alerting RTKQ client to api-clients package (#114546)
This commit is contained in:
@@ -116,6 +116,14 @@
|
||||
"import": "./dist/esm/clients/rtkq/shorturl/v1beta1/index.mjs",
|
||||
"require": "./dist/cjs/clients/rtkq/shorturl/v1beta1/index.cjs"
|
||||
},
|
||||
"./rtkq/notifications.alerting/v0alpha1": {
|
||||
"import": "./src/clients/rtkq/notifications.alerting/v0alpha1/index.ts",
|
||||
"require": "./src/clients/rtkq/notifications.alerting/v0alpha1/index.ts"
|
||||
},
|
||||
"./rtkq/rules.alerting/v0alpha1": {
|
||||
"import": "./src/clients/rtkq/rules.alerting/v0alpha1/index.ts",
|
||||
"require": "./src/clients/rtkq/rules.alerting/v0alpha1/index.ts"
|
||||
},
|
||||
"./rtkq/historian.alerting/v0alpha1": {
|
||||
"@grafana-app/source": "./src/clients/rtkq/historian.alerting/v0alpha1/index.ts",
|
||||
"types": "./dist/types/clients/rtkq/historian.alerting/v0alpha1/index.d.ts",
|
||||
|
||||
@@ -10,10 +10,12 @@ import { generatedAPI as historianAlertingAPIv0alpha1 } from './historian.alerti
|
||||
import { generatedAPI as iamAPIv0alpha1 } from './iam/v0alpha1';
|
||||
import { generatedAPI as logsdrilldownAPIv1alpha1 } from './logsdrilldown/v1alpha1';
|
||||
import { generatedAPI as migrateToCloudAPI } from './migrate-to-cloud';
|
||||
import { generatedAPI as notificationsAlertingAPIv0alpha1 } from './notifications.alerting/v0alpha1';
|
||||
import { generatedAPI as playlistAPIv0alpha1 } from './playlist/v0alpha1';
|
||||
import { generatedAPI as preferencesUserAPI } from './preferences/user';
|
||||
import { generatedAPI as preferencesAPIv1alpha1 } from './preferences/v1alpha1';
|
||||
import { generatedAPI as provisioningAPIv0alpha1 } from './provisioning/v0alpha1';
|
||||
import { generatedAPI as rulesAlertingAPIv0alpha1 } from './rules.alerting/v0alpha1';
|
||||
import { generatedAPI as shortURLAPIv1beta1 } from './shorturl/v1beta1';
|
||||
import { generatedAPI as legacyUserAPI } from './user';
|
||||
// PLOP_INJECT_IMPORT
|
||||
@@ -33,6 +35,8 @@ export const allMiddleware = [
|
||||
shortURLAPIv1beta1.middleware,
|
||||
correlationsAPIv0alpha1.middleware,
|
||||
legacyUserAPI.middleware,
|
||||
notificationsAlertingAPIv0alpha1.middleware,
|
||||
rulesAlertingAPIv0alpha1.middleware,
|
||||
historianAlertingAPIv0alpha1.middleware,
|
||||
logsdrilldownAPIv1alpha1.middleware,
|
||||
// PLOP_INJECT_MIDDLEWARE
|
||||
@@ -53,6 +57,8 @@ export const allReducers = {
|
||||
[shortURLAPIv1beta1.reducerPath]: shortURLAPIv1beta1.reducer,
|
||||
[correlationsAPIv0alpha1.reducerPath]: correlationsAPIv0alpha1.reducer,
|
||||
[legacyUserAPI.reducerPath]: legacyUserAPI.reducer,
|
||||
[notificationsAlertingAPIv0alpha1.reducerPath]: notificationsAlertingAPIv0alpha1.reducer,
|
||||
[rulesAlertingAPIv0alpha1.reducerPath]: rulesAlertingAPIv0alpha1.reducer,
|
||||
[historianAlertingAPIv0alpha1.reducerPath]: historianAlertingAPIv0alpha1.reducer,
|
||||
[logsdrilldownAPIv1alpha1.reducerPath]: logsdrilldownAPIv1alpha1.reducer,
|
||||
// PLOP_INJECT_REDUCER
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { getAPIBaseURL } from '../../../../utils/utils';
|
||||
import { createBaseQuery } from '../../createBaseQuery';
|
||||
|
||||
export const API_GROUP = 'notifications.alerting.grafana.app' as const;
|
||||
export const API_VERSION = 'v0alpha1' as const;
|
||||
export const BASE_URL = getAPIBaseURL(API_GROUP, API_VERSION);
|
||||
|
||||
export const api = createApi({
|
||||
reducerPath: 'notificationsAlertingAPIv0alpha1',
|
||||
baseQuery: createBaseQuery({
|
||||
baseURL: BASE_URL,
|
||||
}),
|
||||
endpoints: () => ({}),
|
||||
});
|
||||
Generated
+1468
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
export { BASE_URL, API_GROUP, API_VERSION } from './baseAPI';
|
||||
import { generatedAPI as rawAPI } from './endpoints.gen';
|
||||
|
||||
export * from './endpoints.gen';
|
||||
export const generatedAPI = rawAPI.enhanceEndpoints({});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { getAPIBaseURL } from '../../../../utils/utils';
|
||||
import { createBaseQuery } from '../../createBaseQuery';
|
||||
|
||||
export const API_GROUP = 'rules.alerting.grafana.app' as const;
|
||||
export const API_VERSION = 'v0alpha1' as const;
|
||||
export const BASE_URL = getAPIBaseURL(API_GROUP, API_VERSION);
|
||||
|
||||
export const api = createApi({
|
||||
reducerPath: 'rulesAlertingAPIv0alpha1',
|
||||
baseQuery: createBaseQuery({
|
||||
baseURL: BASE_URL,
|
||||
}),
|
||||
endpoints: () => ({}),
|
||||
});
|
||||
+1117
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
export { BASE_URL, API_GROUP, API_VERSION } from './baseAPI';
|
||||
import { generatedAPI as rawAPI } from './endpoints.gen';
|
||||
|
||||
export * from './endpoints.gen';
|
||||
export const generatedAPI = rawAPI.enhanceEndpoints({});
|
||||
@@ -1 +1,4 @@
|
||||
export { getAPINamespace, getAPIBaseURL, normalizeError, handleRequestError } from './utils/utils';
|
||||
|
||||
/* @TODO figure out how to automatically set the MockBackendSrv when consumers of this package write tests using the exported clients */
|
||||
export { MockBackendSrv } from './utils/backendSrv.mock';
|
||||
|
||||
@@ -108,6 +108,8 @@ const config: ConfigFile = {
|
||||
...createAPIConfig('preferences', 'v1alpha1'),
|
||||
...createAPIConfig('provisioning', 'v0alpha1'),
|
||||
...createAPIConfig('shorturl', 'v1beta1'),
|
||||
...createAPIConfig('notifications.alerting', 'v0alpha1'),
|
||||
...createAPIConfig('rules.alerting', 'v0alpha1'),
|
||||
...createAPIConfig('historian.alerting', 'v0alpha1'),
|
||||
...createAPIConfig('logsdrilldown', 'v1alpha1'),
|
||||
// PLOP_INJECT_API_CLIENT - Used by the API client generator
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { fromFetch } from 'rxjs/fetch';
|
||||
|
||||
import { BackendSrv, BackendSrvRequest, FetchResponse } from '@grafana/runtime';
|
||||
|
||||
/**
|
||||
* Minimal mock implementation of BackendSrv for testing.
|
||||
* Only implements the fetch() method which is used by RTKQ.
|
||||
* HTTP requests are intercepted by MSW in tests.
|
||||
*/
|
||||
export class MockBackendSrv implements Partial<BackendSrv> {
|
||||
fetch<T>(options: BackendSrvRequest): Observable<FetchResponse<T>> {
|
||||
const init: RequestInit = {
|
||||
method: options.method || 'GET',
|
||||
headers: options.headers,
|
||||
body: options.data ? JSON.stringify(options.data) : undefined,
|
||||
credentials: options.credentials,
|
||||
signal: options.abortSignal,
|
||||
};
|
||||
|
||||
return new Observable((observer) => {
|
||||
fromFetch(options.url, init).subscribe({
|
||||
next: async (response) => {
|
||||
try {
|
||||
const data = await response.json();
|
||||
observer.next({
|
||||
data,
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
ok: response.ok,
|
||||
headers: response.headers,
|
||||
redirected: response.redirected,
|
||||
type: response.type,
|
||||
url: response.url,
|
||||
config: options,
|
||||
});
|
||||
observer.complete();
|
||||
} catch (error) {
|
||||
observer.error(error);
|
||||
}
|
||||
},
|
||||
error: (error) => observer.error(error),
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user