Start query editor with placeholder text

pull/1081/head
Andrew Watkins 2017-04-03 10:15:08 -07:00
parent 20ca434e97
commit 1aa7b4770a
4 changed files with 22 additions and 11 deletions

View File

@ -52,7 +52,7 @@ const QueryBuilder = React.createClass({
handleAddRawQuery() {
const newIndex = this.props.queries.length
this.props.actions.addQuery({rawText: `SELECT "fields" from "db"."rp"."measurement"`})
this.props.actions.addQuery({rawText: ''})
this.handleSetActiveQueryIndex(newIndex)
},
@ -115,7 +115,7 @@ const QueryBuilder = React.createClass({
query={q}
onSelect={this.handleSetActiveQueryIndex}
onDelete={onDeleteQuery}
queryTabText={q.rawText || buildInfluxQLQuery(timeRange, q) || `SELECT "fields" FROM "db"."rp"."measurement"`}
queryTabText={q.rawText || buildInfluxQLQuery(timeRange, q) || `Query ${i + 1}`}
/>
)
})}

View File

@ -91,9 +91,9 @@ const QueryEditor = React.createClass({
renderQuery() {
const {query, timeRange} = this.props
const statement = query.rawText || buildInfluxQLQuery(timeRange, query) || `SELECT "fields" FROM "db"."rp"."measurement"`
const statement = query.rawText || buildInfluxQLQuery(timeRange, query) || `Select a database, measurement, and field below.`
if (!query.rawText) {
if (typeof query.rawText !== 'string') {
return (
<div className="query-builder--query-preview">
<pre><code>{statement}</code></pre>

View File

@ -29,7 +29,7 @@ const RawQueryEditor = React.createClass({
e.preventDefault()
this.handleUpdate()
} else if (e.keyCode === ESCAPE) {
this.setState({value: this.props.query.rawText}, () => {
this.setState({value: this.state.value}, () => {
this.editor.blur()
})
}

View File

@ -6,6 +6,10 @@ import _ from 'lodash'
import moment from 'moment'
const {oneOfType, number, string, shape, arrayOf, func} = PropTypes
const emptyCells = {
columns: [],
values: [],
}
const CustomCell = React.createClass({
propTypes: {
@ -39,10 +43,7 @@ const ChronoTable = React.createClass({
getInitialState() {
return {
cellData: {
columns: [],
values: [],
},
cellData: emptyCells,
columnWidths: {},
}
},
@ -54,6 +55,10 @@ const ChronoTable = React.createClass({
},
async fetchCellData(query) {
if (!query.text) {
return
}
this.setState({isLoading: true})
const {onEditRawStatus} = this.props
// second param is db, we want to leave this blank
@ -87,9 +92,15 @@ const ChronoTable = React.createClass({
},
componentWillReceiveProps(nextProps) {
if (this.props.query.text !== nextProps.query.text) {
this.fetchCellData(nextProps.query)
if (!this.props.query || !nextProps.query) {
return
}
if (this.props.query.text === nextProps.query.text) {
return
}
this.fetchCellData(nextProps.query)
},
handleColumnResize(newColumnWidth, columnKey) {