mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* creating types, actions, reducer * load teams and store in redux * delete team * set search query action and tests * Teampages page * team members, bug in fetching team * flattened team state, tests for TeamMembers * test for team member selector * team settings * actions for group sync * tests for team groups * removed comment * remove old stores * fix: formating of datasource.go * fix: minor changes to imports * adding debounce and fixing issue in teamlist * refactoring: moving types to their own files
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
import { AlertRuleDTO, StoreState } from 'app/types';
|
|
import { ThunkAction } from 'redux-thunk';
|
|
|
|
export enum ActionTypes {
|
|
LoadAlertRules = 'LOAD_ALERT_RULES',
|
|
SetSearchQuery = 'SET_ALERT_SEARCH_QUERY',
|
|
}
|
|
|
|
export interface LoadAlertRulesAction {
|
|
type: ActionTypes.LoadAlertRules;
|
|
payload: AlertRuleDTO[];
|
|
}
|
|
|
|
export interface SetSearchQueryAction {
|
|
type: ActionTypes.SetSearchQuery;
|
|
payload: string;
|
|
}
|
|
|
|
export const loadAlertRules = (rules: AlertRuleDTO[]): LoadAlertRulesAction => ({
|
|
type: ActionTypes.LoadAlertRules,
|
|
payload: rules,
|
|
});
|
|
|
|
export const setSearchQuery = (query: string): SetSearchQueryAction => ({
|
|
type: ActionTypes.SetSearchQuery,
|
|
payload: query,
|
|
});
|
|
|
|
export type Action = LoadAlertRulesAction | SetSearchQueryAction;
|
|
|
|
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
|
|
|
|
export function getAlertRulesAsync(options: { state: string }): ThunkResult<void> {
|
|
return async dispatch => {
|
|
const rules = await getBackendSrv().get('/api/alerts', options);
|
|
dispatch(loadAlertRules(rules));
|
|
};
|
|
}
|
|
|
|
export function togglePauseAlertRule(id: number, options: { paused: boolean }): ThunkResult<void> {
|
|
return async (dispatch, getState) => {
|
|
await getBackendSrv().post(`/api/alerts/${id}/pause`, options);
|
|
const stateFilter = getState().location.query.state || 'all';
|
|
dispatch(getAlertRulesAsync({ state: stateFilter.toString() }));
|
|
};
|
|
}
|