mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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 AmRoutes from './AmRoutes';
|
||||||
import { fetchAlertManagerConfig, fetchStatus, updateAlertManagerConfig } from './api/alertmanager';
|
import { fetchAlertManagerConfig, fetchStatus, updateAlertManagerConfig } from './api/alertmanager';
|
||||||
import { discoverAlertmanagerFeatures } from './api/buildInfo';
|
import { discoverAlertmanagerFeatures } from './api/buildInfo';
|
||||||
|
import * as grafanaApp from './components/receivers/grafanaAppReceivers/grafanaApp';
|
||||||
import { mockDataSource, MockDataSourceSrv, someCloudAlertManagerConfig, someCloudAlertManagerStatus } from './mocks';
|
import { mockDataSource, MockDataSourceSrv, someCloudAlertManagerConfig, someCloudAlertManagerStatus } from './mocks';
|
||||||
import { defaultGroupBy } from './utils/amroutes';
|
import { defaultGroupBy } from './utils/amroutes';
|
||||||
import { getAllDataSources } from './utils/config';
|
import { getAllDataSources } from './utils/config';
|
||||||
@ -43,6 +44,7 @@ const mocks = {
|
|||||||
},
|
},
|
||||||
contextSrv: jest.mocked(contextSrv),
|
contextSrv: jest.mocked(contextSrv),
|
||||||
};
|
};
|
||||||
|
const useGetGrafanaReceiverTypeCheckerMock = jest.spyOn(grafanaApp, 'useGetGrafanaReceiverTypeChecker');
|
||||||
|
|
||||||
const renderAmRoutes = (alertManagerSourceName?: string) => {
|
const renderAmRoutes = (alertManagerSourceName?: string) => {
|
||||||
const store = configureStore();
|
const store = configureStore();
|
||||||
@ -199,6 +201,7 @@ describe('AmRoutes', () => {
|
|||||||
mocks.contextSrv.evaluatePermission.mockImplementation(() => []);
|
mocks.contextSrv.evaluatePermission.mockImplementation(() => []);
|
||||||
mocks.api.discoverAlertmanagerFeatures.mockResolvedValue({ lazyConfigInit: false });
|
mocks.api.discoverAlertmanagerFeatures.mockResolvedValue({ lazyConfigInit: false });
|
||||||
setDataSourceSrv(new MockDataSourceSrv(dataSources));
|
setDataSourceSrv(new MockDataSourceSrv(dataSources));
|
||||||
|
useGetGrafanaReceiverTypeCheckerMock.mockReturnValue(() => undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
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 { Receiver } from 'app/plugins/datasource/alertmanager/types';
|
||||||
|
|
||||||
import { useGetOnCallIntegrationsQuery } from '../../../api/onCallApi';
|
import { useGetOnCallIntegrationsQuery } from '../../../api/onCallApi';
|
||||||
|
import { SupportedPlugin, usePluginBridge } from '../../PluginBridge';
|
||||||
|
|
||||||
import { isOnCallReceiver } from './onCall/onCall';
|
import { isOnCallReceiver } from './onCall/onCall';
|
||||||
import { AmRouteReceiver, GrafanaAppReceiverEnum, GRAFANA_APP_PLUGIN_IDS, ReceiverWithTypes } from './types';
|
import { AmRouteReceiver, GrafanaAppReceiverEnum, 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';
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useGetGrafanaReceiverTypeChecker = () => {
|
export const useGetGrafanaReceiverTypeChecker = () => {
|
||||||
const isOnCallEnabled = useGetAppIsInstalledAndEnabled(GrafanaAppReceiverEnum.GRAFANA_ONCALL);
|
const { installed: isOnCallEnabled } = usePluginBridge(SupportedPlugin.OnCall);
|
||||||
const { data } = useGetOnCallIntegrationsQuery(undefined, {
|
const { data } = useGetOnCallIntegrationsQuery(undefined, {
|
||||||
skip: !isOnCallEnabled,
|
skip: !isOnCallEnabled,
|
||||||
});
|
});
|
||||||
|
|
||||||
const getGrafanaReceiverType = (receiver: Receiver): GrafanaAppReceiverEnum | undefined => {
|
const getGrafanaReceiverType = (receiver: Receiver): GrafanaAppReceiverEnum | undefined => {
|
||||||
//CHECK FOR ONCALL PLUGIN
|
//CHECK FOR ONCALL PLUGIN
|
||||||
const onCallIntegrations = data ?? [];
|
const onCallIntegrations = data ?? [];
|
||||||
|
Loading…
Reference in New Issue
Block a user