mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
refactor: changed AlertRuleItem pause action to callback
This commit is contained in:
parent
a440d3510a
commit
6bdaf57ae7
@ -21,7 +21,7 @@ const setup = (propOverrides?: object) => {
|
|||||||
url: 'https://something.something.darkside',
|
url: 'https://something.something.darkside',
|
||||||
},
|
},
|
||||||
search: '',
|
search: '',
|
||||||
togglePauseAlertRule: jest.fn(),
|
onTogglePause: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(props, propOverrides);
|
Object.assign(props, propOverrides);
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import Highlighter from 'react-highlight-words';
|
import Highlighter from 'react-highlight-words';
|
||||||
import classNames from 'classnames/bind';
|
import classNames from 'classnames/bind';
|
||||||
import { togglePauseAlertRule } from './state/actions';
|
|
||||||
import { AlertRule } from '../../types';
|
import { AlertRule } from '../../types';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
rule: AlertRule;
|
rule: AlertRule;
|
||||||
search: string;
|
search: string;
|
||||||
togglePauseAlertRule: typeof togglePauseAlertRule;
|
onTogglePause: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AlertRuleItem extends PureComponent<Props, any> {
|
class AlertRuleItem extends PureComponent<Props> {
|
||||||
togglePaused = () => {
|
|
||||||
const { rule } = this.props;
|
|
||||||
|
|
||||||
this.props.togglePauseAlertRule(rule.id, { paused: rule.state !== 'paused' });
|
|
||||||
};
|
|
||||||
|
|
||||||
renderText(text: string) {
|
renderText(text: string) {
|
||||||
return (
|
return (
|
||||||
<Highlighter
|
<Highlighter
|
||||||
@ -29,7 +21,7 @@ class AlertRuleItem extends PureComponent<Props, any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { rule } = this.props;
|
const { rule, onTogglePause } = this.props;
|
||||||
|
|
||||||
const stateClass = classNames({
|
const stateClass = classNames({
|
||||||
fa: true,
|
fa: true,
|
||||||
@ -61,7 +53,7 @@ class AlertRuleItem extends PureComponent<Props, any> {
|
|||||||
<button
|
<button
|
||||||
className="btn btn-small btn-inverse alert-list__btn width-2"
|
className="btn btn-small btn-inverse alert-list__btn width-2"
|
||||||
title="Pausing an alert rule prevents it from executing"
|
title="Pausing an alert rule prevents it from executing"
|
||||||
onClick={this.togglePaused}
|
onClick={onTogglePause}
|
||||||
>
|
>
|
||||||
<i className={stateClass} />
|
<i className={stateClass} />
|
||||||
</button>
|
</button>
|
||||||
@ -74,6 +66,4 @@ class AlertRuleItem extends PureComponent<Props, any> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(null, {
|
export default AlertRuleItem;
|
||||||
togglePauseAlertRule,
|
|
||||||
})(AlertRuleItem);
|
|
||||||
|
@ -15,6 +15,7 @@ const setup = (propOverrides?: object) => {
|
|||||||
updateLocation: jest.fn(),
|
updateLocation: jest.fn(),
|
||||||
getAlertRulesAsync: jest.fn(),
|
getAlertRulesAsync: jest.fn(),
|
||||||
setSearchQuery: jest.fn(),
|
setSearchQuery: jest.fn(),
|
||||||
|
togglePauseAlertRule: jest.fn(),
|
||||||
stateFilter: '',
|
stateFilter: '',
|
||||||
search: '',
|
search: '',
|
||||||
};
|
};
|
||||||
|
@ -7,7 +7,7 @@ import appEvents from 'app/core/app_events';
|
|||||||
import { updateLocation } from 'app/core/actions';
|
import { updateLocation } from 'app/core/actions';
|
||||||
import { getNavModel } from 'app/core/selectors/navModel';
|
import { getNavModel } from 'app/core/selectors/navModel';
|
||||||
import { NavModel, StoreState, AlertRule } from 'app/types';
|
import { NavModel, StoreState, AlertRule } from 'app/types';
|
||||||
import { getAlertRulesAsync, setSearchQuery } from './state/actions';
|
import { getAlertRulesAsync, setSearchQuery, togglePauseAlertRule } from './state/actions';
|
||||||
import { getAlertRuleItems, getSearchQuery } from './state/selectors';
|
import { getAlertRuleItems, getSearchQuery } from './state/selectors';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
@ -16,6 +16,7 @@ export interface Props {
|
|||||||
updateLocation: typeof updateLocation;
|
updateLocation: typeof updateLocation;
|
||||||
getAlertRulesAsync: typeof getAlertRulesAsync;
|
getAlertRulesAsync: typeof getAlertRulesAsync;
|
||||||
setSearchQuery: typeof setSearchQuery;
|
setSearchQuery: typeof setSearchQuery;
|
||||||
|
togglePauseAlertRule: typeof togglePauseAlertRule;
|
||||||
stateFilter: string;
|
stateFilter: string;
|
||||||
search: string;
|
search: string;
|
||||||
}
|
}
|
||||||
@ -71,6 +72,10 @@ export class AlertRuleList extends PureComponent<Props, any> {
|
|||||||
this.props.setSearchQuery(value);
|
this.props.setSearchQuery(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onTogglePause = (rule: AlertRule) => {
|
||||||
|
this.props.togglePauseAlertRule(rule.id, { paused: rule.state !== 'paused' });
|
||||||
|
};
|
||||||
|
|
||||||
alertStateFilterOption = ({ text, value }) => {
|
alertStateFilterOption = ({ text, value }) => {
|
||||||
return (
|
return (
|
||||||
<option key={value} value={value}>
|
<option key={value} value={value}>
|
||||||
@ -115,7 +120,14 @@ export class AlertRuleList extends PureComponent<Props, any> {
|
|||||||
</div>
|
</div>
|
||||||
<section>
|
<section>
|
||||||
<ol className="alert-rule-list">
|
<ol className="alert-rule-list">
|
||||||
{alertRules.map(rule => <AlertRuleItem rule={rule} key={rule.id} search={search} />)}
|
{alertRules.map(rule => (
|
||||||
|
<AlertRuleItem
|
||||||
|
rule={rule}
|
||||||
|
key={rule.id}
|
||||||
|
search={search}
|
||||||
|
onTogglePause={() => this.onTogglePause(rule)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</ol>
|
</ol>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
@ -135,6 +147,7 @@ const mapDispatchToProps = {
|
|||||||
updateLocation,
|
updateLocation,
|
||||||
getAlertRulesAsync,
|
getAlertRulesAsync,
|
||||||
setSearchQuery,
|
setSearchQuery,
|
||||||
|
togglePauseAlertRule,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(AlertRuleList));
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(AlertRuleList));
|
||||||
|
@ -64,7 +64,7 @@ exports[`Render should render component 1`] = `
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="btn btn-small btn-inverse alert-list__btn width-2"
|
className="btn btn-small btn-inverse alert-list__btn width-2"
|
||||||
onClick={[Function]}
|
onClick={[MockFunction]}
|
||||||
title="Pausing an alert rule prevents it from executing"
|
title="Pausing an alert rule prevents it from executing"
|
||||||
>
|
>
|
||||||
<i
|
<i
|
||||||
|
@ -101,8 +101,9 @@ exports[`Render should render alert rules 1`] = `
|
|||||||
<ol
|
<ol
|
||||||
className="alert-rule-list"
|
className="alert-rule-list"
|
||||||
>
|
>
|
||||||
<Connect(AlertRuleItem)
|
<AlertRuleItem
|
||||||
key="1"
|
key="1"
|
||||||
|
onTogglePause={[Function]}
|
||||||
rule={
|
rule={
|
||||||
Object {
|
Object {
|
||||||
"dashboardId": 7,
|
"dashboardId": 7,
|
||||||
@ -121,8 +122,9 @@ exports[`Render should render alert rules 1`] = `
|
|||||||
}
|
}
|
||||||
search=""
|
search=""
|
||||||
/>
|
/>
|
||||||
<Connect(AlertRuleItem)
|
<AlertRuleItem
|
||||||
key="3"
|
key="3"
|
||||||
|
onTogglePause={[Function]}
|
||||||
rule={
|
rule={
|
||||||
Object {
|
Object {
|
||||||
"dashboardId": 7,
|
"dashboardId": 7,
|
||||||
|
Loading…
Reference in New Issue
Block a user