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

View File

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