simplify dashboard code

pull/837/head
Jade McGough 2017-02-01 10:05:26 -08:00
parent d059cd2750
commit f0f06f887f
1 changed files with 3 additions and 9 deletions

View File

@ -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">