Skip to content

Commit

Permalink
Merge pull request #414 from smartcontractkit/features/gui-navigation
Browse files Browse the repository at this point in the history
Add drawer navigation menu
  • Loading branch information
rupurt authored Jul 12, 2018
2 parents 0fe5931 + 989c527 commit 00ed2c6
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 101 deletions.
104 changes: 4 additions & 100 deletions gui/src/App.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,8 @@
import React, { PureComponent } from 'react'
import Routes from 'react-static-routes'
import CssBaseline from '@material-ui/core/CssBaseline'
import Grid from '@material-ui/core/Grid'
import AppBar from '@material-ui/core/AppBar'
import Typography from '@material-ui/core/Typography'
import universal from 'react-universal-component'
import Layout from 'Layout'
import createStore from 'connectors/redux'
import { Link, Router, Route, Switch } from 'react-static'
import { hot } from 'react-hot-loader'
import { withStyles } from '@material-ui/core/styles'
import { Provider } from 'react-redux'
import logoImg from './logo.svg'

// Use universal-react-component for code-splitting non-static routes
const Bridges = universal(import('./containers/Bridges'))
const Configuration = universal(import('./containers/Configuration'))
const JobSpec = universal(import('./containers/JobSpec'))
const JobSpecRuns = universal(import('./containers/JobSpecRuns'))
const JobSpecRun = universal(import('./containers/JobSpecRun'))

// Custom styles
const styles = theme => {
return {
appBar: {
backgroundColor: theme.palette.background.appBar,
paddingTop: theme.spacing.unit * 3,
paddingBottom: theme.spacing.unit * 3,
paddingLeft: theme.spacing.unit * 5,
paddingRight: theme.spacing.unit * 5
},
content: {
margin: theme.spacing.unit * 5,
marginTop: 0
},
menu: {
marginTop: theme.spacing.unit * 2,
textDecoration: 'none'
},
menuitem: {
color: theme.palette.common.white,
paddingRight: theme.spacing.unit * 5,
display: 'inline-block',
textDecoration: 'none'
}
}
}
import { hot } from 'react-hot-loader'

class App extends PureComponent {
// Remove the server-side injected CSS.
Expand All @@ -56,66 +14,12 @@ class App extends PureComponent {
}

render () {
const { classes } = this.props

return (
<Provider store={createStore()}>
<Router>
<Grid container>
<CssBaseline />
<Grid item xs={12}>
<AppBar
className={classes.appBar}
elevation={0}
color='default'
position='static'
>
<Grid container spacing={40}>
<Grid item xs={9}>
<Link to='/'>
<img src={logoImg} alt='Chainlink' width={121} height={44} />
</Link>
</Grid>
<Grid item xs={3}>
<div align='right' className={classes.menu}>
<Link to='/bridges' className={classes.menuitem}>
<Typography color='inherit'>
Bridges
</Typography>
</Link>
<Link to='/config' className={classes.menuitem}>
<Typography color='inherit'>
Configuration
</Typography>
</Link>
<Link to='/about' className={classes.menuitem}>
<Typography color='inherit'>
About
</Typography>
</Link>
</div>
</Grid>
</Grid>
</AppBar>

<div className={classes.content}>
<Switch>
<Route exact path='/job_specs/:jobSpecId' component={JobSpec} />
<Route exact path='/job_specs/:jobSpecId/runs' component={JobSpecRuns} />
<Route exact path='/job_specs/:jobSpecId/runs/:jobRunId' component={JobSpecRun} />
<Route exact path='/config' component={Configuration} />
<Route exact path='/bridges' component={Bridges} />
<Routes />
</Switch>
</div>
</Grid>
</Grid>
</Router>
<Layout />
</Provider>
)
}
}

const AppWithStyles = withStyles(styles)(App)

export default hot(module)(AppWithStyles)
export default hot(module)(App)
179 changes: 179 additions & 0 deletions gui/src/Layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import React, { Component } from 'react'
import Routes from 'react-static-routes'
import AppBar from '@material-ui/core/AppBar'
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'
import CssBaseline from '@material-ui/core/CssBaseline'
import Divider from '@material-ui/core/Divider'
import Drawer from '@material-ui/core/Drawer'
import List from '@material-ui/core/List'
import ListItem from '@material-ui/core/ListItem'
import ListItemText from '@material-ui/core/ListItemText'
import Grid from '@material-ui/core/Grid'
import IconButton from '@material-ui/core/IconButton'
import MenuIcon from '@material-ui/icons/Menu'
import Typography from '@material-ui/core/Typography'
import universal from 'react-universal-component'
import classNames from 'classnames'
import { Link, Router, Route, Switch } from 'react-static'
import { hot } from 'react-hot-loader'
import { withStyles } from '@material-ui/core/styles'
import logoImg from './logo.svg'

// Use universal-react-component for code-splitting non-static routes
const Bridges = universal(import('./containers/Bridges'))
const Configuration = universal(import('./containers/Configuration'))
const JobSpec = universal(import('./containers/JobSpec'))
const JobSpecRuns = universal(import('./containers/JobSpecRuns'))
const JobSpecRun = universal(import('./containers/JobSpecRun'))

const appBarHeight = 64
const drawerWidth = 240

// Custom styles
const styles = theme => {
return {
appBar: {
backgroundColor: theme.palette.background.appBar,
paddingLeft: theme.spacing.unit * 5,
paddingRight: theme.spacing.unit * 5,
zIndex: theme.zIndex.modal + 1
},
appBarContent: {
height: appBarHeight
},
content: {
margin: theme.spacing.unit * 5,
marginTop: 0
},
menuButton: {
color: theme.palette.common.white
},
menuitem: {
padding: theme.spacing.unit * 3,
paddingTop: theme.spacing.unit * 2,
paddingBottom: theme.spacing.unit * 2,
display: 'inline-block',
textDecoration: 'none'
},
drawerPaper: {
backgroundColor: theme.palette.common.white,
width: drawerWidth
},
drawerList: {
padding: 0
},
toolbar: {
minHeight: appBarHeight
}
}
}

class Layout extends Component {
constructor(props) {
super(props)
this.state = {drawerOpen: false}
this.toggleDrawer = this.toggleDrawer.bind(this)
}

toggleDrawer () {
this.setState({drawerOpen: !this.state.drawerOpen})
}

render () {
const {classes} = this.props
const {drawerOpen} = this.state

const drawer = (
<Drawer
anchor="right"
open={drawerOpen}
classes={{
paper: classes.drawerPaper,
}}
onClose={this.toggleDrawer}
>
<div className={classes.toolbar} />
<div
tabIndex={0}
role="button"
onClick={this.toggleDrawer}
>
<List className={classes.drawerList}>
<ListItem button>
<Link to='/' className={classes.menuitem}>
<ListItemText primary="Jobs" />
</Link>
</ListItem>
<ListItem button>
<Link to='/bridges' className={classes.menuitem}>
<ListItemText primary="Bridges" />
</Link>
</ListItem>
<ListItem button>
<Link to='/config' className={classes.menuitem}>
<ListItemText primary="Configuration" />
</Link>
</ListItem>
<ListItem button>
<Link to='/about' className={classes.menuitem}>
<ListItemText primary="About" />
</Link>
</ListItem>
</List>
</div>
</Drawer>
);

return (
<Router>
<Grid container>
<CssBaseline />
<Grid item xs={12}>
<AppBar
className={classes.appBar}
color='default'
position='absolute'
>
<Grid container alignItems="center" className={classes.appBarContent}>
<Grid item xs={9}>
<Link to='/'>
<img src={logoImg} alt='Chainlink' width={121} height={44} />
</Link>
</Grid>
<Grid item xs={3}>
<div align='right'>
<IconButton
aria-label="open drawer"
onClick={this.toggleDrawer}
className={classes.menuButton}
>
<MenuIcon />
</IconButton>
</div>
</Grid>
</Grid>
</AppBar>

<div className={classes.content}>
<div className={classes.toolbar} />
<Switch>
<Route exact path='/job_specs/:jobSpecId' component={JobSpec} />
<Route exact path='/job_specs/:jobSpecId/runs' component={JobSpecRuns} />
<Route exact path='/job_specs/:jobSpecId/runs/:jobRunId' component={JobSpecRun} />
<Route exact path='/config' component={Configuration} />
<Route exact path='/bridges' component={Bridges} />
<Routes />
</Switch>
</div>

{drawer}
</Grid>
</Grid>
</Router>
)
}
}

const LayoutWithStyles = withStyles(styles)(Layout)

export default hot(module)(LayoutWithStyles)
2 changes: 1 addition & 1 deletion gui/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const formatURI = (path, query = {}) => {
const request = (path, query) => (
global.fetch(
formatURI(path, query),
{credentials: 'same-origin'}
{credentials: 'include'}
)
.then(response => response.json())
.then((data) => camelizeKeys(data))
Expand Down
3 changes: 3 additions & 0 deletions gui/src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { common, green, grey } from '@material-ui/core/colors'

export default {
palette: {
action: {
hoverOpacity: 0.3
},
primary: {
light: '#776bfa',
main: '#3c40c6',
Expand Down

0 comments on commit 00ed2c6

Please sign in to comment.