From 2e5118ecf7fd1c3431d4618243f757fabe436e8c Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Thu, 27 Apr 2017 16:24:00 -0700 Subject: [PATCH] Fix dropdown populating via normalizd parsers, rename selected var names for clarity --- ui/src/dashboards/components/DatabaseDropdown.js | 7 ++++--- .../dashboards/components/MeasurementDropdown.js | 14 ++++++++------ ui/src/dashboards/components/TagKeyDropdown.js | 7 ++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ui/src/dashboards/components/DatabaseDropdown.js b/ui/src/dashboards/components/DatabaseDropdown.js index 8c1cecdc9..4b79bc4b7 100644 --- a/ui/src/dashboards/components/DatabaseDropdown.js +++ b/ui/src/dashboards/components/DatabaseDropdown.js @@ -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) diff --git a/ui/src/dashboards/components/MeasurementDropdown.js b/ui/src/dashboards/components/MeasurementDropdown.js index 9dc79100a..68c7e66a5 100644 --- a/ui/src/dashboards/components/MeasurementDropdown.js +++ b/ui/src/dashboards/components/MeasurementDropdown.js @@ -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) diff --git a/ui/src/dashboards/components/TagKeyDropdown.js b/ui/src/dashboards/components/TagKeyDropdown.js index 2db34f572..e2e42f854 100644 --- a/ui/src/dashboards/components/TagKeyDropdown.js +++ b/ui/src/dashboards/components/TagKeyDropdown.js @@ -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)