Add Data Explorer InfluxQL query and location query synchronization
parent
d1c8a2b8c6
commit
ed361e0060
|
@ -2,19 +2,16 @@ import React, {PropTypes} from 'react'
|
||||||
|
|
||||||
import QueryEditor from './QueryEditor'
|
import QueryEditor from './QueryEditor'
|
||||||
import SchemaExplorer from 'src/shared/components/SchemaExplorer'
|
import SchemaExplorer from 'src/shared/components/SchemaExplorer'
|
||||||
import buildInfluxQLQuery from 'utils/influxql'
|
import {buildRawText} from 'utils/influxql'
|
||||||
|
|
||||||
const rawTextBinder = (links, id, action) => text =>
|
const rawTextBinder = (links, id, action) => text =>
|
||||||
action(links.queries, id, text)
|
action(links.queries, id, text)
|
||||||
|
|
||||||
const buildText = (q, timeRange) =>
|
|
||||||
q.rawText || buildInfluxQLQuery(timeRange, q) || ''
|
|
||||||
|
|
||||||
const QueryMaker = ({source, actions, timeRange, activeQuery}) =>
|
const QueryMaker = ({source, actions, timeRange, activeQuery}) =>
|
||||||
<div className="query-maker query-maker--panel">
|
<div className="query-maker query-maker--panel">
|
||||||
<div className="query-maker--tab-contents">
|
<div className="query-maker--tab-contents">
|
||||||
<QueryEditor
|
<QueryEditor
|
||||||
query={buildText(activeQuery, timeRange)}
|
query={buildRawText(activeQuery, timeRange)}
|
||||||
config={activeQuery}
|
config={activeQuery}
|
||||||
onUpdate={rawTextBinder(
|
onUpdate={rawTextBinder(
|
||||||
source.links,
|
source.links,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import React, {PropTypes, Component} from 'react'
|
import React, {PropTypes, Component} from 'react'
|
||||||
import {connect} from 'react-redux'
|
import {connect} from 'react-redux'
|
||||||
import {bindActionCreators} from 'redux'
|
import {bindActionCreators} from 'redux'
|
||||||
|
import {withRouter} from 'react-router'
|
||||||
|
import queryString from 'query-string'
|
||||||
|
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
|
@ -17,6 +19,7 @@ import {errorThrown} from 'shared/actions/errors'
|
||||||
import {setAutoRefresh} from 'shared/actions/app'
|
import {setAutoRefresh} from 'shared/actions/app'
|
||||||
import * as dataExplorerActionCreators from 'src/data_explorer/actions/view'
|
import * as dataExplorerActionCreators from 'src/data_explorer/actions/view'
|
||||||
import {writeLineProtocolAsync} from 'src/data_explorer/actions/view/write'
|
import {writeLineProtocolAsync} from 'src/data_explorer/actions/view/write'
|
||||||
|
import {buildRawText} from 'src/utils/influxql'
|
||||||
|
|
||||||
class DataExplorer extends Component {
|
class DataExplorer extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -35,6 +38,25 @@ class DataExplorer extends Component {
|
||||||
return queryConfigs[0]
|
return queryConfigs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const {query} = queryString.parse(window.location.search)
|
||||||
|
if (query && query.length) {
|
||||||
|
const qc = this.props.queryConfigs[0]
|
||||||
|
this.props.queryConfigActions.editRawText(qc.id, query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
const {router} = this.props
|
||||||
|
const {queryConfigs, timeRange} = nextProps
|
||||||
|
const query = buildRawText(queryConfigs[0], timeRange)
|
||||||
|
const qsCurrent = queryString.parse(router.location.search)
|
||||||
|
if (query.length && qsCurrent.query !== query) {
|
||||||
|
const qsNew = queryString.stringify({query})
|
||||||
|
router.push(`${window.location.pathname}?${qsNew}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleCloseWriteData = () => {
|
handleCloseWriteData = () => {
|
||||||
this.setState({showWriteForm: false})
|
this.setState({showWriteForm: false})
|
||||||
}
|
}
|
||||||
|
@ -56,12 +78,8 @@ class DataExplorer extends Component {
|
||||||
writeLineProtocol,
|
writeLineProtocol,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
const {activeQueryIndex, showWriteForm} = this.state
|
const {showWriteForm} = this.state
|
||||||
const selectedDatabase = _.get(
|
const selectedDatabase = _.get(queryConfigs, ['0', 'database'], null)
|
||||||
queryConfigs,
|
|
||||||
[`${activeQueryIndex}`, 'database'],
|
|
||||||
null
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="data-explorer">
|
<div className="data-explorer">
|
||||||
|
@ -101,7 +119,7 @@ class DataExplorer extends Component {
|
||||||
timeRange={timeRange}
|
timeRange={timeRange}
|
||||||
queryConfigs={queryConfigs}
|
queryConfigs={queryConfigs}
|
||||||
errorThrown={errorThrownAction}
|
errorThrown={errorThrownAction}
|
||||||
activeQueryIndex={activeQueryIndex}
|
activeQueryIndex={0}
|
||||||
editQueryStatus={queryConfigActions.editQueryStatus}
|
editQueryStatus={queryConfigActions.editQueryStatus}
|
||||||
views={VIS_VIEWS}
|
views={VIS_VIEWS}
|
||||||
/>
|
/>
|
||||||
|
@ -121,6 +139,12 @@ DataExplorer.propTypes = {
|
||||||
queries: string.isRequired,
|
queries: string.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
router: shape({
|
||||||
|
location: shape({
|
||||||
|
search: string,
|
||||||
|
pathanme: string,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
queryConfigs: arrayOf(shape({})).isRequired,
|
queryConfigs: arrayOf(shape({})).isRequired,
|
||||||
queryConfigActions: shape({
|
queryConfigActions: shape({
|
||||||
editQueryStatus: func.isRequired,
|
editQueryStatus: func.isRequired,
|
||||||
|
@ -181,4 +205,6 @@ const mapDispatchToProps = dispatch => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DataExplorer)
|
export default connect(mapStateToProps, mapDispatchToProps)(
|
||||||
|
withRouter(DataExplorer)
|
||||||
|
)
|
||||||
|
|
|
@ -199,3 +199,6 @@ export const buildQueriesForLayouts = (cell, source, timeRange, host) => {
|
||||||
return {...query, host: source.links.proxy, text: queryText}
|
return {...query, host: source.links.proxy, text: queryText}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const buildRawText = (q, timeRange) =>
|
||||||
|
q.rawText || buildInfluxQLQuery(timeRange, q) || ''
|
||||||
|
|
Loading…
Reference in New Issue