mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
redux: minor changes to redux thunk actions and use of typings
This commit is contained in:
parent
41dcd7641b
commit
1e5ad4da78
@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import AlertRuleList, { Props } from './AlertRuleList';
|
import { AlertRuleList, Props } from './AlertRuleList';
|
||||||
import { AlertRule, NavModel } from '../../types';
|
import { AlertRule, NavModel } from '../../types';
|
||||||
import appEvents from '../../core/app_events';
|
import appEvents from '../../core/app_events';
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ export interface Props {
|
|||||||
search: string;
|
search: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AlertRuleList extends PureComponent<Props, any> {
|
export class AlertRuleList extends PureComponent<Props, any> {
|
||||||
stateFilters = [
|
stateFilters = [
|
||||||
{ text: 'All', value: 'all' },
|
{ text: 'All', value: 'all' },
|
||||||
{ text: 'OK', value: 'ok' },
|
{ text: 'OK', value: 'ok' },
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Dispatch } from 'redux';
|
|
||||||
import { getBackendSrv } from 'app/core/services/backend_srv';
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
||||||
import { AlertRuleApi, StoreState } from 'app/types';
|
import { AlertRuleApi, StoreState } from 'app/types';
|
||||||
|
import { ThunkAction } from 'redux-thunk';
|
||||||
|
|
||||||
export enum ActionTypes {
|
export enum ActionTypes {
|
||||||
LoadAlertRules = 'LOAD_ALERT_RULES',
|
LoadAlertRules = 'LOAD_ALERT_RULES',
|
||||||
@ -29,31 +29,19 @@ export const setSearchQuery = (query: string): SetSearchQueryAction => ({
|
|||||||
|
|
||||||
export type Action = LoadAlertRulesAction | SetSearchQueryAction;
|
export type Action = LoadAlertRulesAction | SetSearchQueryAction;
|
||||||
|
|
||||||
export const getAlertRulesAsync = (options: { state: string }) => async (
|
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
|
||||||
dispatch: Dispatch<Action>
|
|
||||||
): Promise<AlertRuleApi[]> => {
|
export function getAlertRulesAsync(options: { state: string }): ThunkResult<void> {
|
||||||
try {
|
return async dispatch => {
|
||||||
const rules = await getBackendSrv().get('/api/alerts', options);
|
const rules = await getBackendSrv().get('/api/alerts', options);
|
||||||
dispatch(loadAlertRules(rules));
|
dispatch(loadAlertRules(rules));
|
||||||
return rules;
|
};
|
||||||
} catch (error) {
|
}
|
||||||
console.error(error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const togglePauseAlertRule = (id: number, options: { paused: boolean }) => async (
|
export function togglePauseAlertRule(id: number, options: { paused: boolean }): ThunkResult<void> {
|
||||||
// Maybe fix dispatch type?
|
return async (dispatch, getState) => {
|
||||||
dispatch: Dispatch<any>,
|
|
||||||
getState: () => StoreState
|
|
||||||
): Promise<boolean> => {
|
|
||||||
try {
|
|
||||||
await getBackendSrv().post(`/api/alerts/${id}/pause`, options);
|
await getBackendSrv().post(`/api/alerts/${id}/pause`, options);
|
||||||
const stateFilter = getState().location.query.state || 'all';
|
const stateFilter = getState().location.query.state || 'all';
|
||||||
dispatch(getAlertRulesAsync({ state: stateFilter.toString() }));
|
dispatch(getAlertRulesAsync({ state: stateFilter.toString() }));
|
||||||
return true;
|
};
|
||||||
} catch (error) {
|
}
|
||||||
console.log(error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user