Change rule status
parent
ffd743a1b0
commit
1b7a056428
|
@ -9,6 +9,7 @@ import {
|
||||||
updateAlerts,
|
updateAlerts,
|
||||||
updateRuleName,
|
updateRuleName,
|
||||||
deleteRuleSuccess,
|
deleteRuleSuccess,
|
||||||
|
updateRuleStatusSuccess,
|
||||||
} from 'src/kapacitor/actions/view';
|
} from 'src/kapacitor/actions/view';
|
||||||
|
|
||||||
describe('Kapacitor.Reducers.rules', () => {
|
describe('Kapacitor.Reducers.rules', () => {
|
||||||
|
@ -134,4 +135,20 @@ describe('Kapacitor.Reducers.rules', () => {
|
||||||
const newState = reducer(initialState, updateDetails(ruleID, details));
|
const newState = reducer(initialState, updateDetails(ruleID, details));
|
||||||
expect(newState[ruleID].details).to.equal(details);
|
expect(newState[ruleID].details).to.equal(details);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can update status', () => {
|
||||||
|
const ruleID = 1;
|
||||||
|
const status = 'enabled';
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
[ruleID]: {
|
||||||
|
id: ruleID,
|
||||||
|
queryID: 988,
|
||||||
|
status: 'disabled',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const newState = reducer(initialState, updateRuleStatusSuccess(ruleID, status));
|
||||||
|
expect(newState[ruleID].status).to.equal(status);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import uuid from 'node-uuid';
|
import uuid from 'node-uuid';
|
||||||
import {getRules, getRule, deleteRule as deleteRuleAPI} from 'src/kapacitor/apis';
|
|
||||||
import {getKapacitor} from 'src/shared/apis';
|
import {getKapacitor} from 'src/shared/apis';
|
||||||
import {publishNotification} from 'src/shared/actions/notifications';
|
import {publishNotification} from 'src/shared/actions/notifications';
|
||||||
|
import {
|
||||||
|
getRules,
|
||||||
|
getRule,
|
||||||
|
deleteRule as deleteRuleAPI,
|
||||||
|
updateRuleStatus as updateRuleStatusAPI,
|
||||||
|
} from 'src/kapacitor/apis';
|
||||||
|
|
||||||
export function fetchRule(source, ruleID) {
|
export function fetchRule(source, ruleID) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
|
@ -126,6 +131,16 @@ export function deleteRuleSuccess(ruleID) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateRuleStatusSuccess(ruleID, status) {
|
||||||
|
return {
|
||||||
|
type: 'UPDATE_RULE_STATUS_SUCCESS',
|
||||||
|
payload: {
|
||||||
|
ruleID,
|
||||||
|
status,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function deleteRule(rule) {
|
export function deleteRule(rule) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
deleteRuleAPI(rule).then(() => {
|
deleteRuleAPI(rule).then(() => {
|
||||||
|
@ -136,3 +151,15 @@ export function deleteRule(rule) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateRuleStatus(rule, {status}) {
|
||||||
|
return (dispatch) => {
|
||||||
|
updateRuleStatusAPI(rule, status).then(() => {
|
||||||
|
dispatch(updateRuleStatusSuccess(rule.id, status));
|
||||||
|
dispatch(publishNotification('success', `${rule.name} ${status} successfully`));
|
||||||
|
}).catch(() => {
|
||||||
|
dispatch(updateRuleStatusSuccess(rule.id, status));
|
||||||
|
dispatch(publishNotification('error', `${rule.name} could not be ${status}`));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -47,3 +47,11 @@ export function deleteRule(rule) {
|
||||||
url: rule.links.self,
|
url: rule.links.self,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateRuleStatus(rule, status) {
|
||||||
|
return AJAX({
|
||||||
|
method: 'PATCH',
|
||||||
|
url: rule.links.self,
|
||||||
|
data: {status},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -6,27 +6,35 @@ import {getKapacitor} from 'src/shared/apis';
|
||||||
import * as kapacitorActionCreators from '../actions/view';
|
import * as kapacitorActionCreators from '../actions/view';
|
||||||
import NoKapacitorError from '../../shared/components/NoKapacitorError';
|
import NoKapacitorError from '../../shared/components/NoKapacitorError';
|
||||||
|
|
||||||
|
const {
|
||||||
|
arrayOf,
|
||||||
|
func,
|
||||||
|
shape,
|
||||||
|
string,
|
||||||
|
} = PropTypes;
|
||||||
|
|
||||||
export const KapacitorRulesPage = React.createClass({
|
export const KapacitorRulesPage = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
source: PropTypes.shape({
|
source: shape({
|
||||||
id: PropTypes.string.isRequired,
|
id: string.isRequired,
|
||||||
links: PropTypes.shape({
|
links: shape({
|
||||||
proxy: PropTypes.string.isRequired,
|
proxy: string.isRequired,
|
||||||
self: PropTypes.string.isRequired,
|
self: string.isRequired,
|
||||||
kapacitors: PropTypes.string.isRequired,
|
kapacitors: string.isRequired,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
rules: PropTypes.arrayOf(PropTypes.shape({
|
rules: arrayOf(shape({
|
||||||
name: PropTypes.string.isRequired,
|
name: string.isRequired,
|
||||||
trigger: PropTypes.string.isRequired,
|
trigger: string.isRequired,
|
||||||
message: PropTypes.string.isRequired,
|
message: string.isRequired,
|
||||||
alerts: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired,
|
alerts: arrayOf(string.isRequired).isRequired,
|
||||||
})).isRequired,
|
})).isRequired,
|
||||||
actions: PropTypes.shape({
|
actions: shape({
|
||||||
fetchRules: PropTypes.func.isRequired,
|
fetchRules: func.isRequired,
|
||||||
deleteRule: PropTypes.func.isRequired,
|
deleteRule: func.isRequired,
|
||||||
|
updateRuleStatus: func.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
addFlashMessage: PropTypes.func,
|
addFlashMessage: func,
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
|
@ -50,6 +58,11 @@ export const KapacitorRulesPage = React.createClass({
|
||||||
actions.deleteRule(rule);
|
actions.deleteRule(rule);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleRuleStatus(e, rule) {
|
||||||
|
const status = e.target.checked ? 'enabled' : 'disabled';
|
||||||
|
this.props.actions.updateRuleStatus(rule, {status});
|
||||||
|
},
|
||||||
|
|
||||||
renderSubComponent() {
|
renderSubComponent() {
|
||||||
const {source} = this.props;
|
const {source} = this.props;
|
||||||
const {hasKapacitor, loading} = this.state;
|
const {hasKapacitor, loading} = this.state;
|
||||||
|
@ -72,6 +85,7 @@ export const KapacitorRulesPage = React.createClass({
|
||||||
<th>Trigger</th>
|
<th>Trigger</th>
|
||||||
<th>Message</th>
|
<th>Message</th>
|
||||||
<th>Alerts</th>
|
<th>Alerts</th>
|
||||||
|
<th>Enabled</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -129,6 +143,9 @@ export const KapacitorRulesPage = React.createClass({
|
||||||
<td className="monotype">{rule.trigger}</td>
|
<td className="monotype">{rule.trigger}</td>
|
||||||
<td className="monotype">{rule.message}</td>
|
<td className="monotype">{rule.message}</td>
|
||||||
<td className="monotype">{rule.alerts.join(', ')}</td>
|
<td className="monotype">{rule.alerts.join(', ')}</td>
|
||||||
|
<td className="monotype">
|
||||||
|
<input className="form-control-static" type="checkbox" ref={(r) => this.enabled = r} checked={rule.status === "enabled"} onClick={(e) => this.handleRuleStatus(e, rule)} />
|
||||||
|
</td>
|
||||||
<td className="text-right"><button className="btn btn-danger btn-xs" onClick={() => this.handleDeleteRule(rule)}>Delete</button></td>
|
<td className="text-right"><button className="btn btn-danger btn-xs" onClick={() => this.handleDeleteRule(rule)}>Delete</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
|
|
@ -93,6 +93,14 @@ export default function rules(state = {}, action) {
|
||||||
[ruleID]: {...state[ruleID], details},
|
[ruleID]: {...state[ruleID], details},
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'UPDATE_RULE_STATUS_SUCCESS': {
|
||||||
|
const {ruleID, status} = action.payload;
|
||||||
|
|
||||||
|
return {...state, ...{
|
||||||
|
[ruleID]: {...state[ruleID], status},
|
||||||
|
}};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue