add basic ui for processes

This commit is contained in:
Jonathan Rainville 2018-08-01 14:09:58 -04:00 committed by Pascal Precht
parent 9b9f5743f7
commit fdbc567b3b
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
10 changed files with 92 additions and 29 deletions

View File

@ -16,7 +16,7 @@ export function fetchAccounts() {
export function receiveAccounts(accounts) { export function receiveAccounts(accounts) {
return { return {
type: RECEIVE_ACCOUNTS, type: RECEIVE_ACCOUNTS,
accounts: accounts accounts
}; };
} }
@ -35,7 +35,7 @@ export function fetchProcesses() {
export function receiveProcesses(processes) { export function receiveProcesses(processes) {
return { return {
type: RECEIVE_PROCESSES, type: RECEIVE_PROCESSES,
accounts: processes processes
}; };
} }

View File

@ -5,10 +5,5 @@ export function fetchAccounts() {
} }
export function fetchProcesses() { export function fetchProcesses() {
console.log('Calling this shit'); return axios.get('http://localhost:8000/embark-api/processes');
const stuff = axios.get('http://localhost:8000/embark-api/processes');
stuff.then(result => {
console.log('result', result);
}).catch(console.error);
return stuff;
} }

View File

@ -1,14 +1,16 @@
import React from 'react'; import React from 'react';
import { NavLink, withRouter } from "react-router-dom"; import {NavLink, withRouter} from "react-router-dom";
import { Site, Nav, Button, Container } from "tabler-react"; import {Site, Nav, Button, Container} from "tabler-react";
import PropTypes from 'prop-types';
import logo from'../images/logo.png'; import logo from '../images/logo.png';
const navBarItems = [ const navBarItems = [
{ value: "Home", to: "/embark", icon: "home", LinkComponent: withRouter(NavLink) }, {value: "Home", to: "/embark", icon: "home", LinkComponent: withRouter(NavLink)},
{ value: "Contracts", to: "/embark/contracts", icon: "box", LinkComponent: withRouter(NavLink) }, {value: "Contracts", to: "/embark/contracts", icon: "box", LinkComponent: withRouter(NavLink)},
{ value: "Explorer", to: "/embark/explorer/accounts", icon: "activity", LinkComponent: withRouter(NavLink) }, {value: "Explorer", to: "/embark/explorer/accounts", icon: "activity", LinkComponent: withRouter(NavLink)},
{ value: "Documentation", to: "/embark/documentation", icon: "file-text", LinkComponent: withRouter(NavLink) }, {value: "Processes", to: "/embark/processes", icon: "cpu", LinkComponent: withRouter(NavLink)},
{value: "Documentation", to: "/embark/documentation", icon: "file-text", LinkComponent: withRouter(NavLink)}
]; ];
const Layout = (props) => ( const Layout = (props) => (
@ -32,7 +34,7 @@ const Layout = (props) => (
</Nav.Item> </Nav.Item>
) )
}} }}
navProps={{ itemsObjects: navBarItems}} navProps={{itemsObjects: navBarItems}}
> >
<Container> <Container>
{props.children} {props.children}
@ -40,4 +42,8 @@ const Layout = (props) => (
</Site.Wrapper> </Site.Wrapper>
); );
Layout.propTypes = {
children: PropTypes.element
};
export default Layout; export default Layout;

View File

@ -1,9 +1,9 @@
import {ConnectedRouter} from "connected-react-router"; import {ConnectedRouter} from "connected-react-router";
import React, { Component } from 'react'; import React, {Component} from 'react';
import history from '../history'; import history from '../history';
import Layout from '../components/Layout'; import Layout from '../components/Layout';
import routes from '../routes' import routes from '../routes';
class AppContainer extends Component { class AppContainer extends Component {
render() { render() {

View File

@ -0,0 +1,49 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {fetchProcesses} from '../actions';
import PropTypes from 'prop-types';
class ProcessesContainer extends Component {
componentDidMount() {
this.props.fetchProcesses();
}
render() {
const {processes} = this.props;
if (!processes.data) {
return (
<h1>
<i>Loading processes...</i>
</h1>
);
}
if (processes.error) {
return (
<h1>
<i>Error API...</i>
</h1>
);
}
return (
<p>Loaded</p>
);
}
}
ProcessesContainer.propTypes = {
processes: PropTypes.object,
fetchProcesses: PropTypes.func
};
function mapStateToProps(state) {
return {processes: state.processes};
}
export default connect(
mapStateToProps,
{
fetchProcesses
}
)(ProcessesContainer);

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'; import {Provider} from 'react-redux';
import "tabler-react/dist/Tabler.css"; import "tabler-react/dist/Tabler.css";

View File

@ -1,5 +1,6 @@
import { combineReducers } from 'redux'; import {combineReducers} from 'redux';
import { RECEIVE_ACCOUNTS, RECEIVE_ACCOUNTS_ERROR } from "../actions"; import {RECEIVE_ACCOUNTS, RECEIVE_ACCOUNTS_ERROR} from "../actions";
import processesReducer from './processesReducer';
function accounts(state = {}, action) { function accounts(state = {}, action) {
switch (action.type) { switch (action.type) {
@ -10,7 +11,7 @@ function accounts(state = {}, action) {
default: default:
return state; return state;
} }
}; }
const rootReducer = combineReducers({accounts}); const rootReducer = combineReducers({accounts, processes: processesReducer});
export default rootReducer; export default rootReducer;

View File

@ -0,0 +1,12 @@
import {RECEIVE_PROCESSES, RECEIVE_PROCESSES_ERROR} from "../actions";
export default function processes(state = {}, action) {
switch (action.type) {
case RECEIVE_PROCESSES:
return Object.assign({}, state, {data: action.processes.data});
case RECEIVE_PROCESSES_ERROR:
return Object.assign({}, state, {error: true});
default:
return state;
}
}

View File

@ -1,7 +1,8 @@
import React from 'react'; import React from 'react';
import { Route, Switch } from 'react-router'; import {Route, Switch} from 'react-router';
import Home from './components/Home'; import Home from './components/Home';
import AccountsContainer from './containers/AccountsContainer'; import AccountsContainer from './containers/AccountsContainer';
import ProcessesContainer from './containers/ProcessesContainer';
import NoMatch from './components/NoMatch'; import NoMatch from './components/NoMatch';
const routes = ( const routes = (
@ -9,9 +10,10 @@ const routes = (
<Switch> <Switch>
<Route exact path="/embark" component={Home} /> <Route exact path="/embark" component={Home} />
<Route path="/embark/explorer/accounts" component={AccountsContainer} /> <Route path="/embark/explorer/accounts" component={AccountsContainer} />
<Route path="/embark/processes" component={ProcessesContainer} />
<Route component={NoMatch} /> <Route component={NoMatch} />
</Switch> </Switch>
</React.Fragment> </React.Fragment>
) );
export default routes export default routes;

View File

@ -15,11 +15,9 @@ export function *watchFetchAccounts() {
yield takeEvery(actions.FETCH_ACCOUNTS, fetchAccounts); yield takeEvery(actions.FETCH_ACCOUNTS, fetchAccounts);
} }
export function *fetchProcesses() { export function *fetchProcesses() {
try { try {
const processes = yield call(api.fetchProcesses); const processes = yield call(api.fetchProcesses);
console.log('Got processes', processes);
yield put(actions.receiveProcesses(processes)); yield put(actions.receiveProcesses(processes));
} catch (e) { } catch (e) {
yield put(actions.receiveProcessesError()); yield put(actions.receiveProcessesError());
@ -31,5 +29,5 @@ export function *watchFetchProcesses() {
} }
export default function *root() { export default function *root() {
yield all([fork(watchFetchAccounts, watchFetchProcesses())]); yield all([fork(watchFetchAccounts), fork(watchFetchProcesses)]);
} }