Add append handlers for join function

pull/10616/head
ebb-tide 2018-05-17 12:46:05 -07:00 committed by Andrew Watkins
parent 149cd4a27f
commit 8abf433a6e
5 changed files with 14 additions and 0 deletions

View File

@ -12,6 +12,7 @@ interface Props {
body: Body[]
suggestions: Suggestion[]
onAppendFrom: () => void
onAppendJoin: () => void
}
interface Body extends FlatBody {

View File

@ -23,6 +23,7 @@ interface Props {
onChangeScript: OnChangeScript
onSubmitScript: OnSubmitScript
onAppendFrom: () => void
onAppendJoin: () => void
onAnalyze: () => void
}
@ -73,6 +74,7 @@ class TimeMachine extends PureComponent<Props> {
onAnalyze,
suggestions,
onAppendFrom,
onAppendJoin,
onChangeScript,
onSubmitScript,
} = this.props
@ -119,6 +121,7 @@ class TimeMachine extends PureComponent<Props> {
body={body}
suggestions={suggestions}
onAppendFrom={onAppendFrom}
onAppendJoin={onAppendJoin}
/>
),
},

View File

@ -1 +1,2 @@
export const NEW_FROM = `from(db: "pick a db")\n\t|> filter(fn: (r) => r.tag == "value")\n\t|> range(start: -1m)`
export const NEW_JOIN = `join(tables: {table1:table1, table2:table2}, on:["host"], fn: (tables) => tables.table1["_value"] + tables.table2["_value"])`

View File

@ -102,6 +102,7 @@ export class IFQLPage extends PureComponent<Props, State> {
suggestions={suggestions}
onAnalyze={this.handleAnalyze}
onAppendFrom={this.handleAppendFrom}
onAppendJoin={this.handleAppendJoin}
onChangeScript={this.handleChangeScript}
onSubmitScript={this.handleSubmitScript}
/>
@ -249,6 +250,13 @@ export class IFQLPage extends PureComponent<Props, State> {
this.getASTResponse(newScript)
}
private handleAppendJoin = (): void => {
const {script} = this.state
const newScript = `${script.trim()}\n\n${builder.NEW_JOIN}\n\n`
this.getASTResponse(newScript)
}
private handleChangeScript = (script: string): void => {
this.setState({script})
}

View File

@ -13,6 +13,7 @@ const setup = () => {
onChangeScript: () => {},
onAnalyze: () => {},
onAppendFrom: () => {},
onAppendJoin: () => {},
}
const wrapper = shallow(<TimeMachine {...props} />)