diff --git a/ui/src/data_explorer/components/View.js b/ui/src/data_explorer/components/View.js new file mode 100644 index 0000000000..e7ebbba894 --- /dev/null +++ b/ui/src/data_explorer/components/View.js @@ -0,0 +1,81 @@ +import React, {PropTypes} from 'react' + +import Table from './Table' +import AutoRefresh from 'shared/components/AutoRefresh' +import LineGraph from 'shared/components/LineGraph' +import SingleStat from 'shared/components/SingleStat' +const RefreshingLineGraph = AutoRefresh(LineGraph) +const RefreshingSingleStat = AutoRefresh(SingleStat) + +const View = ({ + view, + queries, + cellType, + autoRefresh, + heightPixels, + editQueryStatus, + fetchTimeSeries, + activeQueryIndex, +}) => { + const activeQuery = queries[activeQueryIndex] + const defaultQuery = queries[0] + const query = activeQuery || defaultQuery + + if (view === 'table') { + if (!query) { + return
Enter your query above
+ } + + return ( + + ) + } + + if (cellType === 'single-stat') { + return + } + + const displayOptions = { + stepPlot: cellType === 'line-stepplot', + stackedGraph: cellType === 'line-stacked', + } + + return ( + + ) +} + +const { + arrayOf, + func, + number, + shape, + string, +} = PropTypes + +View.propTypes = { + view: string.isRequired, + queries: arrayOf(shape()).isRequired, + cellType: string, + autoRefresh: number.isRequired, + heightPixels: number, + editQueryStatus: func, + fetchTimeSeries: func.isRequired, + activeQueryIndex: number, +} + +export default View diff --git a/ui/src/data_explorer/components/Visualization.js b/ui/src/data_explorer/components/Visualization.js index 1cfb38b0b9..ff2237cd14 100644 --- a/ui/src/data_explorer/components/Visualization.js +++ b/ui/src/data_explorer/components/Visualization.js @@ -1,14 +1,8 @@ import React, {PropTypes} from 'react' import buildInfluxQLQuery from 'utils/influxql' import classNames from 'classnames' -import AutoRefresh from 'shared/components/AutoRefresh' -import LineGraph from 'shared/components/LineGraph' -import SingleStat from 'shared/components/SingleStat' -import Table from './Table' import VisHeader from 'src/data_explorer/components/VisHeader' - -const RefreshingLineGraph = AutoRefresh(LineGraph) -const RefreshingSingleStat = AutoRefresh(SingleStat) +import View from 'src/data_explorer/components/View' const GRAPH = 'graph' const TABLE = 'table' @@ -36,6 +30,7 @@ const Visualization = React.createClass({ height: string, heightPixels: number, fetchTimeSeries: func.isRequired, + editQueryStatus: func, }, contextTypes: { @@ -76,7 +71,17 @@ const Visualization = React.createClass({ }, render() { - const {queryConfigs, timeRange, height, heightPixels, fetchTimeSeries, activeQueryIndex} = this.props + const { + height, + cellType, + timeRange, + autoRefresh, + heightPixels, + queryConfigs, + editQueryStatus, + fetchTimeSeries, + activeQueryIndex, + } = this.props const {source} = this.context const proxyLink = source.links.proxy const {view} = this.state @@ -93,54 +98,20 @@ const Visualization = React.createClass({
- {this.renderVisualization(view, queries, heightPixels, fetchTimeSeries, activeQueryIndex)} +
) }, - - renderVisualization(view, queries, heightPixels, fetchTimeSeries, activeQueryIndex) { - const activeQuery = queries[activeQueryIndex] - const defaultQuery = queries[0] - - if (view === TABLE) { - return this.renderTable(activeQuery || defaultQuery, heightPixels, fetchTimeSeries) - } - - return this.renderGraph(queries) - }, - - renderTable(query, heightPixels, fetchTimeSeries) { - if (!query) { - return
Enter your query above
- } - - return
- }, - - renderGraph(queries) { - const {cellType, autoRefresh, activeQueryIndex} = this.props - const isInDataExplorer = true - - if (cellType === 'single-stat') { - return - } - - const displayOptions = { - stepPlot: cellType === 'line-stepplot', - stackedGraph: cellType === 'line-stacked', - } - return ( - - ) - }, }) export default Visualization diff --git a/ui/src/data_explorer/containers/DataExplorer.js b/ui/src/data_explorer/containers/DataExplorer.js index 054107e610..b1a4bb8109 100644 --- a/ui/src/data_explorer/containers/DataExplorer.js +++ b/ui/src/data_explorer/containers/DataExplorer.js @@ -11,6 +11,7 @@ import ResizeContainer, {ResizeBottom} from 'src/shared/components/ResizeContain import {setAutoRefresh} from 'shared/actions/app' import {fetchTimeSeriesAsync} from 'shared/actions/timeSeries' +import {editQueryStatus} from 'src/data_explorer/actions/view' import * as viewActions from 'src/data_explorer/actions/view' const { @@ -112,8 +113,8 @@ const DataExplorer = React.createClass({ timeRange={timeRange} queryConfigs={queryConfigs} activeQueryIndex={activeQueryIndex} - onEditRawStatus={queryConfigActions.editRawQueryStatus} fetchTimeSeries={fetchTimeSeries} + editQueryStatus={editQueryStatus} /> diff --git a/ui/src/shared/actions/timeSeries.js b/ui/src/shared/actions/timeSeries.js index 169ab15330..b506071665 100644 --- a/ui/src/shared/actions/timeSeries.js +++ b/ui/src/shared/actions/timeSeries.js @@ -1,12 +1,15 @@ import {proxy} from 'utils/queryUrlGenerator' -import {editQueryStatus} from 'src/data_explorer/actions/view' import _ from 'lodash' -export const handleLoading = (query, dispatch) => { +const NOOP = () => ({ + type: 'I_NEED_TO_EDIT_QUERY_STATUS', +}) + +export const handleLoading = (query, editQueryStatus, dispatch) => { dispatch(editQueryStatus(query.id, {loading: true})) } // {results: [{}]} -export const handleSuccess = (data, query, dispatch) => { +export const handleSuccess = (data, query, editQueryStatus, dispatch) => { const {results} = data const error = _.get(results, ['0', 'error'], false) const series = _.get(results, ['0', 'series'], false) @@ -27,7 +30,7 @@ export const handleSuccess = (data, query, dispatch) => { return data } -export const handleError = (error, query, dispatch) => { +export const handleError = (error, query, editQueryStatus, dispatch) => { const message = _.get(error, ['data', 'message'], error) // 400 from chrono server = fail @@ -35,13 +38,13 @@ export const handleError = (error, query, dispatch) => { console.error(error) } -export const fetchTimeSeriesAsync = ({source, db, rp, query}) => async (dispatch) => { - handleLoading(query, dispatch) +export const fetchTimeSeriesAsync = ({source, db, rp, query}, editQueryStatus = NOOP) => async (dispatch) => { + handleLoading(query, editQueryStatus, dispatch) try { const {data} = await proxy({source, db, rp, query: query.text}) - return handleSuccess(data, query, dispatch) + return handleSuccess(data, query, editQueryStatus, dispatch) } catch (error) { - handleError(error, query, dispatch) + handleError(error, query, editQueryStatus, dispatch) throw error } } diff --git a/ui/src/shared/components/AutoRefresh.js b/ui/src/shared/components/AutoRefresh.js index 2fc68d1609..47073f052a 100644 --- a/ui/src/shared/components/AutoRefresh.js +++ b/ui/src/shared/components/AutoRefresh.js @@ -25,6 +25,7 @@ const AutoRefresh = (ComposedComponent) => { text: string, }).isRequired).isRequired, fetchTimeSeries: func.isRequired, + editQueryStatus: func, }, getInitialState() { return { @@ -72,7 +73,7 @@ const AutoRefresh = (ComposedComponent) => { const newSeries = [] for (const query of queries) { const {host, database, rp} = query - const response = await this.props.fetchTimeSeries({source: host, db: database, rp, query}) + const response = await this.props.fetchTimeSeries({source: host, db: database, rp, query}, this.props.editQueryStatus) newSeries.push({response}) count += 1 if (count === queries.length) {