simplify dashboard code
parent
d059cd2750
commit
f0f06f887f
|
@ -32,17 +32,12 @@ const DashboardPage = React.createClass({
|
||||||
getSource(this.props.params.sourceID).then(({data: source}) => {
|
getSource(this.props.params.sourceID).then(({data: source}) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
dashboards: resp.data.dashboards,
|
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) {
|
currentDashboard(dashboards, dashboardID) {
|
||||||
return _.find(dashboards, (d) => d.id.toString() === dashboardID);
|
return _.find(dashboards, (d) => d.id.toString() === dashboardID);
|
||||||
},
|
},
|
||||||
|
@ -86,9 +81,8 @@ const DashboardPage = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {dashboards, dashboard, timeRange} = this.state;
|
const {dashboards, timeRange} = this.state;
|
||||||
|
const dashboard = this.currentDashboard(dashboards, this.props.params.dashboardID)
|
||||||
const dashboardName = dashboard ? dashboard.name : '';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page">
|
<div className="page">
|
||||||
|
@ -97,7 +91,7 @@ const DashboardPage = React.createClass({
|
||||||
<div className="page-header__left">
|
<div className="page-header__left">
|
||||||
<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">{dashboard ? dashboard.name : ''}</span>
|
||||||
<span className="caret"></span>
|
<span className="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul className="dropdown-menu" aria-labelledby="dropdownMenu1">
|
<ul className="dropdown-menu" aria-labelledby="dropdownMenu1">
|
||||||
|
|
Loading…
Reference in New Issue