Skip to content

Commit

Permalink
improve table UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastil committed Jun 23, 2024
1 parent 3094bc1 commit ef2bb7a
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions .github/actions/metrics-report/src/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function logBundleSize(bundleSize, isIndented) {
[
[isIndented ? ' ' : '', bundleSize.label].join('').padEnd(30),
[
getSizeInKb(bundleSize.size),
`${getSizeInKb(bundleSize.sizeMinified)} minified`,
`${getSizeInKb(bundleSize.sizeBrotliCompressed)} brotli compressed`,
getSizeInKb(bundleSize.size).padStart(14),
`${getSizeInKb(bundleSize.sizeMinified).padStart(14)} minified`,
`${getSizeInKb(bundleSize.sizeBrotliCompressed).padStart(14)} brotli compressed`,
].join(' '),
].join(''),
)
Expand All @@ -71,15 +71,13 @@ function logBundleSize(bundleSize, isIndented) {
* @param {number} size
*/
function getSizeInKb(size) {
return (size / 1024)
.toLocaleString('en-GB', {
style: 'unit',
unit: 'kilobyte',
unitDisplay: 'short',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})
.padStart(14)
return (size / 1024).toLocaleString('en-GB', {
style: 'unit',
unit: 'kilobyte',
unitDisplay: 'short',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})
}

/**
Expand Down Expand Up @@ -142,7 +140,9 @@ function getBundleSizeTable(localBundleSizes, baseBundleSizes) {
*/
function getBundleSizeRow(bundleSize, baseBundleSize, isIndented) {
return [
[isIndented ? '→ ' : '', '`', bundleSize.label, '`'].join('').padEnd(30),
nonBreaking(
[isIndented ? '› ' : '', '<code>', bundleSize.label, '</code>'].join(''),
).padEnd(30),
getBundleSizeDifference(bundleSize.size, baseBundleSize?.size),
getBundleSizeDifference(bundleSize.sizeMinified, baseBundleSize?.sizeMinified),
getBundleSizeDifference(
Expand All @@ -158,11 +158,13 @@ function getBundleSizeRow(bundleSize, baseBundleSize, isIndented) {
* @param {number=} baseSize
*/
function getBundleSizeDifference(size, baseSize) {
const sizeString = nonBreaking(getSizeInKb(size))

if (baseSize) {
return getSizeInKb(size) + ' ' + getSizeDifference(size, baseSize)
return sizeString + ' ' + nonBreaking(getSizeDifference(size, baseSize))
}

return getSizeInKb(size)
return sizeString
}

/**
Expand Down Expand Up @@ -296,3 +298,10 @@ function getHtmlLinesToIndent(elements) {
return [openingTag, innerHtmlLines, closingTag]
})
}

/**
* @param {string} text
*/
function nonBreaking(text) {
return text.replace(/ /g, '&nbsp;')
}

0 comments on commit ef2bb7a

Please sign in to comment.