From d3927dc1875e690e8d38fb53217915228725c954 Mon Sep 17 00:00:00 2001 From: deniz kusefoglu Date: Fri, 8 Sep 2017 12:35:42 -0700 Subject: [PATCH] Refactor DataSection SFC --- ui/src/kapacitor/components/DataSection.js | 131 +++++++++++---------- 1 file changed, 70 insertions(+), 61 deletions(-) diff --git a/ui/src/kapacitor/components/DataSection.js b/ui/src/kapacitor/components/DataSection.js index 2ea72d58b3..025d4d2b9c 100644 --- a/ui/src/kapacitor/components/DataSection.js +++ b/ui/src/kapacitor/components/DataSection.js @@ -1,4 +1,4 @@ -import React, {PropTypes, Component} from 'react' +import React, {PropTypes} from 'react' import DatabaseList from 'src/shared/components/DatabaseList' import MeasurementList from 'src/shared/components/MeasurementList' @@ -6,79 +6,88 @@ import FieldList from 'src/shared/components/FieldList' import {defaultEveryFrequency} from 'src/kapacitor/constants' -class DataSection extends Component { - constructor(props) { - super(props) - } +const makeQueryHandlers = (actions, query) => ({ + handleChooseNamespace: namespace => { + actions.chooseNamespace(query.id, namespace) + }, - handleChooseNamespace = namespace => { - this.props.actions.chooseNamespace(this.props.query.id, namespace) - } + handleChooseMeasurement: measurement => { + actions.chooseMeasurement(query.id, measurement) + }, - handleChooseMeasurement = measurement => { - this.props.actions.chooseMeasurement(this.props.query.id, measurement) - } - - handleToggleField = field => { - this.props.actions.toggleField(this.props.query.id, field) + handleToggleField: onRemoveEvery => field => { + actions.toggleField(query.id, field) // Every is only added when a function has been added to a field. // Here, the field is selected without a function. - this.props.onRemoveEvery() + onRemoveEvery() // Because there are no functions there is no group by time. - this.props.actions.groupByTime(this.props.query.id, null) - } + actions.groupByTime(query.id, null) + }, - handleGroupByTime = time => { - this.props.actions.groupByTime(this.props.query.id, time) - } + handleGroupByTime: time => { + actions.groupByTime(query.id, time) + }, - handleApplyFuncsToField = fieldFunc => { - this.props.actions.applyFuncsToField(this.props.query.id, fieldFunc) - this.props.onAddEvery(defaultEveryFrequency) - } + handleApplyFuncsToField: onAddEvery => fieldFunc => { + actions.applyFuncsToField(query.id, fieldFunc) + onAddEvery(defaultEveryFrequency) + }, - handleChooseTag = tag => { - this.props.actions.chooseTag(this.props.query.id, tag) - } + handleChooseTag: tag => { + actions.chooseTag(query.id, tag) + }, - handleToggleTagAcceptance = () => { - this.props.actions.toggleTagAcceptance(this.props.query.id) - } + handleToggleTagAcceptance: () => { + actions.toggleTagAcceptance(query.id) + }, - handleGroupByTag = tagKey => { - this.props.actions.groupByTag(this.props.query.id, tagKey) - } + handleGroupByTag: tagKey => { + actions.groupByTag(query.id, tagKey) + }, +}) - render() { - const {query, isKapacitorRule, isDeadman} = this.props +const DataSection = ({ + actions, + query, + isDeadman, + isKapacitorRule, + onRemoveEvery, + onAddEvery, +}) => { + const { + handleChooseNamespace, + handleChooseMeasurement, + handleToggleField, + handleGroupByTime, + handleApplyFuncsToField, + handleChooseTag, + handleToggleTagAcceptance, + handleGroupByTag, + } = makeQueryHandlers(actions, query) - return ( -
-
- - - {isDeadman - ? null - : } -
+ return ( +
+
+ + + {isDeadman + ? null + : }
- ) - } +
+ ) } const {bool, func, shape, string} = PropTypes