From 2d1ff2cf46351d9c09ada82f74e2d82afcc70357 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Thu, 10 May 2018 10:48:36 -0700 Subject: [PATCH] Fix up type errors --- ui/src/ifql/ast/walker.ts | 11 ++--------- ui/src/ifql/components/Filter.tsx | 2 +- ui/src/ifql/components/FilterBuilder.tsx | 4 ++-- ui/src/types/ifql.ts | 3 ++- ui/test/ifql/components/Filter.test.tsx | 3 +++ 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ui/src/ifql/ast/walker.ts b/ui/src/ifql/ast/walker.ts index 7acab68a1..193a3e80c 100644 --- a/ui/src/ifql/ast/walker.ts +++ b/ui/src/ifql/ast/walker.ts @@ -106,7 +106,6 @@ export default class Walker { object: {name: object.name, type: object.type}, property: {name: name || value, type}, type: node.type, - paren, }, ] } @@ -116,17 +115,11 @@ export default class Walker { } if (node.name) { - results = [ - ...results, - {type: node.type, source: node.location.source, paren}, - ] + results = [...results, {type: node.type, source: node.location.source}] } if (node.value) { - results = [ - ...results, - {type: node.type, source: node.location.source, paren}, - ] + results = [...results, {type: node.type, source: node.location.source}] } const isRightParen = this.hasParen(node, node.right) diff --git a/ui/src/ifql/components/Filter.tsx b/ui/src/ifql/components/Filter.tsx index b7e8d7fea..dd2ca8d6f 100644 --- a/ui/src/ifql/components/Filter.tsx +++ b/ui/src/ifql/components/Filter.tsx @@ -29,7 +29,7 @@ export class Filter extends PureComponent { try { const ast = await getAST({url: links.ast, body: value}) const nodes = new Walker(ast).inOrderExpression - this.setState({nodes}, () => console.log(this.state.nodes)) + this.setState({nodes}) } catch (error) { console.error('Could not parse AST', error) } diff --git a/ui/src/ifql/components/FilterBuilder.tsx b/ui/src/ifql/components/FilterBuilder.tsx index 29772c9da..1e3f57b3a 100644 --- a/ui/src/ifql/components/FilterBuilder.tsx +++ b/ui/src/ifql/components/FilterBuilder.tsx @@ -1,7 +1,7 @@ import React, {PureComponent} from 'react' -import {BinaryExpressionNode, MemberExpressionNode} from 'src/types/ifql' +import {MemberExpressionNode} from 'src/types/ifql' -type FilterNode = BinaryExpressionNode | MemberExpressionNode +type FilterNode = MemberExpressionNode interface Props { nodes: FilterNode[] diff --git a/ui/src/types/ifql.ts b/ui/src/types/ifql.ts index 09c980b51..1792b1744 100644 --- a/ui/src/types/ifql.ts +++ b/ui/src/types/ifql.ts @@ -46,7 +46,8 @@ interface ObjectNode { } interface PropertyNode { - value: string + name?: string + value?: string type: string } diff --git a/ui/test/ifql/components/Filter.test.tsx b/ui/test/ifql/components/Filter.test.tsx index 2330f535b..83c1d423e 100644 --- a/ui/test/ifql/components/Filter.test.tsx +++ b/ui/test/ifql/components/Filter.test.tsx @@ -2,6 +2,8 @@ import React from 'react' import {shallow} from 'enzyme' import {Filter} from 'src/ifql/components/Filter' +jest.mock('src/ifql/apis', () => require('mocks/ifql/apis')) + const setup = (override = {}) => { const props = { argKey: 'fn', @@ -10,6 +12,7 @@ const setup = (override = {}) => { declarationID: 'd1', value: '(r) => r["measurement"] === "m1"', onChangeArg: () => {}, + render: () =>
, links: { self: '', ast: '',