Get new dbs, rps, meas, fields etc when selecting a new source

pull/1996/head
deniz kusefoglu 2017-10-03 15:36:44 -07:00
parent 6230ddc512
commit ae364f5018
6 changed files with 87 additions and 17 deletions

View File

@ -257,9 +257,20 @@ class CellEditorOverlay extends Component {
return (selected && selected.text) || 'No sources'
}
getSource = () => {
const {source, sources} = this.props
const query = _.get(this.state.queriesWorkingDraft, 0, false)
if (!query || !query.source) {
return source
}
const querySource = sources.find(s => s.id === query.source.id)
return querySource || source
}
render() {
const {
source,
onCancel,
templates,
timeRange,
@ -330,7 +341,7 @@ class CellEditorOverlay extends Component {
onSetYAxisBoundMax={this.handleSetYAxisBoundMax}
/>
: <QueryMaker
source={source}
source={this.getSource()}
templates={templates}
queries={queriesWorkingDraft}
actions={queryActions}

View File

@ -13,7 +13,7 @@ const buildText = q =>
q.rawText || buildInfluxQLQuery(q.range || TEMPLATE_RANGE, q) || ''
const QueryMaker = ({
source: {links},
source,
actions,
queries,
timeRange,
@ -39,7 +39,7 @@ const QueryMaker = ({
query={buildText(activeQuery)}
config={activeQuery}
onUpdate={rawTextBinder(
links,
source.links,
activeQuery.id,
actions.editRawTextAsync
)}
@ -49,6 +49,7 @@ const QueryMaker = ({
query={activeQuery}
actions={actions}
onAddQuery={onAddQuery}
source={source}
/>
</div>
: <EmptyQuery onAddQuery={onAddQuery} />}

View File

@ -14,6 +14,17 @@ const DatabaseList = React.createClass({
propTypes: {
query: shape({}).isRequired,
onChooseNamespace: func.isRequired,
querySource: shape({
links: shape({
proxy: string.isRequired,
}).isRequired,
}),
},
getDefaultProps() {
return {
source: null,
}
},
contextTypes: {
@ -31,8 +42,23 @@ const DatabaseList = React.createClass({
},
componentDidMount() {
this.getDbRp()
},
componentDidUpdate(prevProps) {
if (_.isEqual(prevProps.querySource, this.props.querySource)) {
return
}
this.getDbRp()
},
getDbRp() {
const {source} = this.context
const proxy = source.links.proxy
const {querySource} = this.props
const proxy =
_.get(querySource, ['links', 'proxy'], null) || source.links.proxy
showDatabases(proxy).then(resp => {
const {errors, databases} = showDatabasesParser(resp.data)
if (errors.length) {

View File

@ -1,4 +1,5 @@
import React, {PropTypes, Component} from 'react'
import _ from 'lodash'
import FieldListItem from 'src/data_explorer/components/FieldListItem'
import GroupByTimeDropdown from 'src/data_explorer/components/GroupByTimeDropdown'
@ -26,7 +27,8 @@ class FieldList extends Component {
}
componentDidUpdate(prevProps) {
const {database, measurement, retentionPolicy} = this.props.query
const {querySource, query} = this.props
const {database, measurement, retentionPolicy} = query
const {
database: prevDB,
measurement: prevMeas,
@ -39,7 +41,8 @@ class FieldList extends Component {
if (
database === prevDB &&
measurement === prevMeas &&
retentionPolicy === prevRP
retentionPolicy === prevRP &&
_.isEqual(prevProps.querySource, querySource)
) {
return
}
@ -58,14 +61,12 @@ class FieldList extends Component {
_getFields = () => {
const {database, measurement, retentionPolicy} = this.props.query
const {source} = this.context
const proxySource = source.links.proxy
const {querySource} = this.props
showFieldKeys(
proxySource,
database,
measurement,
retentionPolicy
).then(resp => {
const proxy =
_.get(querySource, ['links', 'proxy'], null) || source.links.proxy
showFieldKeys(proxy, database, measurement, retentionPolicy).then(resp => {
const {errors, fieldSets} = showFieldKeysParser(resp.data)
if (errors.length) {
console.error('Error parsing fields keys: ', errors)
@ -171,6 +172,11 @@ FieldList.propTypes = {
applyFuncsToField: func.isRequired,
isKapacitorRule: bool,
isInDataExplorer: bool,
querySource: shape({
links: shape({
proxy: string.isRequired,
}).isRequired,
}),
}
export default FieldList

View File

@ -1,5 +1,6 @@
import React, {PropTypes} from 'react'
import classnames from 'classnames'
import _ from 'lodash'
import {showMeasurements} from 'shared/apis/metaQuery'
import showMeasurementsParser from 'shared/parsing/showMeasurements'
@ -19,6 +20,11 @@ const MeasurementList = React.createClass({
onChooseTag: func.isRequired,
onToggleTagAcceptance: func.isRequired,
onGroupByTag: func.isRequired,
querySource: shape({
links: shape({
proxy: string.isRequired,
}).isRequired,
}),
},
contextTypes: {
@ -36,6 +42,12 @@ const MeasurementList = React.createClass({
}
},
getDefaultProps() {
return {
querySource: null,
}
},
componentDidMount() {
if (!this.props.query.database) {
return
@ -45,13 +57,16 @@ const MeasurementList = React.createClass({
},
componentDidUpdate(prevProps) {
const {query} = this.props
const {query, querySource} = this.props
if (!query.database) {
return
}
if (prevProps.query.database === query.database) {
if (
prevProps.query.database === query.database &&
_.isEqual(prevProps.querySource, querySource)
) {
return
}
@ -181,7 +196,11 @@ const MeasurementList = React.createClass({
_getMeasurements() {
const {source} = this.context
const proxy = source.links.proxy
const {querySource} = this.props
const proxy =
_.get(querySource, ['links', 'proxy'], null) || source.links.proxy
showMeasurements(proxy, this.props.query.database).then(resp => {
const {errors, measurementSets} = showMeasurementsParser(resp.data)
if (errors.length) {

View File

@ -9,6 +9,7 @@ const actionBinder = (id, action) => item => action(id, item)
const SchemaExplorer = ({
query,
query: {id},
source,
actions: {
chooseTag,
groupByTag,
@ -24,17 +25,22 @@ const SchemaExplorer = ({
<div className="query-builder">
<DatabaseList
query={query}
querySource={source}
onChooseNamespace={actionBinder(id, chooseNamespace)}
/>
<MeasurementList
source={source}
query={query}
querySource={source}
onChooseTag={actionBinder(id, chooseTag)}
onGroupByTag={actionBinder(id, groupByTag)}
onChooseMeasurement={actionBinder(id, chooseMeasurement)}
onToggleTagAcceptance={actionBinder(id, toggleTagAcceptance)}
/>
<FieldList
source={source}
query={query}
querySource={source}
onToggleField={actionBinder(id, toggleFieldWithGroupByInterval)}
onFill={actionBinder(id, fill)}
onGroupByTime={actionBinder(id, groupByTime)}
@ -60,6 +66,7 @@ SchemaExplorer.propTypes = {
fill: func.isRequired,
editRawTextAsync: func.isRequired,
}).isRequired,
source: shape({}),
}
export default SchemaExplorer