Browse Source

Merge pull request #135 from SuperNETorg/logstatus-redux

Logstatus redux
all-modes
pbca26 7 years ago
committed by GitHub
parent
commit
a9c1519931
  1. 58
      react/src/reducers/dashboard.js
  2. 11
      react/src/store.js

58
react/src/reducers/dashboard.js

@ -13,6 +13,16 @@ import {
const HTTP_STACK_MAX_ENTRIES = 150; // limit stack mem length to N records per type
const trimHTTPLogs = (logObject) => {
const logObjectArray = Object.keys(logObject);
if (logObjectArray.length - HTTP_STACK_MAX_ENTRIES === 1) {
delete logObject[logObjectArray.shift()];
}
return logObject;
};
export function Dashboard(state = {
activeSection: 'wallets',
activeHandle: null,
@ -25,7 +35,7 @@ export function Dashboard(state = {
currentNodeName: null,
failedToConnectNodes: null,
},
guiLog: {}
guiLog: {},
}, action) {
switch (action.type) {
case DASHBOARD_SECTION_CHANGE:
@ -70,44 +80,22 @@ export function Dashboard(state = {
displayViewCacheModal: action.display,
});
case LOG_GUI_HTTP:
let _guiLogState = state.guiLog;
let _guiLogStateTrim = {
error: [],
success: [],
pending: []
};
const logState = state.guiLog;
const actionTS = action.timestamp;
let newLogState = {};
if (_guiLogState[action.timestamp]) {
_guiLogState[action.timestamp].status = action.log.status;
_guiLogState[action.timestamp].response = action.log.response;
if (logState[actionTS]) {
const logItem = { [actionTS]: logState[actionTS] };
logItem[actionTS].status = action.log.status;
logItem[actionTS].response = action.log.response;
newLogState = trimHTTPLogs(Object.assign({}, logState, logItem));
} else {
_guiLogState[action.timestamp] = action.log;
const logItem = { [actionTS]: action.log };
newLogState = trimHTTPLogs(Object.assign({}, logState, logItem));
}
for (let timestamp in _guiLogState) {
if (_guiLogState[timestamp].status === 'error') {
_guiLogStateTrim.error.push(_guiLogState[timestamp]);
}
if (_guiLogState[timestamp].status === 'success') {
_guiLogStateTrim.success.push(_guiLogState[timestamp]);
}
if (_guiLogState[timestamp].status === 'pending') {
_guiLogStateTrim.pending.push(_guiLogState[timestamp]);
}
}
let _guiLogStateNew = {};
for (let _key in _guiLogStateTrim) {
if (_guiLogStateTrim[_key].length > HTTP_STACK_MAX_ENTRIES) {
_guiLogStateTrim[_key].shift();
}
for (let i = 0; i < _guiLogStateTrim[_key].length; i++) {
_guiLogStateNew[_guiLogStateTrim[_key][i].timestamp] = _guiLogStateTrim[_key][i];
}
}
return Object.assign({}, state, {
guiLog: _guiLogStateNew,
guiLog: newLogState,
});
default:
return state;

11
react/src/store.js

@ -14,16 +14,17 @@ const defaultState = {
Main: null,
};
const enhancers = compose(window.devToolsExtension ? window.devToolsExtension() : f => f);
// const enhancers = compose(window.devToolsExtension ? window.devToolsExtension() : f => f);
/* eslint-disable no-underscore-dangle */
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const enhancers = composeEnhancers(applyMiddleware(thunkMiddleware, loggerMiddleware));
const store = createStore(
rootReducer,
defaultState,
applyMiddleware(
thunkMiddleware,
loggerMiddleware,
),
enhancers);
/* eslint-enable */
export const history = syncHistoryWithStore(browserHistory, store);

Loading…
Cancel
Save