mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
27 lines
705 B
TypeScript
27 lines
705 B
TypeScript
|
import { Dispatch } from 'redux';
|
||
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
||
|
import { AlertRule } from 'app/types';
|
||
|
|
||
|
export interface LoadAlertRulesAction {
|
||
|
type: 'LOAD_ALERT_RULES';
|
||
|
payload: AlertRule[];
|
||
|
}
|
||
|
|
||
|
export const loadAlertRules = (rules: AlertRule[]): LoadAlertRulesAction => ({
|
||
|
type: 'LOAD_ALERT_RULES',
|
||
|
payload: rules,
|
||
|
});
|
||
|
|
||
|
export type Action = LoadAlertRulesAction;
|
||
|
|
||
|
export const getAlertRulesAsync = () => async (dispatch: Dispatch<Action>): Promise<AlertRule[]> => {
|
||
|
try {
|
||
|
const rules = await getBackendSrv().get('/api/alerts', {});
|
||
|
dispatch(loadAlertRules(rules));
|
||
|
return rules;
|
||
|
} catch (error) {
|
||
|
console.error(error);
|
||
|
throw error;
|
||
|
}
|
||
|
};
|