mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* mobx: poc in using each store as individual prop on the react containers * prettier test * fix: end the war between prettier vs tslint. * mobx: Move stores into their own folders * mobx: Refactor the AlertRule into its own file and add a helper-file * mobx: Move NavItem out of NavStore and remove lodash dependancy * mobx: Move ResultItem and SearchResultSection models out of the SearchStore * mobx: ServerStatsStore rename .tsx => .ts. And move ServerStat-model to its own file. * mobx: Remove lodash and jquery dependancy from ViewStore * mobx: Remove issue with double question mark
35 lines
982 B
TypeScript
35 lines
982 B
TypeScript
import { types, getEnv, flow } from 'mobx-state-tree';
|
|
import { setStateFields } from './helpers';
|
|
|
|
export const AlertRule = types
|
|
.model('AlertRule', {
|
|
id: types.identifier(types.number),
|
|
dashboardId: types.number,
|
|
panelId: types.number,
|
|
name: types.string,
|
|
state: types.string,
|
|
stateText: types.string,
|
|
stateIcon: types.string,
|
|
stateClass: types.string,
|
|
stateAge: types.string,
|
|
info: types.optional(types.string, ''),
|
|
dashboardUri: types.string,
|
|
})
|
|
.views(self => ({
|
|
get isPaused() {
|
|
return self.state === 'paused';
|
|
},
|
|
}))
|
|
.actions(self => ({
|
|
/**
|
|
* will toggle alert rule paused state
|
|
*/
|
|
togglePaused: flow(function* togglePaused() {
|
|
const backendSrv = getEnv(self).backendSrv;
|
|
const payload = { paused: self.isPaused };
|
|
const res = yield backendSrv.post(`/api/alerts/${self.id}/pause`, payload);
|
|
setStateFields(self, res.state);
|
|
self.info = '';
|
|
}),
|
|
}));
|