From 46511bcfe8491ac8dc4b061144d479cbfb488076 Mon Sep 17 00:00:00 2001 From: emizzle Date: Wed, 10 Oct 2018 14:49:10 +1100 Subject: [PATCH] Rebase updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the code was rebased, there were some additional changes for getting websockets logs that needed to be catered for. When there is a call to get all logs for a process, the state entity is updated with a new array item containing all the logs (this is then reduced and selected for rendering). In the case of a websocket log that simply returns only one log item, the latest full log for the process is found in the state entities, and it’s logs are appending to with the data from the websocket. Additionally, log limits were updated to be passed in as a parameter to the API calls from the frontend. Parameter validation (for `limit`) was also added in this commit. --- embark-ui/src/actions/index.js | 7 ++++--- embark-ui/src/components/Console.js | 6 +++--- embark-ui/src/containers/HomeContainer.js | 5 +++-- embark-ui/src/reducers/index.js | 8 +++++++- embark-ui/src/sagas/index.js | 2 +- embark-ui/src/services/api.js | 2 +- lib/core/logger.js | 2 +- lib/modules/logger_api/index.js | 4 +++- 8 files changed, 23 insertions(+), 13 deletions(-) diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 1b49e153..1989d4e9 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -99,11 +99,12 @@ export const commands = { export const PROCESS_LOGS = createRequestTypes('PROCESS_LOGS'); export const processLogs = { - request: (processName) => action(PROCESS_LOGS[REQUEST], {processName}), + request: (processName, limit) => action(PROCESS_LOGS[REQUEST], {processName, limit}), success: (processLogs, payload) => { return action(PROCESS_LOGS[SUCCESS], - { - processLogs: [ + { + ws: !!payload.ws, + processLogs: [ { process: payload.processName, timestamp: new Date().getTime(), diff --git a/embark-ui/src/components/Console.js b/embark-ui/src/components/Console.js index eb6574cf..b8dd1592 100644 --- a/embark-ui/src/components/Console.js +++ b/embark-ui/src/components/Console.js @@ -46,7 +46,7 @@ class Console extends Component { renderCommandsResult(){ const {commands} = this.props; return ( - this.state.selectedProcess === DEFAULT_PROCESS && + this.props.isEmbark() && commands.map((command, index) => { return ; }) @@ -57,8 +57,8 @@ class Console extends Component { const {processes} = this.props; return processes .sort((a, b) => { // ensure the "Embark" tab is displayed first - if (a.name === DEFAULT_PROCESS) return -1; - if (b.name === DEFAULT_PROCESS) return 1; + if (a.name === 'embark') return -1; + if (b.name === 'embark') return 1; return 0; }) .map(process => ( diff --git a/embark-ui/src/containers/HomeContainer.js b/embark-ui/src/containers/HomeContainer.js index f3566852..9c13b6b9 100644 --- a/embark-ui/src/containers/HomeContainer.js +++ b/embark-ui/src/containers/HomeContainer.js @@ -9,7 +9,8 @@ import Processes from '../components/Processes'; import Console from '../components/Console'; import {getProcesses, getCommands, getProcessLogs} from "../reducers/selectors"; -const EMBARK_PROCESS_NAME = 'Embark'; +const EMBARK_PROCESS_NAME = 'embark'; +const LOG_LIMIT = 50; class HomeContainer extends Component { constructor(props) { @@ -30,8 +31,8 @@ class HomeContainer extends Component { this.props.stopProcessLogs(this.state.activeProcess) } + this.props.fetchProcessLogs(processName, LOG_LIMIT); if (processName !== EMBARK_PROCESS_NAME) { - this.props.fetchProcessLogs(processName); this.props.listenToProcessLogs(processName); } diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index d07177d4..e9002750 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -1,6 +1,6 @@ import {combineReducers} from 'redux'; import {REQUEST, SUCCESS, FAILURE, CONTRACT_COMPILE, FILES, LOGOUT, AUTHENTICATE, - FETCH_CREDENTIALS, UPDATE_BASE_ETHER} from "../actions"; + FETCH_CREDENTIALS, UPDATE_BASE_ETHER, PROCESS_LOGS} from "../actions"; const BN_FACTOR = 10000; const VOID_ADDRESS = '0x0000000000000000000000000000000000000000'; @@ -103,6 +103,12 @@ const filtrer = { }; function entities(state = entitiesDefaultState, action) { + if (action.type === PROCESS_LOGS[SUCCESS] && action.ws === true){ + const process = action.processLogs[0].process; + let processLogs = state.processLogs.filter(logs => logs.process === process).sort((a, b) => b.timestamp - a.timestamp)[0]; + processLogs.logs.push(action.processLogs[0].logs[0]); + return {...state}; + } if (action.type === FILES[SUCCESS]) { return {...state, files: action.files}; } diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index fea051df..650f6237 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -241,7 +241,7 @@ export function *listenToProcessLogs(action) { return; } - yield put(actions.processLogs.success([processLog])); + yield put(actions.processLogs.success([processLog], {processName: action.processName, ws: true})); } } diff --git a/embark-ui/src/services/api.js b/embark-ui/src/services/api.js index d96fcf4d..e79ee8e5 100644 --- a/embark-ui/src/services/api.js +++ b/embark-ui/src/services/api.js @@ -56,7 +56,7 @@ export function fetchProcesses() { } export function fetchProcessLogs(payload) { - return get(`/process-logs/${payload.processName}`, ...arguments); + return get(`/process-logs/${payload.processName}`, {params: payload, processName: payload.processName, credentials: payload.credentials}); } export function fetchContractLogs() { diff --git a/lib/core/logger.js b/lib/core/logger.js index d8ad9216..85676bdb 100644 --- a/lib/core/logger.js +++ b/lib/core/logger.js @@ -55,7 +55,7 @@ class Logger { } // if 'limit' is specified, get log lines from the end of the log file - if(limit && logs.length > limit){ + if(limit && limit > 0 && logs.length > limit){ logs.slice(limit * -1); } return logs; diff --git a/lib/modules/logger_api/index.js b/lib/modules/logger_api/index.js index 238fd7ab..703883d5 100644 --- a/lib/modules/logger_api/index.js +++ b/lib/modules/logger_api/index.js @@ -11,7 +11,9 @@ class LoggerApi { 'get', '/embark-api/process-logs/embark', (req, res) => { - res.send(this.logger.parseLogFile(req.query.limit)); + let limit = parseInt(req.query.limit, 10); + if(!Number.isInteger(limit)) limit = 0; + res.send(this.logger.parseLogFile(limit)); } ); }