From 9e7313afc83cab4eeb8528c983743821e73ecf60 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Tue, 1 Nov 2016 17:44:59 +0100 Subject: [PATCH] Proper order for status logs (#3055) (#3062) --- .../views/Status/components/Debug/Debug.css | 17 +++++++ js/src/views/Status/components/Debug/Debug.js | 44 +++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/js/src/views/Status/components/Debug/Debug.css b/js/src/views/Status/components/Debug/Debug.css index 9db3d2b5b..2199b97ce 100644 --- a/js/src/views/Status/components/Debug/Debug.css +++ b/js/src/views/Status/components/Debug/Debug.css @@ -39,9 +39,26 @@ .logs { margin: 0; max-width: 100%; +} + +.log { + font-family: monospace; white-space: pre-line; word-wrap: break-word; color: #aaa; + margin: 0.5em 0; + display: flex; + align-items: center; +} + +.logDate { + color: green; + font-size: 0.85em; + margin-right: 0.5em; +} + +.logText { + flex: 1; } .stopped { diff --git a/js/src/views/Status/components/Debug/Debug.js b/js/src/views/Status/components/Debug/Debug.js index 5be4d594f..654662b84 100644 --- a/js/src/views/Status/components/Debug/Debug.js +++ b/js/src/views/Status/components/Debug/Debug.js @@ -18,6 +18,7 @@ import React, { Component, PropTypes } from 'react'; import AvPause from 'material-ui/svg-icons/av/pause'; import AvPlay from 'material-ui/svg-icons/av/play-arrow'; import AvReplay from 'material-ui/svg-icons/av/replay'; +import ReorderIcon from 'material-ui/svg-icons/action/reorder'; import { Container, ContainerTitle } from '../../../../ui'; @@ -32,6 +33,10 @@ export default class Debug extends Component { nodeStatus: PropTypes.object.isRequired } + state = { + reversed: true + } + render () { const { nodeStatus } = this.props; const { devLogsLevels } = nodeStatus; @@ -66,16 +71,43 @@ export default class Debug extends Component { renderLogs () { const { nodeStatus } = this.props; + const { reversed } = this.state; const { devLogs } = nodeStatus; + const dateRegex = /^(\d{4}.\d{2}.\d{2}.\d{2}.\d{2}.\d{2})(.*)$/i; + if (!devLogs) { return null; } + const logs = reversed + ? [].concat(devLogs).reverse() + : [].concat(devLogs); + + const text = logs + .map((log, index) => { + const logDate = dateRegex.exec(log); + + if (!logDate) { + return ( +

+ { log } +

+ ); + } + + return ( +

+ { logDate[1] } + { logDate[2] } +

+ ); + }); + return ( -
-        { devLogs.reverse().join('\n') }
-      
+
+ { text } +
); } @@ -89,6 +121,7 @@ export default class Debug extends Component {
{ toggleButton } +
); } @@ -105,4 +138,9 @@ export default class Debug extends Component { toggleStatusLogs(!devLogsEnabled); } + + reverse = () => { + const { reversed } = this.state; + this.setState({ reversed: !reversed }); + } }