From 3499e7ad31e304859d442561c6808b87aea5cb50 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 5 Sep 2018 17:02:40 -0400 Subject: [PATCH] basic implementation of tabs for process logs --- embark-ui/src/actions/index.js | 2 +- embark-ui/src/components/Console.js | 40 ++++++++++++++++++----- embark-ui/src/containers/HomeContainer.js | 23 ++++++++++--- embark-ui/src/reducers/selectors.js | 4 +++ 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 0dc4bf8a..1e6d936a 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -64,7 +64,7 @@ export const processes = { export const COMMANDS = createRequestTypes('COMMANDS'); export const commands = { - post: (command) => action(COMMANDS[REQUEST], {command}), + post: (command) => action(COMMANDS[REQUEST], {command, noLoading: true}), success: (command) => action(COMMANDS[SUCCESS], {commands: [{timestamp: new Date().getTime(), ...command}]}), failure: (error) => action(COMMANDS[FAILURE], {error}) }; diff --git a/embark-ui/src/components/Console.js b/embark-ui/src/components/Console.js index 8093c45a..a6667d60 100644 --- a/embark-ui/src/components/Console.js +++ b/embark-ui/src/components/Console.js @@ -1,7 +1,10 @@ import PropTypes from "prop-types"; import React, {Component} from 'react'; -import {Grid, Card, Form} from 'tabler-react'; +import {Grid, Card, Form, Tabs, Tab} from 'tabler-react'; +import Logs from "./Logs"; +import Convert from 'ansi-to-html'; +const convert = new Convert(); require('./Console.css'); const CommandResult = ({result}) => ( @@ -30,6 +33,7 @@ class Console extends Component { } render() { + const {processLogs, processes, commands}= this.props; return ( @@ -37,18 +41,36 @@ class Console extends Component { Embark console - -
- {this.props.commands.map((command, index) => )} -
+ + + + + {commands.map((command, index) => )} + + + {processes.map(process => { + return ( + + + { + processLogs.filter((item) => item.name === process.name) + .map((item, i) =>

) + } +
+
+ ); + })} +
+
-
this.handleSubmit(event)}> + this.handleSubmit(event)} autoComplete="off"> this.handleChange(event)} name="command" placeholder="Type a command (e.g help)" /> - +
@@ -59,7 +81,9 @@ class Console extends Component { Console.propTypes = { postCommand: PropTypes.func, - commands: PropTypes.arrayOf(PropTypes.object) + commands: PropTypes.arrayOf(PropTypes.object).isRequired, + processes: PropTypes.arrayOf(PropTypes.object).isRequired, + processLogs: PropTypes.arrayOf(PropTypes.object).isRequired }; export default Console; diff --git a/embark-ui/src/containers/HomeContainer.js b/embark-ui/src/containers/HomeContainer.js index cd714274..7be08163 100644 --- a/embark-ui/src/containers/HomeContainer.js +++ b/embark-ui/src/containers/HomeContainer.js @@ -3,14 +3,23 @@ import React, {Component} from 'react'; import {connect} from 'react-redux'; import {Page} from "tabler-react"; -import {commands as commandsAction} from "../actions"; +import {commands as commandsAction, listenToProcessLogs, processLogs as processLogsAction} from "../actions"; import DataWrapper from "../components/DataWrapper"; import Processes from '../components/Processes'; import Versions from '../components/Versions'; import Console from '../components/Console'; -import {getProcesses, getCommands, getVersions} from "../reducers/selectors"; +import {getProcesses, getCommands, getVersions, getProcessLogs} from "../reducers/selectors"; class HomeContainer extends Component { + componentDidMount() { + if (this.props.processLogs.length === 0) { + // TODO get all + this.props.fetchProcessLogs('blockchain'); + this.props.fetchProcessLogs('ipfs'); + this.props.listenToProcessLogs('blockchain'); + } + } + render() { return ( @@ -21,7 +30,10 @@ class HomeContainer extends Component { 0 } {...this.props} render={({versions}) => ( )} /> - + + 0 } {...this.props} render={({processes, postCommand, processLogs}) => ( + + )} /> ); } @@ -42,6 +54,7 @@ function mapStateToProps(state) { processes: getProcesses(state), commands: getCommands(state), error: state.errorMessage, + processLogs: getProcessLogs(state), loading: state.loading }; } @@ -49,6 +62,8 @@ function mapStateToProps(state) { export default connect( mapStateToProps, { - postCommand: commandsAction.post + postCommand: commandsAction.post, + fetchProcessLogs: processLogsAction.request, + listenToProcessLogs } )(HomeContainer); diff --git a/embark-ui/src/reducers/selectors.js b/embark-ui/src/reducers/selectors.js index b5bc403d..115344c6 100644 --- a/embark-ui/src/reducers/selectors.js +++ b/embark-ui/src/reducers/selectors.js @@ -48,6 +48,10 @@ export function getProcess(state, name) { return state.entities.processes.find((process) => process.name === name); } +export function getProcessLogs(state) { + return state.entities.processLogs; +} + export function getProcessLogsByProcess(state, processName) { return state.entities.processLogs.filter((processLog => processLog.name === processName)); }