Pass editQueryStatus as prop and refactor Visualization
parent
06bcaa9ba7
commit
b3d481f5c2
|
@ -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 <div className="generic-empty-state">Enter your query above</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table
|
||||||
|
query={query}
|
||||||
|
height={heightPixels}
|
||||||
|
editQueryStatus={editQueryStatus}
|
||||||
|
fetchTimeSeries={fetchTimeSeries}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cellType === 'single-stat') {
|
||||||
|
return <RefreshingSingleStat queries={[queries[0]]} autoRefresh={autoRefresh} />
|
||||||
|
}
|
||||||
|
|
||||||
|
const displayOptions = {
|
||||||
|
stepPlot: cellType === 'line-stepplot',
|
||||||
|
stackedGraph: cellType === 'line-stacked',
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<RefreshingLineGraph
|
||||||
|
queries={queries}
|
||||||
|
autoRefresh={autoRefresh}
|
||||||
|
activeQueryIndex={activeQueryIndex}
|
||||||
|
isInDataExplorer={true}
|
||||||
|
showSingleStat={cellType === "line-plus-single-stat"}
|
||||||
|
displayOptions={displayOptions}
|
||||||
|
fetchTimeSeries={fetchTimeSeries}
|
||||||
|
editQueryStatus={editQueryStatus}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
|
@ -1,14 +1,8 @@
|
||||||
import React, {PropTypes} from 'react'
|
import React, {PropTypes} from 'react'
|
||||||
import buildInfluxQLQuery from 'utils/influxql'
|
import buildInfluxQLQuery from 'utils/influxql'
|
||||||
import classNames from 'classnames'
|
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'
|
import VisHeader from 'src/data_explorer/components/VisHeader'
|
||||||
|
import View from 'src/data_explorer/components/View'
|
||||||
const RefreshingLineGraph = AutoRefresh(LineGraph)
|
|
||||||
const RefreshingSingleStat = AutoRefresh(SingleStat)
|
|
||||||
|
|
||||||
const GRAPH = 'graph'
|
const GRAPH = 'graph'
|
||||||
const TABLE = 'table'
|
const TABLE = 'table'
|
||||||
|
@ -36,6 +30,7 @@ const Visualization = React.createClass({
|
||||||
height: string,
|
height: string,
|
||||||
heightPixels: number,
|
heightPixels: number,
|
||||||
fetchTimeSeries: func.isRequired,
|
fetchTimeSeries: func.isRequired,
|
||||||
|
editQueryStatus: func,
|
||||||
},
|
},
|
||||||
|
|
||||||
contextTypes: {
|
contextTypes: {
|
||||||
|
@ -76,7 +71,17 @@ const Visualization = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
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 {source} = this.context
|
||||||
const proxyLink = source.links.proxy
|
const proxyLink = source.links.proxy
|
||||||
const {view} = this.state
|
const {view} = this.state
|
||||||
|
@ -93,52 +98,18 @@ const Visualization = React.createClass({
|
||||||
<div className="graph" style={{height}}>
|
<div className="graph" style={{height}}>
|
||||||
<VisHeader views={VIEWS} view={view} onToggleView={this.handleToggleView} name={name || 'Graph'}/>
|
<VisHeader views={VIEWS} view={view} onToggleView={this.handleToggleView} name={name || 'Graph'}/>
|
||||||
<div className={classNames({"graph-container": view === GRAPH, "table-container": view === TABLE})}>
|
<div className={classNames({"graph-container": view === GRAPH, "table-container": view === TABLE})}>
|
||||||
{this.renderVisualization(view, queries, heightPixels, fetchTimeSeries, activeQueryIndex)}
|
<View
|
||||||
</div>
|
view={view}
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
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 <div className="generic-empty-state">Enter your query above</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Table query={query} height={heightPixels} fetchTimeSeries={fetchTimeSeries} />
|
|
||||||
},
|
|
||||||
|
|
||||||
renderGraph(queries) {
|
|
||||||
const {cellType, autoRefresh, activeQueryIndex} = this.props
|
|
||||||
const isInDataExplorer = true
|
|
||||||
|
|
||||||
if (cellType === 'single-stat') {
|
|
||||||
return <RefreshingSingleStat queries={[queries[0]]} autoRefresh={autoRefresh} />
|
|
||||||
}
|
|
||||||
|
|
||||||
const displayOptions = {
|
|
||||||
stepPlot: cellType === 'line-stepplot',
|
|
||||||
stackedGraph: cellType === 'line-stacked',
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<RefreshingLineGraph
|
|
||||||
queries={queries}
|
queries={queries}
|
||||||
|
cellType={cellType}
|
||||||
autoRefresh={autoRefresh}
|
autoRefresh={autoRefresh}
|
||||||
|
heightPixels={heightPixels}
|
||||||
|
editQueryStatus={editQueryStatus}
|
||||||
|
fetchTimeSeries={fetchTimeSeries}
|
||||||
activeQueryIndex={activeQueryIndex}
|
activeQueryIndex={activeQueryIndex}
|
||||||
isInDataExplorer={isInDataExplorer}
|
|
||||||
showSingleStat={cellType === "line-plus-single-stat"}
|
|
||||||
displayOptions={displayOptions}
|
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,6 +11,7 @@ import ResizeContainer, {ResizeBottom} from 'src/shared/components/ResizeContain
|
||||||
|
|
||||||
import {setAutoRefresh} from 'shared/actions/app'
|
import {setAutoRefresh} from 'shared/actions/app'
|
||||||
import {fetchTimeSeriesAsync} from 'shared/actions/timeSeries'
|
import {fetchTimeSeriesAsync} from 'shared/actions/timeSeries'
|
||||||
|
import {editQueryStatus} from 'src/data_explorer/actions/view'
|
||||||
import * as viewActions from 'src/data_explorer/actions/view'
|
import * as viewActions from 'src/data_explorer/actions/view'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -112,8 +113,8 @@ const DataExplorer = React.createClass({
|
||||||
timeRange={timeRange}
|
timeRange={timeRange}
|
||||||
queryConfigs={queryConfigs}
|
queryConfigs={queryConfigs}
|
||||||
activeQueryIndex={activeQueryIndex}
|
activeQueryIndex={activeQueryIndex}
|
||||||
onEditRawStatus={queryConfigActions.editRawQueryStatus}
|
|
||||||
fetchTimeSeries={fetchTimeSeries}
|
fetchTimeSeries={fetchTimeSeries}
|
||||||
|
editQueryStatus={editQueryStatus}
|
||||||
/>
|
/>
|
||||||
</ResizeBottom>
|
</ResizeBottom>
|
||||||
</ResizeContainer>
|
</ResizeContainer>
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import {proxy} from 'utils/queryUrlGenerator'
|
import {proxy} from 'utils/queryUrlGenerator'
|
||||||
import {editQueryStatus} from 'src/data_explorer/actions/view'
|
|
||||||
import _ from 'lodash'
|
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}))
|
dispatch(editQueryStatus(query.id, {loading: true}))
|
||||||
}
|
}
|
||||||
// {results: [{}]}
|
// {results: [{}]}
|
||||||
export const handleSuccess = (data, query, dispatch) => {
|
export const handleSuccess = (data, query, editQueryStatus, dispatch) => {
|
||||||
const {results} = data
|
const {results} = data
|
||||||
const error = _.get(results, ['0', 'error'], false)
|
const error = _.get(results, ['0', 'error'], false)
|
||||||
const series = _.get(results, ['0', 'series'], false)
|
const series = _.get(results, ['0', 'series'], false)
|
||||||
|
@ -27,7 +30,7 @@ export const handleSuccess = (data, query, dispatch) => {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handleError = (error, query, dispatch) => {
|
export const handleError = (error, query, editQueryStatus, dispatch) => {
|
||||||
const message = _.get(error, ['data', 'message'], error)
|
const message = _.get(error, ['data', 'message'], error)
|
||||||
|
|
||||||
// 400 from chrono server = fail
|
// 400 from chrono server = fail
|
||||||
|
@ -35,13 +38,13 @@ export const handleError = (error, query, dispatch) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchTimeSeriesAsync = ({source, db, rp, query}) => async (dispatch) => {
|
export const fetchTimeSeriesAsync = ({source, db, rp, query}, editQueryStatus = NOOP) => async (dispatch) => {
|
||||||
handleLoading(query, dispatch)
|
handleLoading(query, editQueryStatus, dispatch)
|
||||||
try {
|
try {
|
||||||
const {data} = await proxy({source, db, rp, query: query.text})
|
const {data} = await proxy({source, db, rp, query: query.text})
|
||||||
return handleSuccess(data, query, dispatch)
|
return handleSuccess(data, query, editQueryStatus, dispatch)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, query, dispatch)
|
handleError(error, query, editQueryStatus, dispatch)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ const AutoRefresh = (ComposedComponent) => {
|
||||||
text: string,
|
text: string,
|
||||||
}).isRequired).isRequired,
|
}).isRequired).isRequired,
|
||||||
fetchTimeSeries: func.isRequired,
|
fetchTimeSeries: func.isRequired,
|
||||||
|
editQueryStatus: func,
|
||||||
},
|
},
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
|
@ -72,7 +73,7 @@ const AutoRefresh = (ComposedComponent) => {
|
||||||
const newSeries = []
|
const newSeries = []
|
||||||
for (const query of queries) {
|
for (const query of queries) {
|
||||||
const {host, database, rp} = query
|
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})
|
newSeries.push({response})
|
||||||
count += 1
|
count += 1
|
||||||
if (count === queries.length) {
|
if (count === queries.length) {
|
||||||
|
|
Loading…
Reference in New Issue