From d87f54d4a4f36e1a0da8babf4c6e8ad438e71144 Mon Sep 17 00:00:00 2001 From: badrAZ Date: Wed, 24 Jan 2018 18:14:35 +0100 Subject: [PATCH] feat(job/log): display start/end time for each call and precise its duration (#2284) Fixes part of #2270 --- src/common/intl/index.js | 37 +++++++++++++++++++++++++++-------- src/common/intl/messages.js | 4 ++++ src/xo-app/logs/index.js | 39 ++++++++++++++++++++++++++++++++----- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/common/intl/index.js b/src/common/intl/index.js index 15f76ea58..124d18101 100644 --- a/src/common/intl/index.js +++ b/src/common/intl/index.js @@ -6,8 +6,10 @@ import React, { Component } from 'react' import { connect } from 'react-redux' import { FormattedMessage, IntlProvider as IntlProvider_ } from 'react-intl' -import messages from './messages' import locales from './locales' +import messages from './messages' +import Tooltip from '.././tooltip' +import { createSelector } from '.././selectors' // =================================================================== @@ -74,17 +76,36 @@ export class IntlProvider extends Component { } } +const parseDuration = milliseconds => { + let seconds = Math.floor(milliseconds / 1e3) + const days = Math.floor(seconds / 86400) + seconds -= days * 86400 + const hours = Math.floor(seconds / 3600) + seconds -= hours * 3600 + const minutes = Math.floor(seconds / 60) + seconds -= minutes * 60 + return { days, hours, minutes, seconds } +} + @connect(({ lang }) => ({ lang })) export class FormattedDuration extends Component { + _parseDuration = createSelector(() => this.props.duration, parseDuration) + + _humanizeDuration = createSelector( + () => this.props.duration, + () => this.props.lang, + (duration, lang) => + moment + .duration(duration) + .locale(lang) + .humanize() + ) + render () { - const { duration, lang } = this.props return ( - - {moment - .duration(duration) - .locale(lang) - .humanize()} - + + {this._humanizeDuration()} + ) } } diff --git a/src/common/intl/messages.js b/src/common/intl/messages.js index 691a13304..f69fc88b4 100644 --- a/src/common/intl/messages.js +++ b/src/common/intl/messages.js @@ -1705,6 +1705,10 @@ const messages = { expiresOn: 'expires on {date}', xosanInstallXoaPlugin: 'Install XOA plugin first', xosanLoadXoaPlugin: 'Load XOA plugin first', + + // ----- Utils ----- + durationFormat: + '{days, plural, =0 {} one {# day } other {# days }}{hours, plural, =0 {} one {# hour } other {# hours }}{minutes, plural, =0 {} one {# minute } other {# minutes }}{seconds, plural, =0 {} one {# second} other {# seconds}}', } forEach(messages, function (message, id) { if (isString(message)) { diff --git a/src/xo-app/logs/index.js b/src/xo-app/logs/index.js index 906809d78..71187e79f 100644 --- a/src/xo-app/logs/index.js +++ b/src/xo-app/logs/index.js @@ -162,11 +162,40 @@ class Log extends BaseComponent { ,
, ])} - {end !== undefined && - _.keyValue( - _('jobDuration'), - - )} + {_.keyValue( + _('jobStart'), + + )} +
+ {end !== undefined && ( +
+ {_.keyValue( + _('jobEnd'), + + )} +
+ {_.keyValue( + _('jobDuration'), + + )} +
+ )} {returnedValue != null && (