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: {