diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 4fb6b2c6..1b49e153 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -100,7 +100,19 @@ export const commands = { export const PROCESS_LOGS = createRequestTypes('PROCESS_LOGS'); export const processLogs = { request: (processName) => action(PROCESS_LOGS[REQUEST], {processName}), - success: (processLogs) => action(PROCESS_LOGS[SUCCESS], {processLogs}), + success: (processLogs, payload) => { + return action(PROCESS_LOGS[SUCCESS], + { + processLogs: [ + { + process: payload.processName, + timestamp: new Date().getTime(), + logs: processLogs + } + ] + } + ); + }, failure: (error) => action(PROCESS_LOGS[FAILURE], {error}) }; diff --git a/embark-ui/src/components/Console.js b/embark-ui/src/components/Console.js index dcf6c0df..ce012b6b 100644 --- a/embark-ui/src/components/Console.js +++ b/embark-ui/src/components/Console.js @@ -31,6 +31,16 @@ class Console extends Component { this.setState({value: event.target.value}); } + getProcessLogs(processName){ + const log = this.props.processLogs + .reverse() + .filter((item) => item.process === processName); + + if(!log.length) return []; + //should be only one item in the array + return log[0].logs; + } + renderCommandsResult(){ const {commands} = this.props; return ( @@ -42,7 +52,7 @@ class Console extends Component { } renderTabs() { - const {processLogs, processes} = this.props; + const {processes} = this.props; return processes .sort((a, b) => { // ensure the "Embark" tab is displayed first if (a.name === this.DEFAULT_PROCESS) return -1; @@ -53,10 +63,7 @@ class Console extends Component { this.clickTab(e, x)}> { - processLogs - .reverse() - .filter((item) => item.name === process.name) - .sort((a, b) => a.timestamp - b.timestamp) + this.getProcessLogs(process.name) .map((item, i) =>

) } diff --git a/embark-ui/src/reducers/selectors.js b/embark-ui/src/reducers/selectors.js index dad78cfd..3c170e56 100644 --- a/embark-ui/src/reducers/selectors.js +++ b/embark-ui/src/reducers/selectors.js @@ -53,7 +53,15 @@ export function getProcesses(state) { } export function getProcessLogs(state) { - return state.entities.processLogs; + if(!state.entities.processLogs.length) return []; + const processLogsObj = state.entities.processLogs.reduce((processLogs, processLog) => { + const existingProcessLog = processLogs[processLog.process]; + if(!existingProcessLog || processLog.timestamp > existingProcessLog.timestamp){ + processLogs[processLog.process] = processLog; + } + return processLogs; + }, {}); + return Object.values(processLogsObj); } export function getContractLogsByContract(state, contractName) {