From 7c1e5ff6969f67cd66a4b00d8b9ce414a7408abb Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Thu, 24 Oct 2019 17:29:36 -0500 Subject: [PATCH] fix(server): show milliseconds as unit for delta --- .../build-view/audit-list/numeric-diff.jsx | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/server/src/ui/routes/build-view/audit-list/numeric-diff.jsx b/packages/server/src/ui/routes/build-view/audit-list/numeric-diff.jsx index 1370cc2fc..44b5013cf 100644 --- a/packages/server/src/ui/routes/build-view/audit-list/numeric-diff.jsx +++ b/packages/server/src/ui/routes/build-view/audit-list/numeric-diff.jsx @@ -41,7 +41,7 @@ const getUnitFromAudit = (audit, groupId) => { return 'none'; }; -/** @param {number} x @param {{asDelta?: boolean, unit: 'ms'|'bytes'|'none', withSuffix?: boolean}} options */ +/** @param {number} x @param {{asDelta?: boolean, unit: 'ms'|'bytes'|'none', withSuffix?: boolean, preventSecondsConversion?: boolean}} options */ const toDisplay = (x, options) => { const {asDelta = false, withSuffix = false, unit = 'none'} = options; let value = Math.round(x); @@ -51,7 +51,7 @@ const toDisplay = (x, options) => { if (unit === 'ms') { suffix = ' ms'; - if (Math.abs(value) >= 50) { + if (Math.abs(value) >= 500 && !options.preventSecondsConversion) { value /= 1000; fractionDigits = 1; suffix = ' s'; @@ -107,11 +107,18 @@ export const NumericDiff = props => { const boxRight = 100 - (100 * (maxValue - lowerLimit)) / range; const deltaType = getDeltaLabel(delta, 'audit'); const minValueIsCurrentValue = minValue === currentNumericValue; + const hoverDisplay = `${toDisplay(baseNumericValue, {unit, withSuffix: true})} to ${toDisplay( + currentNumericValue, + { + withSuffix: true, + unit, + } + )}`; if (props.showAsNarrow) { return ( -
- {toDisplay(delta, {asDelta: true, withSuffix: true, unit})} +
+ {toDisplay(delta, {asDelta: true, withSuffix: true, preventSecondsConversion: true, unit})}
); } @@ -127,13 +134,7 @@ export const NumericDiff = props => { 'audit-numeric-diff__box--regression': deltaType === 'regression', })} style={{left: `${boxLeft}%`, right: `${boxRight}%`}} - data-tooltip={`${toDisplay(baseNumericValue, {unit, withSuffix: true})} to ${toDisplay( - currentNumericValue, - { - withSuffix: true, - unit, - } - )}`} + data-tooltip={hoverDisplay} >
{ })} style={{[minValueIsCurrentValue ? 'right' : 'left']: '100%'}} > - {toDisplay(delta, {asDelta: true, withSuffix: true, unit})} + {toDisplay(delta, { + asDelta: true, + withSuffix: true, + preventSecondsConversion: true, + unit, + })}