From a8b6bb48c80cc63e43895c69a5b4d8bb03a80c9a Mon Sep 17 00:00:00 2001 From: ebb-tide Date: Tue, 29 May 2018 12:35:24 -0700 Subject: [PATCH] Add missing suggestion params inside bodynodes function --- ui/src/ifql/containers/IFQLPage.tsx | 17 ++--------------- ui/src/ifql/helpers/index.ts | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ui/src/ifql/containers/IFQLPage.tsx b/ui/src/ifql/containers/IFQLPage.tsx index ba71141ba..e79093252 100644 --- a/ui/src/ifql/containers/IFQLPage.tsx +++ b/ui/src/ifql/containers/IFQLPage.tsx @@ -17,7 +17,7 @@ import { import {bodyNodes} from 'src/ifql/helpers' import {getSuggestions, getAST, getTimeSeries} from 'src/ifql/apis' -import {funcNames, builder, argTypes} from 'src/ifql/constants' +import {builder, argTypes} from 'src/ifql/constants' import {Source, Service, Notification} from 'src/types' import { @@ -408,20 +408,7 @@ export class IFQLPage extends PureComponent { try { const ast = await getAST({url: links.ast, body: script}) - const suggestions = this.state.suggestions.map(s => { - if (s.name === funcNames.JOIN) { - return { - ...s, - params: { - tables: 'object', - on: 'array', - fn: 'function', - }, - } - } - return s - }) - const body = bodyNodes(ast, suggestions) + const body = bodyNodes(ast, this.state.suggestions) const status = {type: 'success', text: ''} this.setState({ast, body, status}) this.props.updateScript(script) diff --git a/ui/src/ifql/helpers/index.ts b/ui/src/ifql/helpers/index.ts index e7cd0358d..55459b775 100644 --- a/ui/src/ifql/helpers/index.ts +++ b/ui/src/ifql/helpers/index.ts @@ -1,6 +1,8 @@ import uuid from 'uuid' import _ from 'lodash' import Walker from 'src/ifql/ast/walker' +import {funcNames} from 'src/ifql/constants' + import {FlatBody, Func} from 'src/types/ifql' interface Body extends FlatBody { @@ -12,6 +14,20 @@ export const bodyNodes = (ast, suggestions): Body[] => { return [] } + const enrichedSuggestions = suggestions.map(s => { + if (s.name === funcNames.JOIN) { + return { + ...s, + params: { + tables: 'object', + on: 'array', + fn: 'function', + }, + } + } + return s + }) + const walker = new Walker(ast) const body = walker.body.map(b => { @@ -26,7 +42,7 @@ export const bodyNodes = (ast, suggestions): Body[] => { return { ...d, id: uuid.v4(), - funcs: functions(d.funcs, suggestions), + funcs: functions(d.funcs, enrichedSuggestions), } }) @@ -37,7 +53,7 @@ export const bodyNodes = (ast, suggestions): Body[] => { return { id, - funcs: functions(funcs, suggestions), + funcs: functions(funcs, enrichedSuggestions), declarations: [], type, source,