From b5535b2c09640b00aa046ec250ad1f409164f9c9 Mon Sep 17 00:00:00 2001 From: Kelly Mears Date: Tue, 11 Jul 2023 11:11:42 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20improve:=20tighten=20y-padding=20of?= =?UTF-8?q?=20dashboard=20elements=20(#2371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In response to feedback that new dashboard y padding takes up too much real estate this update returns it to what you'd see in 6.13.0. ## Type of change **PATCH: backwards compatible change** --- .../@roots/bud-dashboard/src/application.tsx | 48 ++- .../bud-dashboard/src/components/asset.tsx | 5 +- .../src/components/assets.component.tsx | 30 -- .../bud-dashboard/src/components/view.tsx | 28 +- sources/@roots/bud-dashboard/src/service.tsx | 2 +- .../@roots/bud-dashboard/src/views/assets.tsx | 96 +++-- .../bud-dashboard/src/views/compilation.tsx | 41 +- .../bud-dashboard/src/views/entrypoints.tsx | 49 ++- .../@roots/bud-dashboard/src/views/server.tsx | 85 ++-- .../test/__snapshots__/app.test.tsx.snap | 71 ++++ .../@roots/bud-dashboard/test/app.test.tsx | 377 ++++++------------ tests/util/project/config/bud.config.js | 2 - yarn.lock | 6 +- 13 files changed, 368 insertions(+), 472 deletions(-) delete mode 100644 sources/@roots/bud-dashboard/src/components/assets.component.tsx create mode 100644 sources/@roots/bud-dashboard/test/__snapshots__/app.test.tsx.snap diff --git a/sources/@roots/bud-dashboard/src/application.tsx b/sources/@roots/bud-dashboard/src/application.tsx index 8845902fe8..a52c4aa36b 100644 --- a/sources/@roots/bud-dashboard/src/application.tsx +++ b/sources/@roots/bud-dashboard/src/application.tsx @@ -2,7 +2,7 @@ import type {Bud} from '@roots/bud-framework' import type {StatsCompilation} from '@roots/bud-framework/config' import type {BudHandler} from '@roots/bud-support/errors' -import {exit, stdout} from 'node:process' +import {exit} from 'node:process' import Compilation from '@roots/bud-dashboard/views/compilation' import Debug from '@roots/bud-dashboard/views/debug' @@ -10,10 +10,7 @@ import Error from '@roots/bud-dashboard/views/node-error' import Server from '@roots/bud-dashboard/views/server' import { Box, - Fragment, type PropsWithChildren, - Spinner, - Text, useApp, useInput, useState, @@ -62,19 +59,12 @@ export const Application = ({ }: Props) => { if (error) return - return ( - - {!compilations?.length && status && ( - - - {` `} - {status} - - )} + if (!compilations?.length) return null + return ( + {compilations?.map((compilation, id) => { - if (isolated > 0 && id + 1 !== isolated) - return + if (isolated > 0 && id + 1 !== isolated) return null return ( @@ -124,12 +114,28 @@ export const TeletypeApplication = ({ const [isolated, setIsolated] = useState(0) useInput((key, input) => { - key === `a` && setDisplayAssets(!displayAssets) - key === `e` && setDisplayEntrypoints(!displayEntrypoints) - key === `d` && setDisplayDebug(!debug) - key === `s` && setDisplayServerInfo(!displayServerInfo) - key === `c` && setCompact(!compact) - key === `0` && setIsolated(0) + switch (key) { + case `a`: + setDisplayAssets(!displayAssets) + break + case `e`: + setDisplayEntrypoints(!displayEntrypoints) + break + case `d`: + setDisplayDebug(!debug) + break + case `s`: + setDisplayServerInfo(!displayServerInfo) + break + case `c`: + setCompact(!compact) + break + case `0`: + setIsolated(0) + break + default: + break + } new Array(9) .fill(0) diff --git a/sources/@roots/bud-dashboard/src/components/asset.tsx b/sources/@roots/bud-dashboard/src/components/asset.tsx index 5556e65e39..e4ea7c4bf0 100644 --- a/sources/@roots/bud-dashboard/src/components/asset.tsx +++ b/sources/@roots/bud-dashboard/src/components/asset.tsx @@ -22,6 +22,7 @@ const Asset = (asset: Props) => { > + {` `} {!asset.emitted ? figures.almostEqual : figures.pointerSmall} {` `} {asset.name} @@ -37,7 +38,9 @@ const Asset = (asset: Props) => { )} - {`${formatSize(asset.size)}`.trim()} + + {`${asset.size > 0 ? formatSize(asset.size) : `ø`}`.trim()} + ) diff --git a/sources/@roots/bud-dashboard/src/components/assets.component.tsx b/sources/@roots/bud-dashboard/src/components/assets.component.tsx deleted file mode 100644 index 1401c4b05b..0000000000 --- a/sources/@roots/bud-dashboard/src/components/assets.component.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import type {StatsAsset} from '@roots/bud-framework/config' - -import Asset from '@roots/bud-dashboard/components/asset' -import {useLongestNamedObjectLength} from '@roots/bud-dashboard/hooks/useLongestNamedObjectLength' -import {Box} from '@roots/bud-support/ink' - -interface Props { - assets?: Array & {name?: string; size?: number}> - minWidth?: number -} - -const Assets = ({assets, minWidth}: Props) => { - const fallbackMinWidth = useLongestNamedObjectLength(assets) - - if (!assets) return null - - return ( - - {assets.map((asset, index) => ( - - ))} - - ) -} - -export default Assets diff --git a/sources/@roots/bud-dashboard/src/components/view.tsx b/sources/@roots/bud-dashboard/src/components/view.tsx index d45d207e99..6923a1b8ff 100644 --- a/sources/@roots/bud-dashboard/src/components/view.tsx +++ b/sources/@roots/bud-dashboard/src/components/view.tsx @@ -1,25 +1,28 @@ import figures from '@roots/bud-support/figures' import {Box, Text} from '@roots/bud-support/ink' +export interface Props { + borderColor?: string + children?: any + compact?: boolean + footer?: any + head?: any + paddingY?: number +} + const View = ({ borderColor = `dim`, children, compact, footer, head, -}: { - borderColor?: string - children?: any - compact?: boolean - footer?: any - head?: any -}) => { + paddingY = 0, +}: Props) => { return ( - + {figures.lineDownRightArc} - {figures.line} {head} @@ -35,9 +38,9 @@ const View = ({ flexDirection="column" gap={1} overflowX="hidden" - paddingBottom={1} + paddingBottom={paddingY} paddingLeft={1} - paddingTop={1} + paddingTop={paddingY} width="100%" > {children} @@ -45,9 +48,8 @@ const View = ({ )} - + {figures.lineUpRightArc} - {figures.line} {footer} diff --git a/sources/@roots/bud-dashboard/src/service.tsx b/sources/@roots/bud-dashboard/src/service.tsx index a5ed47efd0..b417fc69e4 100644 --- a/sources/@roots/bud-dashboard/src/service.tsx +++ b/sources/@roots/bud-dashboard/src/service.tsx @@ -243,7 +243,7 @@ export class Dashboard extends Service implements BudDashboard { * the current state. */ renderApplication( - + - !asset.name?.endsWith(`js`) && - !asset.name?.endsWith(`css`) && - asset.size > 0, - ) - .slice(0, limit), - ) const compilationColor = useCompilationColor(compilation, `cyan`) if (!displayAssets) return null if (!compilation?.assets) return null - const assets = [...compilation.assets].filter( - asset => - !asset.name?.endsWith(`js`) && - !asset.name?.endsWith(`css`) && - asset.size > 0, - ) + const filteredAssets = [...compilation.assets] + .sort((a, b) => { + if (a.size < b.size) return 1 + if (a.size > b.size) return -1 + return 0 + }) + .sort((a, b) => { + if (a.emitted && !b.emitted) return -1 + if (!a.emitted && b.emitted) return 1 + return 0 + }) + .filter( + asset => + !asset.name?.endsWith(`js`) && + !asset.name?.endsWith(`css`) && + !asset.name?.endsWith(`map`) && + !asset.name?.endsWith(`json`), + ) + + const assets = filteredAssets.splice(limit * -1) - const hidden = assets.splice(limit) + if (assets.length === 0) return null - return ( - - ) -} - -const Footer = ({ - assets, - hidden, -}: { - assets?: Array<{size: number}> - hidden?: Array<{size: number}> -}) => { - if (!assets) return ... - - const totalFileSize = size( - [...assets, ...(hidden ?? [])].reduce( - (value, asset): number => value + asset.size, - 0, - ), + ) - return {`${totalFileSize}`} } diff --git a/sources/@roots/bud-dashboard/src/views/compilation.tsx b/sources/@roots/bud-dashboard/src/views/compilation.tsx index 177e29341c..2db4a75748 100644 --- a/sources/@roots/bud-dashboard/src/views/compilation.tsx +++ b/sources/@roots/bud-dashboard/src/views/compilation.tsx @@ -8,7 +8,6 @@ import {relative} from 'node:path' import Messages from '@roots/bud-dashboard/components/messages' import View from '@roots/bud-dashboard/components/view' import {useCompilationColor} from '@roots/bud-dashboard/hooks/useCompilationColor' -import figures from '@roots/bud-support/figures' import {duration} from '@roots/bud-support/human-readable' import {Box, Text} from '@roots/bud-support/ink' @@ -55,6 +54,7 @@ const Compilation = ({ } borderColor={compilationColor} footer={