Rebase updates

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.
This commit is contained in:
emizzle 2018-10-10 14:49:10 +11:00 committed by Pascal Precht
parent d4d7e3b8ac
commit 46511bcfe8
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
8 changed files with 23 additions and 13 deletions

View File

@ -99,11 +99,12 @@ export const commands = {
export const PROCESS_LOGS = createRequestTypes('PROCESS_LOGS'); export const PROCESS_LOGS = createRequestTypes('PROCESS_LOGS');
export const processLogs = { export const processLogs = {
request: (processName) => action(PROCESS_LOGS[REQUEST], {processName}), request: (processName, limit) => action(PROCESS_LOGS[REQUEST], {processName, limit}),
success: (processLogs, payload) => { success: (processLogs, payload) => {
return action(PROCESS_LOGS[SUCCESS], return action(PROCESS_LOGS[SUCCESS],
{ {
processLogs: [ ws: !!payload.ws,
processLogs: [
{ {
process: payload.processName, process: payload.processName,
timestamp: new Date().getTime(), timestamp: new Date().getTime(),

View File

@ -46,7 +46,7 @@ class Console extends Component {
renderCommandsResult(){ renderCommandsResult(){
const {commands} = this.props; const {commands} = this.props;
return ( return (
this.state.selectedProcess === DEFAULT_PROCESS && this.props.isEmbark() &&
commands.map((command, index) => { commands.map((command, index) => {
return <CommandResult key={index} result={command.result}/>; return <CommandResult key={index} result={command.result}/>;
}) })
@ -57,8 +57,8 @@ class Console extends Component {
const {processes} = this.props; const {processes} = this.props;
return processes return processes
.sort((a, b) => { // ensure the "Embark" tab is displayed first .sort((a, b) => { // ensure the "Embark" tab is displayed first
if (a.name === DEFAULT_PROCESS) return -1; if (a.name === 'embark') return -1;
if (b.name === DEFAULT_PROCESS) return 1; if (b.name === 'embark') return 1;
return 0; return 0;
}) })
.map(process => ( .map(process => (

View File

@ -9,7 +9,8 @@ import Processes from '../components/Processes';
import Console from '../components/Console'; import Console from '../components/Console';
import {getProcesses, getCommands, getProcessLogs} from "../reducers/selectors"; 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 { class HomeContainer extends Component {
constructor(props) { constructor(props) {
@ -30,8 +31,8 @@ class HomeContainer extends Component {
this.props.stopProcessLogs(this.state.activeProcess) this.props.stopProcessLogs(this.state.activeProcess)
} }
this.props.fetchProcessLogs(processName, LOG_LIMIT);
if (processName !== EMBARK_PROCESS_NAME) { if (processName !== EMBARK_PROCESS_NAME) {
this.props.fetchProcessLogs(processName);
this.props.listenToProcessLogs(processName); this.props.listenToProcessLogs(processName);
} }

View File

@ -1,6 +1,6 @@
import {combineReducers} from 'redux'; import {combineReducers} from 'redux';
import {REQUEST, SUCCESS, FAILURE, CONTRACT_COMPILE, FILES, LOGOUT, AUTHENTICATE, 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 BN_FACTOR = 10000;
const VOID_ADDRESS = '0x0000000000000000000000000000000000000000'; const VOID_ADDRESS = '0x0000000000000000000000000000000000000000';
@ -103,6 +103,12 @@ const filtrer = {
}; };
function entities(state = entitiesDefaultState, action) { 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]) { if (action.type === FILES[SUCCESS]) {
return {...state, files: action.files}; return {...state, files: action.files};
} }

View File

@ -241,7 +241,7 @@ export function *listenToProcessLogs(action) {
return; return;
} }
yield put(actions.processLogs.success([processLog])); yield put(actions.processLogs.success([processLog], {processName: action.processName, ws: true}));
} }
} }

View File

@ -56,7 +56,7 @@ export function fetchProcesses() {
} }
export function fetchProcessLogs(payload) { 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() { export function fetchContractLogs() {

View File

@ -55,7 +55,7 @@ class Logger {
} }
// if 'limit' is specified, get log lines from the end of the log file // 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); logs.slice(limit * -1);
} }
return logs; return logs;

View File

@ -11,7 +11,9 @@ class LoggerApi {
'get', 'get',
'/embark-api/process-logs/embark', '/embark-api/process-logs/embark',
(req, res) => { (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));
} }
); );
} }