Hydrate MetaQueryTemplateBuilder correctly

pull/10616/head
Christopher Henn 2018-06-19 16:09:13 -07:00
parent 95a45fda9f
commit eee06b07bb
2 changed files with 13 additions and 10 deletions

View File

@ -12,8 +12,6 @@ import {
TemplateValueType, TemplateValueType,
} from 'src/types' } from 'src/types'
// TODO: Ensure save is wired up to changes
const DEBOUNCE_DELAY = 750 const DEBOUNCE_DELAY = 750
interface State { interface State {
@ -30,30 +28,31 @@ class CustomMetaQueryTemplateBuilder extends PureComponent<
> { > {
private handleMetaQueryChange: () => void = _.debounce(() => { private handleMetaQueryChange: () => void = _.debounce(() => {
const {metaQuery, metaQueryInput} = this.state const {metaQuery, metaQueryInput} = this.state
const {template, onUpdateTemplate} = this.props
if (metaQuery === metaQueryInput) { if (metaQuery === metaQueryInput) {
return return
} }
this.setState({metaQuery: metaQueryInput}, this.executeQuery) this.setState({metaQuery: metaQueryInput}, this.executeQuery)
const nextTemplate = {...template, query: {influxql: metaQueryInput}}
onUpdateTemplate(nextTemplate)
}, DEBOUNCE_DELAY) }, DEBOUNCE_DELAY)
constructor(props) { constructor(props) {
super(props) super(props)
const metaQuery = _.get(props.template, 'query.influxql', '')
this.state = { this.state = {
metaQueryInput: '', metaQuery,
metaQuery: '', metaQueryInput: metaQuery,
metaQueryResults: [], metaQueryResults: [],
metaQueryResultsStatus: RemoteDataState.NotStarted, metaQueryResultsStatus: RemoteDataState.NotStarted,
} }
} }
public componentDidMount() {
this.executeQuery()
}
public render() { public render() {
const {metaQueryInput} = this.state const {metaQueryInput} = this.state
@ -138,7 +137,7 @@ class CustomMetaQueryTemplateBuilder extends PureComponent<
const nextValues = metaQueryResults.map(result => { const nextValues = metaQueryResults.map(result => {
return { return {
type: TemplateValueType.Constant, type: TemplateValueType.MetaQuery,
value: result, value: result,
selected: false, selected: false,
} }
@ -151,6 +150,9 @@ class CustomMetaQueryTemplateBuilder extends PureComponent<
const nextTemplate = { const nextTemplate = {
...template, ...template,
values: nextValues, values: nextValues,
query: {
influxql: metaQuery,
},
} }
onUpdateTemplate(nextTemplate) onUpdateTemplate(nextTemplate)

View File

@ -9,6 +9,7 @@ export enum TemplateValueType {
CSV = 'csv', CSV = 'csv',
Points = 'points', Points = 'points',
Constant = 'constant', Constant = 'constant',
MetaQuery = 'influxql',
} }
export interface TemplateValue { export interface TemplateValue {