Merge pull request #306 from influxdata/feature/241-time-selector

Feature/241 time selector
pull/10616/head
Rachel McGough 2016-11-01 10:52:53 -07:00 committed by GitHub
commit 0a8285b638
5 changed files with 26 additions and 7 deletions

View File

@ -1,8 +1,8 @@
import React, {PropTypes} from 'react'; import React, {PropTypes} from 'react';
import moment from 'moment'; import moment from 'moment';
import {withRouter} from 'react-router'; import {withRouter} from 'react-router';
import TimeRangeDropdown from '../components/TimeRangeDropdown'; import TimeRangeDropdown from '../../shared/components/TimeRangeDropdown';
import timeRanges from 'hson!../data/timeRanges.hson'; import timeRanges from 'hson!../../shared/data/timeRanges.hson';
import Dropdown from 'shared/components/Dropdown'; import Dropdown from 'shared/components/Dropdown';
const Header = React.createClass({ const Header = React.createClass({

View File

@ -8,6 +8,7 @@ const RefreshingLineGraph = AutoRefresh(LineGraph);
export const LayoutRenderer = React.createClass({ export const LayoutRenderer = React.createClass({
propTypes: { propTypes: {
timeRange: PropTypes.string.isRequired,
cells: PropTypes.arrayOf( cells: PropTypes.arrayOf(
PropTypes.shape({ PropTypes.shape({
queries: PropTypes.arrayOf( queries: PropTypes.arrayOf(
@ -37,10 +38,12 @@ export const LayoutRenderer = React.createClass({
}, },
generateGraphs() { generateGraphs() {
const {timeRange, host, autoRefreshMs, source} = this.props;
return this.props.cells.map((cell) => { return this.props.cells.map((cell) => {
const qs = cell.queries.map((q) => { const qs = cell.queries.map((q) => {
_.merge(q, {host: this.props.source}); _.merge(q, {host: source});
q.text += ` where host = '${this.props.host}' and time > now() - 15m`; q.text += ` where host = '${host}' and time > ${timeRange}`;
return q; return q;
}); });
return ( return (
@ -49,7 +52,7 @@ export const LayoutRenderer = React.createClass({
<div className="hosts-graph graph-panel__graph-container"> <div className="hosts-graph graph-panel__graph-container">
<RefreshingLineGraph <RefreshingLineGraph
queries={qs} queries={qs}
autoRefresh={this.props.autoRefreshMs} autoRefresh={autoRefreshMs}
/> />
</div> </div>
</div> </div>

View File

@ -1,6 +1,7 @@
import React, {PropTypes} from 'react'; import React, {PropTypes} from 'react';
// TODO: move this to a higher level package than chronograf?
import LayoutRenderer from '../components/LayoutRenderer'; import LayoutRenderer from '../components/LayoutRenderer';
import TimeRangeDropdown from '../../shared/components/TimeRangeDropdown';
import timeRanges from 'hson!../../shared/data/timeRanges.hson';
import {fetchLayouts} from '../apis'; import {fetchLayouts} from '../apis';
import _ from 'lodash'; import _ from 'lodash';
@ -17,7 +18,12 @@ export const HostPage = React.createClass({
}, },
getInitialState() { getInitialState() {
return {layouts: []}; const fifteenMinutesIndex = 1;
return {
layouts: [],
timeRange: timeRanges[fifteenMinutesIndex],
};
}, },
componentDidMount() { componentDidMount() {
@ -26,10 +32,16 @@ export const HostPage = React.createClass({
}); });
}, },
handleChooseTimeRange({lower}) {
const timeRange = timeRanges.find((range) => range.queryValue === lower);
this.setState({timeRange});
},
render() { render() {
const autoRefreshMs = 15000; const autoRefreshMs = 15000;
const source = this.props.source.links.proxy; const source = this.props.source.links.proxy;
const hostID = this.props.params.hostID; const hostID = this.props.params.hostID;
const {timeRange} = this.state;
const layout = _.head(this.state.layouts); const layout = _.head(this.state.layouts);
@ -44,6 +56,7 @@ export const HostPage = React.createClass({
layoutComponent = ( layoutComponent = (
<LayoutRenderer <LayoutRenderer
timeRange={timeRange.queryValue}
cells={layout.cells} cells={layout.cells}
autoRefreshMs={autoRefreshMs} autoRefreshMs={autoRefreshMs}
source={source} source={source}
@ -64,6 +77,9 @@ export const HostPage = React.createClass({
<div className="enterprise-header__right"> <div className="enterprise-header__right">
<p>Uptime: <strong>2d 4h 33m</strong></p> <p>Uptime: <strong>2d 4h 33m</strong></p>
</div> </div>
<div className="enterprise-header__right">
<TimeRangeDropdown onChooseTimeRange={this.handleChooseTimeRange} selected={timeRange.inputValue} />
</div>
</div> </div>
</div> </div>
<div className="container-fluid hosts-dashboard"> <div className="container-fluid hosts-dashboard">