From a5c1a83e9011c4f4c98084d8244babff92ca9bbc Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Wed, 6 Sep 2017 15:40:54 -0700 Subject: [PATCH] Reform Relative into an SFC --- ui/src/kapacitor/components/KapacitorRule.js | 15 +-- ui/src/kapacitor/components/Relative.js | 129 +++++++++---------- ui/src/kapacitor/components/Threshold.js | 8 +- ui/src/kapacitor/components/ValuesSection.js | 12 +- 4 files changed, 79 insertions(+), 85 deletions(-) diff --git a/ui/src/kapacitor/components/KapacitorRule.js b/ui/src/kapacitor/components/KapacitorRule.js index 4e09347ffd..02a2edaf46 100644 --- a/ui/src/kapacitor/components/KapacitorRule.js +++ b/ui/src/kapacitor/components/KapacitorRule.js @@ -108,10 +108,13 @@ class KapacitorRule extends Component { handleRuleTypeDropdownChange = ({type, text}) => { const {ruleActions, rule} = this.props - ruleActions.updateRuleValues(rule.id, rule.trigger, {[type]: text}) + ruleActions.updateRuleValues(rule.id, rule.trigger, { + ...this.props.rule.values, + [type]: text, + }) } - handleThresholdInputChange = e => { + handleRuleTypeInputChange = e => { const {ruleActions, rule} = this.props const {lower, upper} = e.target.form @@ -121,11 +124,6 @@ class KapacitorRule extends Component { rangeValue: upper ? upper.value : '', }) } - // - // handleRelativeInputChange = () => { - // const {ruleActions, rule} = this.props - // // ruleActions.updateRuleValues(rule.id, rule.trigger, {period: text}) - // } handleDeadmanChange = ({text}) => { const {ruleActions, rule} = this.props @@ -169,8 +167,7 @@ class KapacitorRule extends Component { onUpdateValues={updateRuleValues} onDeadmanChange={this.handleDeadmanChange} onRuleTypeDropdownChange={this.handleRuleTypeDropdownChange} - onThresholdInputChange={this.handleThresholdInputChange} - onRelativeInputChange={this.handleRelativeInputChange} + onRuleTypeInputChange={this.handleRuleTypeInputChange} /> arr.map(text => ({text, type})) +const changes = mapToItems(CHANGES, 'change') +const shifts = mapToItems(SHIFTS, 'shift') +const operators = mapToItems(OPERATORS, 'operator') -const Relative = React.createClass({ - propTypes: { - rule: PropTypes.shape({ - values: PropTypes.shape({ - change: PropTypes.string, - shift: PropTypes.string, - operator: PropTypes.string, - value: PropTypes.string, - }), +const Relative = ({ + onRuleTypeInputChange, + onDropdownChange, + rule: {values: {change, shift, operator, value}}, +}) => +
+

Send Alert when

+ +

compared to previous

+ +

is

+ +
+ +
+ {change === CHANGES[1] ?

%

: null} +
+ +const {shape, string, func} = PropTypes + +Relative.propTypes = { + onRuleTypeInputChange: func.isRequired, + onDropdownChange: func.isRequired, + rule: shape({ + values: shape({ + change: string, + shift: string, + operator: string, + value: string, }), - onChange: PropTypes.func.isRequired, - }, - - handleDropdownChange(item) { - this.props.onChange({...this.props.rule.values, [item.type]: item.text}) - }, - - handleInputChange() { - this.props.onChange({...this.props.rule.values, value: this.input.value}) - }, - - render() { - const {change, shift, operator, value} = this.props.rule.values - - const changes = mapToItems(CHANGES, 'change') - const shifts = mapToItems(SHIFTS, 'shift') - const operators = mapToItems(OPERATORS, 'operator') - - return ( -
-

Send Alert when

- -

compared to previous

- -

is

- - (this.input = r)} - defaultValue={value} - onKeyUp={this.handleInputChange} - required={true} - type="text" - spellCheck="false" - /> - {change === CHANGES[1] ?

%

: null} -
- ) - }, -}) + }), +} export default Relative diff --git a/ui/src/kapacitor/components/Threshold.js b/ui/src/kapacitor/components/Threshold.js index f7e8fbb9fd..62a4049199 100644 --- a/ui/src/kapacitor/components/Threshold.js +++ b/ui/src/kapacitor/components/Threshold.js @@ -9,7 +9,7 @@ const Threshold = ({ rule: {values: {operator, value, rangeValue}}, query, onDropdownChange, - onThresholdInputChange, + onRuleTypeInputChange, }) =>

Send Alert where

@@ -32,7 +32,7 @@ const Threshold = ({ name="lower" spellCheck="false" value={value} - onChange={onThresholdInputChange} + onChange={onRuleTypeInputChange} placeholder={ operator === 'inside range' || operator === 'outside range' ? 'Lower' @@ -48,7 +48,7 @@ const Threshold = ({ type="text" spellCheck="false" value={rangeValue} - onChange={onThresholdInputChange} + onChange={onRuleTypeInputChange} />}
@@ -65,7 +65,7 @@ Threshold.propTypes = { }), }), onDropdownChange: func.isRequired, - onThresholdInputChange: func.isRequired, + onRuleTypeInputChange: func.isRequired, query: shape({}).isRequired, } diff --git a/ui/src/kapacitor/components/ValuesSection.js b/ui/src/kapacitor/components/ValuesSection.js index d82f69c8c4..8b329e15eb 100644 --- a/ui/src/kapacitor/components/ValuesSection.js +++ b/ui/src/kapacitor/components/ValuesSection.js @@ -20,7 +20,7 @@ export const ValuesSection = React.createClass({ query: PropTypes.shape({}).isRequired, onDeadmanChange: PropTypes.func.isRequired, onRuleTypeDropdownChange: PropTypes.func.isRequired, - onThresholdInputChange: PropTypes.func.isRequired, + onRuleTypeInputChange: PropTypes.func.isRequired, }, render() { @@ -29,7 +29,7 @@ export const ValuesSection = React.createClass({ query, onDeadmanChange, onRuleTypeDropdownChange, - onThresholdInputChange, + onRuleTypeInputChange, } = this.props const initialIndex = TABS.indexOf(_.startCase(rule.trigger)) @@ -52,11 +52,15 @@ export const ValuesSection = React.createClass({ rule={rule} query={query} onDropdownChange={onRuleTypeDropdownChange} - onThresholdInputChange={onThresholdInputChange} + onRuleTypeInputChange={onRuleTypeInputChange} /> - +