diff --git a/ui/src/ifql/components/BodyBuilder.tsx b/ui/src/ifql/components/BodyBuilder.tsx index 1a65874909..0e733e54aa 100644 --- a/ui/src/ifql/components/BodyBuilder.tsx +++ b/ui/src/ifql/components/BodyBuilder.tsx @@ -12,6 +12,7 @@ interface Props { body: Body[] suggestions: Suggestion[] onAppendFrom: () => void + onAppendJoin: () => void } interface Body extends FlatBody { diff --git a/ui/src/ifql/components/TimeMachine.tsx b/ui/src/ifql/components/TimeMachine.tsx index 8119966a7a..8e56d0e405 100644 --- a/ui/src/ifql/components/TimeMachine.tsx +++ b/ui/src/ifql/components/TimeMachine.tsx @@ -23,6 +23,7 @@ interface Props { onChangeScript: OnChangeScript onSubmitScript: OnSubmitScript onAppendFrom: () => void + onAppendJoin: () => void onAnalyze: () => void } @@ -73,6 +74,7 @@ class TimeMachine extends PureComponent { onAnalyze, suggestions, onAppendFrom, + onAppendJoin, onChangeScript, onSubmitScript, } = this.props @@ -119,6 +121,7 @@ class TimeMachine extends PureComponent { body={body} suggestions={suggestions} onAppendFrom={onAppendFrom} + onAppendJoin={onAppendJoin} /> ), }, diff --git a/ui/src/ifql/constants/builder.ts b/ui/src/ifql/constants/builder.ts index 752966cb91..f57aba1c26 100644 --- a/ui/src/ifql/constants/builder.ts +++ b/ui/src/ifql/constants/builder.ts @@ -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"])` diff --git a/ui/src/ifql/containers/IFQLPage.tsx b/ui/src/ifql/containers/IFQLPage.tsx index 5981b9c89d..0df31bcb74 100644 --- a/ui/src/ifql/containers/IFQLPage.tsx +++ b/ui/src/ifql/containers/IFQLPage.tsx @@ -102,6 +102,7 @@ export class IFQLPage extends PureComponent { 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 { 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}) } diff --git a/ui/test/ifql/components/TimeMachine.test.tsx b/ui/test/ifql/components/TimeMachine.test.tsx index b32c918c6d..6d32cec0c9 100644 --- a/ui/test/ifql/components/TimeMachine.test.tsx +++ b/ui/test/ifql/components/TimeMachine.test.tsx @@ -13,6 +13,7 @@ const setup = () => { onChangeScript: () => {}, onAnalyze: () => {}, onAppendFrom: () => {}, + onAppendJoin: () => {}, } const wrapper = shallow()