From 706743447672c0f0b787a2bb0fa6bf39e98e94ad Mon Sep 17 00:00:00 2001 From: pbca26 Date: Fri, 2 Jun 2017 20:16:34 +0300 Subject: [PATCH] refactored notifications component --- .../src/components/dashboard/notifications.js | 61 +++++++++---------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/react/src/components/dashboard/notifications.js b/react/src/components/dashboard/notifications.js index c7cc783..1acf7f4 100755 --- a/react/src/components/dashboard/notifications.js +++ b/react/src/components/dashboard/notifications.js @@ -12,10 +12,12 @@ class Notifications extends React.Component { super(props); this.state = { displayModal: false, - totalCalls: 0, - totalErrorCalls: 0, - totalSuccessCalls: 0, - totalPendingCalls: 0, + calls: { + total: 0, + error: 0, + success: 0, + pending: 0, + }, activeTab: 2, guiLog: null, }; @@ -33,31 +35,27 @@ class Notifications extends React.Component { if (this.props.Dashboard && this.props.Dashboard.guiLog) { const _guiLog = this.props.Dashboard.guiLog; - let totalCalls = Object.keys(_guiLog).length; - let totalErrorCalls = 0; - let totalSuccessCalls = 0; - let totalPendingCalls = 0; + let _callsLength = { + total: Object.keys(_guiLog).length, + error: 0, + success: 0, + pending: 0, + } + let guiLogToArray = []; for (let timestamp in _guiLog) { guiLogToArray.push(_guiLog[timestamp]); - - if (_guiLog[timestamp].status === 'error') { - totalErrorCalls++; - } - if (_guiLog[timestamp].status === 'success') { - totalSuccessCalls++; - } - if (_guiLog[timestamp].status === 'pending') { - totalPendingCalls++; - } + _callsLength[_guiLog[timestamp].status]++; } this.setState(Object.assign({}, this.state, { - totalCalls, - totalErrorCalls, - totalSuccessCalls, - totalPendingCalls, + calls: { + total: _callsLength.total, + error: _callsLength.error, + success: _callsLength.success, + pending: _callsLength.pending, + }, guiLog: guiLogToArray, })); } @@ -70,7 +68,6 @@ class Notifications extends React.Component { let _guiLog = this.state.guiLog; _guiLog = sortByDate(_guiLog); let items = []; - let index = 0; for (let i = 0; i < _guiLog.length; i++) { if (_guiLog[i].status === type) { @@ -78,7 +75,7 @@ class Notifications extends React.Component { items.push(
-
{ index + 1 }.
+
{ i + 1 }.
Time: { secondsToString(_logItem.timestamp, true, true) }
@@ -101,8 +98,6 @@ class Notifications extends React.Component {
); } - - index++; } return items; @@ -123,21 +118,21 @@ class Notifications extends React.Component { this.openTab(0) }> - Success ({ this.state.totalSuccessCalls }) + Success ({ this.state.calls.success })
  • this.openTab(1) }> - Error ({ this.state.totalErrorCalls }) + Error ({ this.state.calls.error })
  • this.openTab(2) }> - Pending ({ this.state.totalPendingCalls }) + Pending ({ this.state.calls.pending })
  • @@ -192,10 +187,10 @@ class Notifications extends React.Component {
    - { this.state.totalSuccessCalls } - { this.state.totalErrorCalls } - { this.state.totalPendingCalls } -
    + { this.state.calls.success } + { this.state.calls.error } + { this.state.calls.pending } +