diff --git a/ui/src/ifql/ast/walker.ts b/ui/src/ifql/ast/walker.ts index 1ae9dc598..332a2a078 100644 --- a/ui/src/ifql/ast/walker.ts +++ b/ui/src/ifql/ast/walker.ts @@ -1,5 +1,6 @@ // Texas Ranger import _ from 'lodash' +import {FlatBody, Func} from 'src/types/ifql' interface Expression { argument: object @@ -19,14 +20,9 @@ interface Body { } interface FlatExpression { + type: string source: string - funcs: FuncNode[] -} - -interface FuncNode { - name: string - arguments: any[] - source: string + funcs: Func[] } interface AST { @@ -44,7 +40,7 @@ export default class Walker { return this.buildFuncNodes(this.walk(this.baseExpression)) } - public get stuff() { + public get body(): FlatBody[] { const body = _.get(this.ast, 'body', new Array
()) return body.map(b => { if (b.type.includes('Expression')) { @@ -74,6 +70,7 @@ export default class Walker { const funcs = this.buildFuncNodes(this.walk(expression)) return { + type: expression.type, source: location.source, funcs, } @@ -86,6 +83,7 @@ export default class Walker { const funcs = this.buildFuncNodes(this.walk(expression)) return { + type: expression.type, source: location.source, funcs, } @@ -122,11 +120,11 @@ export default class Walker { return [{name, args, source}] } - private buildFuncNodes = (nodes): FuncNode[] => { + private buildFuncNodes = (nodes): Func[] => { return nodes.map(({name, args, source}) => { return { name, - arguments: this.reduceArgs(args), + args: this.reduceArgs(args), source, } }) diff --git a/ui/src/ifql/components/BodyBuilder.tsx b/ui/src/ifql/components/BodyBuilder.tsx new file mode 100644 index 000000000..a0ca545bd --- /dev/null +++ b/ui/src/ifql/components/BodyBuilder.tsx @@ -0,0 +1,101 @@ +import React, {PureComponent} from 'react' +import _ from 'lodash' + +import FuncSelector from 'src/ifql/components/FuncSelector' +import FuncNode from 'src/ifql/components/FuncNode' +import { + FlatBody, + OnAddNode, + Suggestion, + OnChangeArg, + OnDeleteFuncNode, +} from 'src/types/ifql' + +interface Props { + body: Body[] + onAddNode: OnAddNode + onChangeArg: OnChangeArg + onDeleteFuncNode: OnDeleteFuncNode + suggestions: Suggestion[] + onGenerateScript: () => void +} + +interface Body extends FlatBody { + id: string +} + +class BodyBuilder extends PureComponent