diff --git a/public/app/features/alerting/AlertRuleList.test.tsx b/public/app/features/alerting/AlertRuleList.test.tsx index 9bcdcd41a3b..3c0c410d1a9 100644 --- a/public/app/features/alerting/AlertRuleList.test.tsx +++ b/public/app/features/alerting/AlertRuleList.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { shallow } from 'enzyme'; -import AlertRuleList, { Props } from './AlertRuleList'; +import { AlertRuleList, Props } from './AlertRuleList'; import { AlertRule, NavModel } from '../../types'; import appEvents from '../../core/app_events'; diff --git a/public/app/features/alerting/AlertRuleList.tsx b/public/app/features/alerting/AlertRuleList.tsx index e8458e72f11..4b48da47256 100644 --- a/public/app/features/alerting/AlertRuleList.tsx +++ b/public/app/features/alerting/AlertRuleList.tsx @@ -20,7 +20,7 @@ export interface Props { search: string; } -class AlertRuleList extends PureComponent { +export class AlertRuleList extends PureComponent { stateFilters = [ { text: 'All', value: 'all' }, { text: 'OK', value: 'ok' }, diff --git a/public/app/features/alerting/state/actions.ts b/public/app/features/alerting/state/actions.ts index 2dff257685f..ca50d9e1038 100644 --- a/public/app/features/alerting/state/actions.ts +++ b/public/app/features/alerting/state/actions.ts @@ -1,6 +1,6 @@ -import { Dispatch } from 'redux'; import { getBackendSrv } from 'app/core/services/backend_srv'; import { AlertRuleApi, StoreState } from 'app/types'; +import { ThunkAction } from 'redux-thunk'; export enum ActionTypes { LoadAlertRules = 'LOAD_ALERT_RULES', @@ -29,31 +29,19 @@ export const setSearchQuery = (query: string): SetSearchQueryAction => ({ export type Action = LoadAlertRulesAction | SetSearchQueryAction; -export const getAlertRulesAsync = (options: { state: string }) => async ( - dispatch: Dispatch -): Promise => { - try { +type ThunkResult = ThunkAction; + +export function getAlertRulesAsync(options: { state: string }): ThunkResult { + return async dispatch => { const rules = await getBackendSrv().get('/api/alerts', options); dispatch(loadAlertRules(rules)); - return rules; - } catch (error) { - console.error(error); - throw error; - } -}; + }; +} -export const togglePauseAlertRule = (id: number, options: { paused: boolean }) => async ( - // Maybe fix dispatch type? - dispatch: Dispatch, - getState: () => StoreState -): Promise => { - try { +export function togglePauseAlertRule(id: number, options: { paused: boolean }): ThunkResult { + return async (dispatch, getState) => { await getBackendSrv().post(`/api/alerts/${id}/pause`, options); const stateFilter = getState().location.query.state || 'all'; dispatch(getAlertRulesAsync({ state: stateFilter.toString() })); - return true; - } catch (error) { - console.log(error); - throw error; - } -}; + }; +}