change dashboards via dropdown
parent
ab3a74b5d2
commit
d059cd2750
|
@ -6,10 +6,3 @@ export function getDashboards() {
|
||||||
url: `/chronograf/v1/dashboards`,
|
url: `/chronograf/v1/dashboards`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDashboard(id) {
|
|
||||||
return AJAX({
|
|
||||||
method: 'GET',
|
|
||||||
url: `/chronograf/v1/dashboards/${id}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import React, {PropTypes} from 'react';
|
import React, {PropTypes} from 'react';
|
||||||
import ReactTooltip from 'react-tooltip';
|
import ReactTooltip from 'react-tooltip';
|
||||||
|
import {Link} from 'react-router';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
import LayoutRenderer from 'shared/components/LayoutRenderer';
|
import LayoutRenderer from 'shared/components/LayoutRenderer';
|
||||||
import TimeRangeDropdown from '../../shared/components/TimeRangeDropdown';
|
import TimeRangeDropdown from '../../shared/components/TimeRangeDropdown';
|
||||||
import timeRanges from 'hson!../../shared/data/timeRanges.hson';
|
import timeRanges from 'hson!../../shared/data/timeRanges.hson';
|
||||||
|
|
||||||
import {getDashboard} from '../apis';
|
import {getDashboards} from '../apis';
|
||||||
import {getSource} from 'shared/apis';
|
import {getSource} from 'shared/apis';
|
||||||
|
|
||||||
const DashboardPage = React.createClass({
|
const DashboardPage = React.createClass({
|
||||||
|
@ -20,21 +22,31 @@ const DashboardPage = React.createClass({
|
||||||
const fifteenMinutesIndex = 1;
|
const fifteenMinutesIndex = 1;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
dashboards: [],
|
||||||
timeRange: timeRanges[fifteenMinutesIndex],
|
timeRange: timeRanges[fifteenMinutesIndex],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
getDashboard(this.props.params.dashboardID).then((resp) => {
|
getDashboards().then((resp) => {
|
||||||
getSource(this.props.params.sourceID).then(({data: source}) => {
|
getSource(this.props.params.sourceID).then(({data: source}) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
dashboard: resp.data,
|
dashboards: resp.data.dashboards,
|
||||||
|
dashboard: this.currentDashboard(resp.data.dashboards, this.props.params.dashboardID),
|
||||||
source,
|
source,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
this.setState({dashboard: this.currentDashboard(this.state.dashboards, nextProps.params.dashboardID)});
|
||||||
|
},
|
||||||
|
|
||||||
|
currentDashboard(dashboards, dashboardID) {
|
||||||
|
return _.find(dashboards, (d) => d.id.toString() === dashboardID);
|
||||||
|
},
|
||||||
|
|
||||||
renderDashboard(dashboard) {
|
renderDashboard(dashboard) {
|
||||||
const autoRefreshMs = 15000;
|
const autoRefreshMs = 15000;
|
||||||
const {timeRange} = this.state;
|
const {timeRange} = this.state;
|
||||||
|
@ -74,7 +86,8 @@ const DashboardPage = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {dashboard, timeRange} = this.state;
|
const {dashboards, dashboard, timeRange} = this.state;
|
||||||
|
|
||||||
const dashboardName = dashboard ? dashboard.name : '';
|
const dashboardName = dashboard ? dashboard.name : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -85,7 +98,19 @@ const DashboardPage = React.createClass({
|
||||||
<div className="dropdown page-header-dropdown">
|
<div className="dropdown page-header-dropdown">
|
||||||
<button className="dropdown-toggle" type="button" data-toggle="dropdown">
|
<button className="dropdown-toggle" type="button" data-toggle="dropdown">
|
||||||
<span className="button-text">{dashboardName}</span>
|
<span className="button-text">{dashboardName}</span>
|
||||||
|
<span className="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
|
<ul className="dropdown-menu" aria-labelledby="dropdownMenu1">
|
||||||
|
{(dashboards).map((d, i) => {
|
||||||
|
return (
|
||||||
|
<li key={i}>
|
||||||
|
<Link to={`/sources/${this.props.params.sourceID}/dashboards/${d.id}`} className="role-option">
|
||||||
|
{d.name}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="page-header__right">
|
<div className="page-header__right">
|
||||||
|
|
Loading…
Reference in New Issue