From de1b7caa632f212205467eedac48ea22a8277a13 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Fri, 23 Mar 2018 15:50:20 -0700 Subject: [PATCH] Get suggestions for functions --- ui/mocks/ifql/apis/index.ts | 1 + ui/src/ifql/containers/IFQLPage.tsx | 24 ++++++++++++++++++++++- ui/test/ifql/containers/IFQLPage.test.tsx | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 ui/mocks/ifql/apis/index.ts diff --git a/ui/mocks/ifql/apis/index.ts b/ui/mocks/ifql/apis/index.ts new file mode 100644 index 0000000000..ab05318610 --- /dev/null +++ b/ui/mocks/ifql/apis/index.ts @@ -0,0 +1 @@ +export const getSuggestions = jest.fn(() => Promise.resolve({data: []})) diff --git a/ui/src/ifql/containers/IFQLPage.tsx b/ui/src/ifql/containers/IFQLPage.tsx index 0bcd6c41cb..9aa0366be7 100644 --- a/ui/src/ifql/containers/IFQLPage.tsx +++ b/ui/src/ifql/containers/IFQLPage.tsx @@ -1,7 +1,11 @@ import React, {PureComponent} from 'react' -import TimeMachine from 'src/ifql/components/TimeMachine' + import {connect} from 'react-redux' +import TimeMachine from 'src/ifql/components/TimeMachine' + +import {getSuggestions} from 'src/ifql/apis' + interface Links { self: string suggestions: string @@ -12,6 +16,24 @@ interface Props { } export class IFQLPage extends PureComponent { + constructor(props) { + super(props) + this.state = { + funcs: [], + } + } + + public async componentDidMount() { + const {suggestions} = this.props.links + + try { + const {data} = await getSuggestions(suggestions) + this.setState({funcs: data}) + } catch (error) { + console.error('Could not get function suggestions: ', error) + } + } + public render() { return (
diff --git a/ui/test/ifql/containers/IFQLPage.test.tsx b/ui/test/ifql/containers/IFQLPage.test.tsx index 90bd2808fb..b7d28bdf19 100644 --- a/ui/test/ifql/containers/IFQLPage.test.tsx +++ b/ui/test/ifql/containers/IFQLPage.test.tsx @@ -4,6 +4,8 @@ import {shallow} from 'enzyme' import {IFQLPage} from 'src/ifql/containers/IFQLPage' import TimeMachine from 'src/ifql/components/TimeMachine' +jest.mock('src/ifql/apis', () => require('mocks/ifql/apis')) + const setup = () => { const props = { links: {