Build dashboard table from API

This pulls the table data into a fetch from the mocked-out API. A
subsequent commit will remove the commented-out sections to actually hit
the backend.
pull/10616/head
Tim Raymond 2016-12-13 17:01:34 -05:00
parent c045443dc9
commit 4bcca2e988
2 changed files with 41 additions and 19 deletions

View File

@ -0,0 +1,17 @@
// import AJAX from 'utils/ajax';
export function getDashboards() {
// return AJAX({
// method: 'GET',
// url: `/chronograf/v1/dashboards`,
// });
return {
then(cb) {
cb([
{name: "Goldeneye System Status"},
{name: "Carver Media Group Broadcast System Status"},
{name: "Icarus Space Program Status"},
]);
},
};
}

View File

@ -1,5 +1,7 @@
import React from 'react'; import React from 'react';
import {getDashboards} from '../apis';
const DashboardsPage = React.createClass({ const DashboardsPage = React.createClass({
getInitialState() { getInitialState() {
return { return {
@ -8,22 +10,28 @@ const DashboardsPage = React.createClass({
}, },
componentDidMount() { componentDidMount() {
// getDashboards().then((dashboards) => { getDashboards().then((dashboards) => {
const dashboards = []; this.setState({
this.state({ dashboards,
dashboards, });
}); });
// });
}, },
render() { render() {
let tableHeader;
if (this.state.dashboards.length === 0) {
tableHeader = "Loading Dashboards...";
} else {
tableHeader = `${this.state.dashboards.length} Dashboards`;
}
return ( return (
<div className="page"> <div className="page">
<div className="page-header"> <div className="page-header">
<div className="page-header__container"> <div className="page-header__container">
<div className="page-header__left"> <div className="page-header__left">
<h1> <h1>
Bond Villain Dashboards Dashboards
</h1> </h1>
</div> </div>
</div> </div>
@ -34,7 +42,7 @@ const DashboardsPage = React.createClass({
<div className="col-md-12"> <div className="col-md-12">
<div className="panel panel-minimal"> <div className="panel panel-minimal">
<div className="panel-heading u-flex u-ai-center u-jc-space-between"> <div className="panel-heading u-flex u-ai-center u-jc-space-between">
<h2 className="panel-title">4 Doomsday Devices</h2> <h2 className="panel-title">{tableHeader}</h2>
</div> </div>
<div className="panel-body"> <div className="panel-body">
<table className="table v-center"> <table className="table v-center">
@ -44,18 +52,15 @@ const DashboardsPage = React.createClass({
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> {
<td className="monotype">Goldeneye System Status</td> this.state.dashboards.map((dashboard) => {
</tr> return (
<tr> <tr key={dashboard.name}>
<td className="monotype">Carver Media Group Broadcast System Status</td> <td className="monotype">{dashboard.name}</td>
</tr> </tr>
<tr> );
<td className="monotype">King Oil Pipeline Status</td> })
</tr> }
<tr>
<td className="monotype">Icarus Space Program Status</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>