mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
Alerting: Use pluginBridge to check if plugin is installed (#61356)
* Use getPluginSettings (/api/plugins//settings) to check if plugin is installed * Use usePluginBridge hook instead of getPluginSettings to check if plugin is installed
This commit is contained in:
parent
ddb85ad6ad
commit
24c3c3a0ef
@ -21,6 +21,7 @@ import { AccessControlAction } from 'app/types';
|
||||
import AmRoutes from './AmRoutes';
|
||||
import { fetchAlertManagerConfig, fetchStatus, updateAlertManagerConfig } from './api/alertmanager';
|
||||
import { discoverAlertmanagerFeatures } from './api/buildInfo';
|
||||
import * as grafanaApp from './components/receivers/grafanaAppReceivers/grafanaApp';
|
||||
import { mockDataSource, MockDataSourceSrv, someCloudAlertManagerConfig, someCloudAlertManagerStatus } from './mocks';
|
||||
import { defaultGroupBy } from './utils/amroutes';
|
||||
import { getAllDataSources } from './utils/config';
|
||||
@ -43,6 +44,7 @@ const mocks = {
|
||||
},
|
||||
contextSrv: jest.mocked(contextSrv),
|
||||
};
|
||||
const useGetGrafanaReceiverTypeCheckerMock = jest.spyOn(grafanaApp, 'useGetGrafanaReceiverTypeChecker');
|
||||
|
||||
const renderAmRoutes = (alertManagerSourceName?: string) => {
|
||||
const store = configureStore();
|
||||
@ -199,6 +201,7 @@ describe('AmRoutes', () => {
|
||||
mocks.contextSrv.evaluatePermission.mockImplementation(() => []);
|
||||
mocks.api.discoverAlertmanagerFeatures.mockResolvedValue({ lazyConfigInit: false });
|
||||
setDataSourceSrv(new MockDataSourceSrv(dataSources));
|
||||
useGetGrafanaReceiverTypeCheckerMock.mockReturnValue(() => undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -1,24 +1,16 @@
|
||||
import { useGetSingleLocalWithoutDetails } from 'app/features/plugins/admin/state/hooks';
|
||||
import { CatalogPlugin } from 'app/features/plugins/admin/types';
|
||||
import { Receiver } from 'app/plugins/datasource/alertmanager/types';
|
||||
|
||||
import { useGetOnCallIntegrationsQuery } from '../../../api/onCallApi';
|
||||
import { SupportedPlugin, usePluginBridge } from '../../PluginBridge';
|
||||
|
||||
import { isOnCallReceiver } from './onCall/onCall';
|
||||
import { AmRouteReceiver, GrafanaAppReceiverEnum, GRAFANA_APP_PLUGIN_IDS, ReceiverWithTypes } from './types';
|
||||
|
||||
export const useGetAppIsInstalledAndEnabled = (grafanaAppType: GrafanaAppReceiverEnum) => {
|
||||
// fetches the plugin settings for this Grafana instance
|
||||
const plugin: CatalogPlugin | undefined = useGetSingleLocalWithoutDetails(GRAFANA_APP_PLUGIN_IDS[grafanaAppType]);
|
||||
return plugin?.isInstalled && !plugin?.isDisabled && plugin?.type === 'app';
|
||||
};
|
||||
import { AmRouteReceiver, GrafanaAppReceiverEnum, ReceiverWithTypes } from './types';
|
||||
|
||||
export const useGetGrafanaReceiverTypeChecker = () => {
|
||||
const isOnCallEnabled = useGetAppIsInstalledAndEnabled(GrafanaAppReceiverEnum.GRAFANA_ONCALL);
|
||||
const { installed: isOnCallEnabled } = usePluginBridge(SupportedPlugin.OnCall);
|
||||
const { data } = useGetOnCallIntegrationsQuery(undefined, {
|
||||
skip: !isOnCallEnabled,
|
||||
});
|
||||
|
||||
const getGrafanaReceiverType = (receiver: Receiver): GrafanaAppReceiverEnum | undefined => {
|
||||
//CHECK FOR ONCALL PLUGIN
|
||||
const onCallIntegrations = data ?? [];
|
||||
|
Loading…
Reference in New Issue
Block a user