Fix dropdown populating via normalizd parsers, rename selected var names for clarity

pull/1326/head
Jared Scheib 2017-04-27 16:24:00 -07:00
parent b25cff0b6d
commit 2e5118ecf7
3 changed files with 16 additions and 12 deletions

View File

@ -2,7 +2,8 @@ import React, {PropTypes, Component} from 'react'
import Dropdown from 'shared/components/Dropdown'
import {showDatabases} from 'shared/apis/metaQuery'
import showDatabasesParser from 'shared/parsing/showDatabases'
import parsers from 'shared/parsing'
const {databases: showDatabasesParser} = parsers
class DatabaseDropdown extends Component {
constructor(props) {
@ -45,10 +46,10 @@ class DatabaseDropdown extends Component {
const {databases} = showDatabasesParser(data)
this.setState({databases})
const selectedText = databases.includes(database)
const selectedDatabaseText = databases.includes(database)
? database
: databases[0] || 'No databases'
onSelectDatabase({text: selectedText})
onSelectDatabase({text: selectedDatabaseText})
} catch (error) {
console.error(error)
onErrorThrown(error)

View File

@ -3,7 +3,8 @@ import _ from 'lodash'
import Dropdown from 'shared/components/Dropdown'
import {showMeasurements} from 'shared/apis/metaQuery'
import showMeasurementsParser from 'shared/parsing/showMeasurements'
import parsers from 'shared/parsing'
const {measurements: showMeasurementsParser} = parsers
class MeasurementDropdown extends Component {
constructor(props) {
@ -51,12 +52,13 @@ class MeasurementDropdown extends Component {
try {
const {data} = await showMeasurements(proxy, database)
const {measurementSets} = showMeasurementsParser(data)
this.setState({measurements: measurementSets[0].measurements})
const selectedText = measurementSets.includes(measurement)
const {measurements} = showMeasurementsParser(data)
this.setState({measurements})
const selectedMeasurementText = measurements.includes(measurement)
? measurement
: _.get(measurementSets, ['0', 'measurements', '0'], 'No measurements')
onSelectMeasurement({text: selectedText})
: measurements[0] || 'No measurements'
onSelectMeasurement({text: selectedMeasurementText})
} catch (error) {
console.error(error)
onErrorThrown(error)

View File

@ -2,7 +2,8 @@ import React, {PropTypes, Component} from 'react'
import Dropdown from 'shared/components/Dropdown'
import {showTagKeys} from 'shared/apis/metaQuery'
import showTagKeysParser from 'shared/parsing/showTagKeys'
import parsers from 'shared/parsing'
const {tagKeys: showTagKeysParser} = parsers
class TagKeyDropdown extends Component {
constructor(props) {
@ -57,10 +58,10 @@ class TagKeyDropdown extends Component {
const {tagKeys} = showTagKeysParser(data)
this.setState({tagKeys})
const selectedText = tagKeys.includes(tagKey)
const selectedTagKeyText = tagKeys.includes(tagKey)
? tagKey
: tagKeys[0] || 'No tags'
onSelectTagKey({text: selectedText})
onSelectTagKey({text: selectedTagKeyText})
} catch (error) {
console.error(error)
onErrorThrown(error)