forked from grafana.jool/grafana-jool
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
776 B
16 lines
776 B
import { RulesSource } from 'app/types/unified-alerting';
|
|
import { useCallback } from 'react';
|
|
import { GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource';
|
|
import { useUnifiedAlertingSelector } from './useUnifiedAlertingSelector';
|
|
|
|
// datasource has ruler if it's grafana managed or if we're able to load rules from it
|
|
export function useHasRuler(): (rulesSource: string | RulesSource) => boolean {
|
|
const rulerRules = useUnifiedAlertingSelector((state) => state.rulerRules);
|
|
return useCallback(
|
|
(rulesSource: string | RulesSource) => {
|
|
const rulesSourceName = typeof rulesSource === 'string' ? rulesSource : rulesSource.name;
|
|
return rulesSourceName === GRAFANA_RULES_SOURCE_NAME || !!rulerRules[rulesSourceName]?.result;
|
|
},
|
|
[rulerRules]
|
|
);
|
|
}
|
|
|