Skip to content

Commit

Permalink
utils for containers
Browse files Browse the repository at this point in the history
  • Loading branch information
roachjc committed Oct 20, 2017
1 parent e2203d2 commit d1e6fe4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions client/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class App extends React.Component {
this.handleIncrement = this.handleIncrement.bind(this);
}

// Get build data
componentDidMount() {
fetch('/getstats')
.then(res => res.json())
Expand All @@ -20,17 +21,20 @@ class App extends React.Component {
});
}

// Select build from LineChart
handleCircleClick(e) {
const len = this.state.build.length;
const index = len - e.target.getAttribute('data-build');
this.setState({ activeBuild: len - index });
}

// Select build from header dropdown
selectBuild(e) {
const index = e.target.getAttribute('data-build');
this.setState({ activeBuild: index - 1 });
}

// Select build from card
handleIncrement() {
if (this.state.activeBuild < this.state.build.length - 1) {
const activeBuild = this.state.activeBuild + 1;
Expand Down
10 changes: 2 additions & 8 deletions client/containers/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import React from 'react';
import { Link } from 'react-router-dom';
import { NavDropdown, MenuItem } from 'react-bootstrap';
import { NavDropdown } from 'react-bootstrap';
import logo from './../assets/wpmlogo.png';
import { getMenuItems } from './utils';

const getMenuItems = (buildNumber, selectBuild) => {
const menuItems = [];
for (let i = buildNumber; i > 0; i -= 1) {
menuItems.push(<MenuItem onClick={selectBuild} data-build={i} key={`build${i}`}>Build {i}</MenuItem>);
}
return menuItems;
};

const Header = (props) => {
const menuItems = getMenuItems(props.build.length, props.selectBuild);
Expand Down
2 changes: 2 additions & 0 deletions client/containers/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Main extends React.Component {
);
}

// Handle routing for Main
renderApp() {
return (
<main>
Expand Down Expand Up @@ -54,6 +55,7 @@ class Main extends React.Component {
);
}

// Render spinner / loader util data loads
render() {
const build = this.props.build.length;
return (
Expand Down
11 changes: 11 additions & 0 deletions client/containers/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { MenuItem } from 'react-bootstrap';


export function getMenuItems(buildNumber, selectBuild) {
const menuItems = [];
for (let i = buildNumber; i > 0; i -= 1) {
menuItems.push(<MenuItem onClick={selectBuild} data-build={i} key={`build${i}`}>Build {i}</MenuItem>);
}
return menuItems;
}
2 changes: 2 additions & 0 deletions client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import App from './App';
const env = process.env.NODE_ENV;

if (env === 'development') {
// AppDev imports a local JSON file as demo data
render(
(
<BrowserRouter>
Expand All @@ -16,6 +17,7 @@ if (env === 'development') {
document.getElementById('root'),
);
} else {
// App retrieves data with fetch from getstats route on plugin server
render(
(
<BrowserRouter>
Expand Down

0 comments on commit d1e6fe4

Please sign in to comment.