From d8ed336248a48c0dec482079bf9a36c22366e73d Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Thu, 24 May 2018 09:37:17 -0700 Subject: [PATCH] Automatically select table on initial render --- ui/src/ifql/components/TimeMachineTable.tsx | 2 +- ui/src/ifql/components/TimeMachineVis.tsx | 15 +++++++++++++-- ui/src/ifql/containers/CheckServices.tsx | 4 ++++ ui/src/ifql/containers/IFQLPage.tsx | 1 + ui/src/shared/parsing/ifql.ts | 6 +++--- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ui/src/ifql/components/TimeMachineTable.tsx b/ui/src/ifql/components/TimeMachineTable.tsx index 6a97764415..c90edeb6ac 100644 --- a/ui/src/ifql/components/TimeMachineTable.tsx +++ b/ui/src/ifql/components/TimeMachineTable.tsx @@ -37,7 +37,7 @@ export default class TimeMachineTable extends PureComponent { }: GridCellProps): React.ReactNode => { const {data} = this.props return ( -
+
{data[rowIndex][columnIndex]}
) diff --git a/ui/src/ifql/components/TimeMachineVis.tsx b/ui/src/ifql/components/TimeMachineVis.tsx index db1400d360..75c335945d 100644 --- a/ui/src/ifql/components/TimeMachineVis.tsx +++ b/ui/src/ifql/components/TimeMachineVis.tsx @@ -1,4 +1,5 @@ import React, {PureComponent, CSSProperties} from 'react' +import _ from 'lodash' import {ErrorHandling} from 'src/shared/decorators/errors' import {ScriptResult, ScriptStatus} from 'src/types' @@ -20,7 +21,13 @@ class TimeMachineVis extends PureComponent { constructor(props) { super(props) - this.state = {selectedResultID: null} + this.state = {selectedResultID: this.initialResultID} + } + + public componentDidUpdate(__, prevState) { + if (prevState.selectedResultID === null) { + this.setState({selectedResultID: this.initialResultID}) + } } public render() { @@ -40,6 +47,10 @@ class TimeMachineVis extends PureComponent { ) } + private get initialResultID(): string { + return _.get(this.props.data, '0.id', null) + } + private handleSelectResult = (selectedResultID: string): void => { this.setState({selectedResultID}) } @@ -51,7 +62,7 @@ class TimeMachineVis extends PureComponent { } private get shouldShowTable(): boolean { - return !!this.selectedResult + return !!this.props.data && !!this.selectedResult } private get selectedResult(): ScriptResult { diff --git a/ui/src/ifql/containers/CheckServices.tsx b/ui/src/ifql/containers/CheckServices.tsx index e7951749ce..fc49e04643 100644 --- a/ui/src/ifql/containers/CheckServices.tsx +++ b/ui/src/ifql/containers/CheckServices.tsx @@ -36,6 +36,10 @@ export class CheckServices extends PureComponent { } public render() { + if (!this.props.services.length) { + return null + } + return this.props.children } diff --git a/ui/src/ifql/containers/IFQLPage.tsx b/ui/src/ifql/containers/IFQLPage.tsx index 3c88744dee..831cbb3a86 100644 --- a/ui/src/ifql/containers/IFQLPage.tsx +++ b/ui/src/ifql/containers/IFQLPage.tsx @@ -93,6 +93,7 @@ export class IFQLPage extends PureComponent { } this.getASTResponse(script) + this.getTimeSeries() } public render() { diff --git a/ui/src/shared/parsing/ifql.ts b/ui/src/shared/parsing/ifql.ts index 4baa51a786..691ac1e120 100644 --- a/ui/src/shared/parsing/ifql.ts +++ b/ui/src/shared/parsing/ifql.ts @@ -4,10 +4,10 @@ import uuid from 'uuid' import {ScriptResult} from 'src/types' -export const parseResults = (resp: string): ScriptResult[] => { - return resp +export const parseResults = (response: string): ScriptResult[] => { + return response .trim() - .split('\n\n') + .split(/\n\s*\n/) .map(parseResult) }