mirror of https://github.com/grafana/grafana
Alerting: use SupportedPlugin.OnCall detecting OnCall types as a single source of truth (#61473)
Use SupportedPlugin.OnCall detecting OnCall types as a single source of truthpull/61475/head^2
parent
da969e7d48
commit
fb5a033282
@ -0,0 +1,30 @@ |
|||||||
|
import { useAsync } from 'react-use'; |
||||||
|
|
||||||
|
import { PluginMeta } from '@grafana/data'; |
||||||
|
import { getPluginSettings } from 'app/features/plugins/pluginSettings'; |
||||||
|
|
||||||
|
import { PluginID } from '../components/PluginBridge'; |
||||||
|
interface PluginBridgeHookResponse { |
||||||
|
loading: boolean; |
||||||
|
installed?: boolean; |
||||||
|
error?: Error; |
||||||
|
settings?: PluginMeta<{}>; |
||||||
|
} |
||||||
|
|
||||||
|
export function usePluginBridge(plugin: PluginID): PluginBridgeHookResponse { |
||||||
|
const { loading, error, value } = useAsync(() => getPluginSettings(plugin, { showErrorAlert: false })); |
||||||
|
|
||||||
|
const installed = value && !error && !loading; |
||||||
|
const enabled = value?.enabled; |
||||||
|
const isLoading = loading && !value; |
||||||
|
|
||||||
|
if (isLoading) { |
||||||
|
return { loading: true }; |
||||||
|
} |
||||||
|
|
||||||
|
if (!installed || !enabled) { |
||||||
|
return { loading: false, installed: false }; |
||||||
|
} |
||||||
|
|
||||||
|
return { loading, installed: true, settings: value }; |
||||||
|
} |
||||||
@ -0,0 +1,5 @@ |
|||||||
|
export enum SupportedPlugin { |
||||||
|
Incident = 'grafana-incident-app', |
||||||
|
OnCall = 'grafana-oncall-app', |
||||||
|
MachineLearning = 'grafana-ml-app', |
||||||
|
} |
||||||
Loading…
Reference in new issue