diff --git a/ui/src/data_explorer/reducers/queryConfigs.js b/ui/src/data_explorer/reducers/queryConfigs.js index f8c7659077..da678e2166 100644 --- a/ui/src/data_explorer/reducers/queryConfigs.js +++ b/ui/src/data_explorer/reducers/queryConfigs.js @@ -34,13 +34,16 @@ const queryConfigs = (state = {}, action) => { case 'DE_CHOOSE_MEASUREMENT': { const {queryID, measurement} = action.payload + const nextQueryConfig = chooseMeasurement(state[queryID], measurement) - return Object.assign({}, state, { - [queryID]: Object.assign(nextQueryConfig, { + return { + ...state, + [queryID]: { + ...nextQueryConfig, rawText: state[queryID].rawText, - }), - }) + }, + } } // there is an additional reducer for this same action in the ui reducer diff --git a/ui/src/shared/components/MeasurementListItem.tsx b/ui/src/shared/components/MeasurementListItem.tsx index 7eac26777b..a2bc46eb6d 100644 --- a/ui/src/shared/components/MeasurementListItem.tsx +++ b/ui/src/shared/components/MeasurementListItem.tsx @@ -1,5 +1,6 @@ +import _ from 'lodash' import classnames from 'classnames' -import React, {SFC} from 'react' +import React, {PureComponent, MouseEvent} from 'react' import TagList from 'src/shared/components/TagList' import {Query, Source} from 'src/types' @@ -17,51 +18,93 @@ interface Props { onChooseMeasurement: (measurement: string) => () => void } -const noop = () => {} +interface State { + isOpen: boolean +} -const MeasurementListItem: SFC = ({ - query, - isActive, - querySource, - measurement, - onChooseTag, - onGroupByTag, - numTagsActive, - onAcceptReject, - areTagsAccepted, - onChooseMeasurement, -}) => ( -
-
- -
- {measurement} - - {isActive && - numTagsActive >= 1 && ( -
-
-
!=
-
=
-
-
+class MeasurementListItem extends PureComponent { + constructor(props) { + super(props) + + this.state = {isOpen: this.isCurrentMeasurement} + } + + public render() { + const { + query, + querySource, + measurement, + onChooseTag, + onGroupByTag, + numTagsActive, + areTagsAccepted, + } = this.props + + return ( +
+
+ +
+ {measurement} + + {this.shouldShow && + numTagsActive >= 1 && ( +
+
+
!=
+
=
+
+
+ )} +
+ {this.shouldShow && ( + )} -
- {isActive && ( - - )} -
-) +
+ ) + } + + private handleAcceptReject = (e: MouseEvent) => { + e.stopPropagation() + + const {onAcceptReject} = this.props + onAcceptReject() + } + + private handleClick = () => { + const {measurement, onChooseMeasurement} = this.props + + if (!this.isCurrentMeasurement) { + this.setState({isOpen: true}, () => { + onChooseMeasurement(measurement)() + }) + } else { + this.setState({isOpen: !this.state.isOpen}) + } + } + + private get shouldShow(): boolean { + return this.isCurrentMeasurement && this.state.isOpen + } + + private get isCurrentMeasurement(): boolean { + const {query, measurement} = this.props + return _.get(query, 'measurement') === measurement + } +} export default MeasurementListItem diff --git a/ui/src/shared/components/TagListItem.tsx b/ui/src/shared/components/TagListItem.tsx index 4ed1ac0240..a6b7edec9e 100644 --- a/ui/src/shared/components/TagListItem.tsx +++ b/ui/src/shared/components/TagListItem.tsx @@ -1,6 +1,6 @@ import classnames from 'classnames' import _ from 'lodash' -import React, {PureComponent} from 'react' +import React, {PureComponent, MouseEvent} from 'react' interface Tag { key: string @@ -36,11 +36,13 @@ class TagListItem extends PureComponent { this.handleFilterText = this.handleFilterText.bind(this) } - public handleChoose(tagValue: string) { + public handleChoose(tagValue: string, e: MouseEvent) { + e.stopPropagation() this.props.onChooseTag({key: this.props.tagKey, value: tagValue}) } - public handleClickKey() { + public handleClickKey(e: MouseEvent) { + e.stopPropagation() this.setState({isOpen: !this.state.isOpen}) }