WIP FilterPreview

pull/10616/head
Andrew Watkins 2018-05-09 11:06:25 -07:00
parent acc84cccc4
commit 470d0ee256
8 changed files with 63 additions and 47 deletions

View File

@ -68,7 +68,10 @@ export default class Walker {
if (node) { if (node) {
results = [...results, ...this.inOrder(node.left)] results = [...results, ...this.inOrder(node.left)]
if (node.type === 'MemberExpression') { if (
node.type === 'MemberExpression' ||
node.type === 'ObjectExpression'
) {
const {location, object, property} = node const {location, object, property} = node
const {name} = object const {name} = object
const {value, type} = property const {value, type} = property

View File

@ -1,22 +1,13 @@
import React, {PureComponent} from 'react' import {PureComponent, ReactNode} from 'react'
import {connect} from 'react-redux' import {connect} from 'react-redux'
import {getAST} from 'src/ifql/apis' import {getAST} from 'src/ifql/apis'
import { import {Links, BinaryExpressionNode, MemberExpressionNode} from 'src/types/ifql'
Links,
OnChangeArg,
BinaryExpressionNode,
MemberExpressionNode,
} from 'src/types/ifql'
import Walker from 'src/ifql/ast/walker' import Walker from 'src/ifql/ast/walker'
interface Props { interface Props {
argKey: string
funcID: string
bodyID: string
declarationID: string
value: string value: string
onChangeArg: OnChangeArg
links: Links links: Links
render: (nodes: FilterNode[]) => ReactNode
} }
type FilterNode = BinaryExpressionNode | MemberExpressionNode type FilterNode = BinaryExpressionNode | MemberExpressionNode
@ -45,17 +36,7 @@ export class Filter extends PureComponent<Props, State> {
} }
public render() { public render() {
const {argKey} = this.props return this.props.render(this.state.nodes)
const {nodes} = this.state
return (
<div className="func-arg">
<label className="func-arg--label">{argKey}</label>
{nodes.map((n, i) => {
return <div key={i}>{n.source}</div>
})}
</div>
)
} }
} }

View File

@ -0,0 +1,16 @@
import React, {PureComponent} from 'react'
import {BinaryExpressionNode, MemberExpressionNode} from 'src/types/ifql'
type FilterNode = BinaryExpressionNode | MemberExpressionNode
interface Props {
nodes: FilterNode[]
}
class FilterPreview extends PureComponent<Props> {
public render() {
return this.props.nodes.map((n, i) => <div key={i}>{n.source}</div>)
}
}
export default FilterPreview

View File

@ -50,16 +50,7 @@ class FuncArg extends PureComponent<Props> {
} }
if (funcName === funcNames.FILTER) { if (funcName === funcNames.FILTER) {
return ( return <Filter value={this.value} render={this.filter} />
<Filter
argKey={argKey}
funcID={funcID}
bodyID={bodyID}
value={this.value}
declarationID={declarationID}
onChangeArg={onChangeArg}
/>
)
} }
switch (type) { switch (type) {
@ -127,6 +118,11 @@ class FuncArg extends PureComponent<Props> {
} }
} }
private filter = nodes => {
console.log(nodes)
return null
}
private get value(): string { private get value(): string {
return this.props.value.toString() return this.props.value.toString()
} }

View File

@ -1,9 +1,15 @@
import React, {PureComponent} from 'react' import React, {PureComponent} from 'react'
import {Arg} from 'src/types/ifql' import _ from 'lodash'
import {Func} from 'src/types/ifql'
import {funcNames} from 'src/ifql/constants'
import Filter from 'src/ifql/components/Filter'
import FilterPreview from 'src/ifql/components/FilterPreview'
import uuid from 'uuid' import uuid from 'uuid'
interface Props { interface Props {
args: Arg[] func: Func
} }
export default class FuncArgsPreview extends PureComponent<Props> { export default class FuncArgsPreview extends PureComponent<Props> {
@ -12,17 +18,32 @@ export default class FuncArgsPreview extends PureComponent<Props> {
} }
private get summarizeArguments(): JSX.Element | JSX.Element[] { private get summarizeArguments(): JSX.Element | JSX.Element[] {
const {args} = this.props const {func} = this.props
const {args} = func
if (!args) { if (!args) {
return return
} }
if (func.name === funcNames.FILTER) {
const value = _.get(args, '0.value', '')
if (!value) {
return this.colorizedArguments
}
return <Filter value={value} render={this.filterPreview} />
}
return this.colorizedArguments return this.colorizedArguments
} }
private filterPreview = nodes => {
return <FilterPreview nodes={nodes} />
}
private get colorizedArguments(): JSX.Element | JSX.Element[] { private get colorizedArguments(): JSX.Element | JSX.Element[] {
const {args} = this.props const {func} = this.props
const {args} = func
return args.map((arg, i): JSX.Element => { return args.map((arg, i): JSX.Element => {
if (!arg.value) { if (!arg.value) {

View File

@ -34,7 +34,6 @@ export default class FuncNode extends PureComponent<Props, State> {
public render() { public render() {
const { const {
func, func,
func: {args},
bodyID, bodyID,
onChangeArg, onChangeArg,
declarationID, declarationID,
@ -49,7 +48,7 @@ export default class FuncNode extends PureComponent<Props, State> {
onMouseLeave={this.handleMouseLeave} onMouseLeave={this.handleMouseLeave}
> >
<div className="func-node--name">{func.name}</div> <div className="func-node--name">{func.name}</div>
<FuncArgsPreview args={args} /> <FuncArgsPreview func={func} />
{isExpanded && ( {isExpanded && (
<FuncArgs <FuncArgs
func={func} func={func}

View File

@ -52,6 +52,10 @@ class TimeMachine extends PureComponent<Props> {
private get divisions() { private get divisions() {
const {body, suggestions, script, onChangeScript} = this.props const {body, suggestions, script, onChangeScript} = this.props
return [ return [
{
name: 'Explore',
render: () => <SchemaExplorer />,
},
{ {
name: 'Script', name: 'Script',
render: () => ( render: () => (
@ -62,10 +66,6 @@ class TimeMachine extends PureComponent<Props> {
name: 'Build', name: 'Build',
render: () => <BodyBuilder body={body} suggestions={suggestions} />, render: () => <BodyBuilder body={body} suggestions={suggestions} />,
}, },
{
name: 'Explore',
render: () => <SchemaExplorer />,
},
] ]
} }
} }

View File

@ -39,9 +39,9 @@ export class IFQLPage extends PureComponent<Props, State> {
ast: null, ast: null,
suggestions: [], suggestions: [],
script: `from(db:"foo") script: `from(db:"foo")
|> filter(fn: (r) => r["_measurement"]=="cpu" AND |> filter(fn: (r) => r._measurement =="cpu" AND
r["_field"] == "usage_system" AND r["_field"] == "usage_system" AND
r["service"] == "app-server")`, r["service"] == "app-server")`,
} }
} }