From 575c1d082ae467f69021e68693972a8826a93236 Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Thu, 1 Oct 2026 15:45:51 -0400 Subject: [PATCH 01/10] Add new quota tiles --- app/components/CapacityBar.tsx | 116 ------------- app/components/CapacityBars.tsx | 54 ------ app/components/QuotaTile.tsx | 212 +++++++++++++++++++++++ app/forms/silo-quotas-edit.tsx | 18 +- app/pages/SiloUtilizationPage.tsx | 7 +- app/pages/system/UtilizationPage.tsx | 7 +- app/pages/system/silos/SiloQuotasTab.tsx | 64 ++----- test/e2e/silos.e2e.ts | 45 +++-- 8 files changed, 272 insertions(+), 251 deletions(-) delete mode 100644 app/components/CapacityBar.tsx delete mode 100644 app/components/CapacityBars.tsx create mode 100644 app/components/QuotaTile.tsx diff --git a/app/components/CapacityBar.tsx b/app/components/CapacityBar.tsx deleted file mode 100644 index d777867dbd..0000000000 --- a/app/components/CapacityBar.tsx +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * Copyright Oxide Computer Company - */ - -import type { JSX } from 'react' - -import { BigNum } from '~/ui/lib/BigNum' -import { percentage, splitDecimal } from '~/util/math' - -export const CapacityBar = ({ - icon, - title, - unit, - provisioned, - capacity, - capacityLabel, - provisionedLabel = 'Provisioned', - includeUnit = true, -}: { - icon: JSX.Element - title: string - unit: string - provisioned: T - capacity: T - provisionedLabel?: string - capacityLabel: string - includeUnit?: boolean -}) => { - const pct = percentage(provisioned, capacity) - const unitElt = includeUnit ? <> {unit} : null - - return ( -
-
- - -
-
- -
-
- - -
-
- ) -} - -type TitleCellProps = { icon: JSX.Element; title: string; unit: string } -function TitleCell({ icon, title, unit }: TitleCellProps) { - return ( -
-
- - {icon} - - {title} - ({unit}) -
-
- ) -} - -function PctCell({ pct }: { pct: number }) { - // NaN happens when both top and bottom are 0 - if (Number.isNaN(pct)) { - return ( -
-
—
-
%
-
- ) - } - - const [wholeNumber, decimal] = splitDecimal(pct) - return ( -
-
{wholeNumber}
-
{decimal}%
-
- ) -} - -function Bar({ pct }: { pct: number }) { - return ( -
-
-
-
- ) -} - -type ValueCellProps = { - label: string - value: number | bigint - unit: React.ReactNode -} - -function ValueCell({ label, value, unit }: ValueCellProps) { - return ( -
-
{label}
-
- - {unit} -
-
- ) -} diff --git a/app/components/CapacityBars.tsx b/app/components/CapacityBars.tsx deleted file mode 100644 index 3b59812bf4..0000000000 --- a/app/components/CapacityBars.tsx +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * Copyright Oxide Computer Company - */ - -import type { VirtualResourceCounts } from '@oxide/api' -import { Cpu16Icon, Ram16Icon, Ssd16Icon } from '@oxide/design-system/icons/react' - -import { bytesToGiB, bytesToTiB } from '~/util/units' - -import { CapacityBar } from './CapacityBar' - -export const CapacityBars = ({ - allocated, - provisioned, - allocatedLabel, -}: { - allocated: VirtualResourceCounts - provisioned: VirtualResourceCounts - allocatedLabel: string -}) => { - return ( -
- } - title="CPU" - unit="vCPUs" - provisioned={provisioned.cpus} - capacity={allocated.cpus} - includeUnit={false} - capacityLabel={allocatedLabel} - /> - } - title="MEMORY" - unit="GiB" - provisioned={bytesToGiB(provisioned.memory)} - capacity={bytesToGiB(allocated.memory)} - capacityLabel={allocatedLabel} - /> - } - title="STORAGE" - unit="TiB" - provisioned={bytesToTiB(provisioned.storage)} - capacity={bytesToTiB(allocated.storage)} - capacityLabel={allocatedLabel} - /> -
- ) -} diff --git a/app/components/QuotaTile.tsx b/app/components/QuotaTile.tsx new file mode 100644 index 0000000000..10cc9edd47 --- /dev/null +++ b/app/components/QuotaTile.tsx @@ -0,0 +1,212 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * Copyright Oxide Computer Company + */ + +import type { ReactNode } from 'react' + +import type { VirtualResourceCounts } from '@oxide/api' +import { Cpu16Icon, Ram16Icon, Ssd16Icon } from '@oxide/design-system/icons/react' + +import { BigNum } from '~/ui/lib/BigNum' +import { percentage, round, splitDecimal } from '~/util/math' +import { bytesToGiB, bytesToTiB } from '~/util/units' + +type Resource = { + icon: ReactNode + title: string + unit: string + provisioned: number + quota: number +} + +/** Convert API byte counts into the display units for each tile */ +function getResources( + provisioned: VirtualResourceCounts, + allocated: VirtualResourceCounts, + storageUnit: 'GiB' | 'TiB' +): Resource[] { + const toStorageUnit = storageUnit === 'GiB' ? bytesToGiB : bytesToTiB + return [ + { + icon: , + title: 'CPU', + unit: 'vCPUs', + provisioned: provisioned.cpus, + quota: allocated.cpus, + }, + { + icon: , + title: 'Memory', + unit: 'GiB', + provisioned: bytesToGiB(provisioned.memory), + quota: bytesToGiB(allocated.memory), + }, + { + icon: , + title: 'Storage', + unit: storageUnit, + provisioned: toStorageUnit(provisioned.storage), + quota: toStorageUnit(allocated.storage), + }, + ] +} + +const IconBox = ({ children }: { children: ReactNode }) => ( +
+ {children} +
+) + +function Pct({ pct }: { pct: number }) { + // NaN happens when both provisioned and quota are 0 + if (Number.isNaN(pct)) { + return ( + + —% + + ) + } + const [wholeNumber, decimal] = splitDecimal(pct) + return ( + + {wholeNumber} + {decimal}% + + ) +} + +function Bar({ pct }: { pct: number }) { + // provisioned can exceed the quota if the quota was lowered below current usage + const width = Number.isNaN(pct) ? 0 : Math.min(pct, 100) + return ( +
+
+
+
+ ) +} + +type QuotaTileProps = Resource & { + /** Show a bar and percentage of the quota that is provisioned */ + showBar?: boolean +} + +export function QuotaTile({ + icon, + title, + unit, + provisioned, + quota, + showBar, +}: QuotaTileProps) { + const available = round(quota - provisioned, 2) + const pct = percentage(provisioned, quota) + return ( +
+
+
+ {icon} +
+
{title}
+
+ {' '} + {unit} +
+
+
+ {showBar && ( +
+ +
+ )} +
+ {showBar && ( +
+ +
+ )} +
+
+
Provisioned
+
+ +
+
+ {available < 0 ? ( +
+
Over quota
+
+ +
+
+ ) : ( +
+
Available
+
+ +
+
+ )} +
+
+ ) +} + +type QuotaTilesProps = { + provisioned: VirtualResourceCounts + allocated: VirtualResourceCounts + storageUnit: 'GiB' | 'TiB' + showBar?: boolean +} + +export const QuotaTiles = ({ + provisioned, + allocated, + storageUnit, + showBar, +}: QuotaTilesProps) => ( +
+ {getResources(provisioned, allocated, storageUnit).map((r) => ( + + ))} +
+) + +/** Compact percent-of-quota tiles, used in the edit quotas side modal */ +export const QuotaUsageChips = ({ + provisioned, + allocated, +}: { + provisioned: VirtualResourceCounts + allocated: VirtualResourceCounts +}) => ( +
+ {getResources(provisioned, allocated, 'GiB').map( + ({ icon, title, provisioned, quota }) => ( +
+ {icon} +
+
{title}
+
+ +
+
+
+ ) + )} +
+) diff --git a/app/forms/silo-quotas-edit.tsx b/app/forms/silo-quotas-edit.tsx index 0657159664..7d78a94469 100644 --- a/app/forms/silo-quotas-edit.tsx +++ b/app/forms/silo-quotas-edit.tsx @@ -12,8 +12,10 @@ import { Cloud16Icon } from '@oxide/design-system/icons/react' import { NumberField } from '~/components/form/fields/NumberField' import { SideModalForm } from '~/components/form/SideModalForm' +import { QuotaUsageChips } from '~/components/QuotaTile' import { addToast } from '~/stores/toast' import { BigNum } from '~/ui/lib/BigNum' +import { FormDivider } from '~/ui/lib/Divider' import { Message } from '~/ui/lib/Message' import { SideModalFormDocs } from '~/ui/lib/ModalLinks' import { ResourceLabel } from '~/ui/lib/SideModal' @@ -89,15 +91,21 @@ export function EditQuotasSideModalForm({ silo, quotas, provisioned, onDismiss } loading={updateQuotas.isPending || updateQuotas.isSuccess} submitError={updateQuotas.error} > +
+

Quota used

+ +
+
- diff --git a/app/pages/system/UtilizationPage.tsx b/app/pages/system/UtilizationPage.tsx index 95b5d60d17..f58d06308f 100644 --- a/app/pages/system/UtilizationPage.tsx +++ b/app/pages/system/UtilizationPage.tsx @@ -20,10 +20,10 @@ import { } from '@oxide/api' import { Metrics16Icon, Metrics24Icon } from '@oxide/design-system/icons/react' -import { CapacityBars } from '~/components/CapacityBars' import { DocsPopover } from '~/components/DocsPopover' import { useDateTimeRangePicker } from '~/components/form/fields/DateTimeRangePicker' import { QueryParamTabs } from '~/components/QueryParamTabs' +import { QuotaTiles } from '~/components/QuotaTile' import { useIntervalPicker } from '~/components/RefetchIntervalPicker' import { SystemMetric } from '~/components/SystemMetric' import { EditQuotasSideModalForm } from '~/forms/silo-quotas-edit' @@ -74,10 +74,11 @@ export default function SystemUtilizationPage() { /> - diff --git a/app/pages/system/silos/SiloQuotasTab.tsx b/app/pages/system/silos/SiloQuotasTab.tsx index b82b2098e2..87e3952aa6 100644 --- a/app/pages/system/silos/SiloQuotasTab.tsx +++ b/app/pages/system/silos/SiloQuotasTab.tsx @@ -10,14 +10,14 @@ import { useState } from 'react' import { type LoaderFunctionArgs } from 'react-router' import { api, q, queryClient, usePrefetchedQuery } from '~/api' +import { QuotaTiles } from '~/components/QuotaTile' import { EditQuotasSideModalForm } from '~/forms/silo-quotas-edit' import { makeCrumb } from '~/hooks/use-crumbs' import { getSiloSelector, useSiloSelector } from '~/hooks/use-params' import { Button } from '~/ui/lib/Button' -import { Table } from '~/ui/lib/Table' -import { ValueUnit } from '~/ui/lib/ValueUnit' +import { CardBlock, LearnMore } from '~/ui/lib/CardBlock' +import { docLinks } from '~/util/links' import type * as PP from '~/util/path-params' -import { bytesToGiB } from '~/util/units' const siloUtil = ({ silo }: PP.Silo) => q(api.siloUtilizationView, { path: { silo } }) @@ -37,49 +37,21 @@ export default function SiloQuotasTab() { return ( <> - - - - Resource - Provisioned - Quota - - - - - CPU - - - - - - - - - Memory - - - - - - - - - Storage - - - - - - - - -
-
- -
+ + + + + + + + + + {editing && ( { await page.goto('/system/silos/maze-war') await page.getByRole('tab', { name: 'Quotas' }).click() - const table = page.getByRole('table') - await expectRowVisible(table, { - Resource: 'CPU', - Provisioned: '30 vCPUs', - Quota: '50 vCPUs', - }) - await expectRowVisible(table, { - Resource: 'Memory', - Provisioned: '234 GiB', - Quota: '300 GiB', - }) - await expectRowVisible(table, { - Resource: 'Storage', - Provisioned: '4403.2 GiB', - Quota: '7168 GiB', - }) + const cpu = page.getByRole('region', { name: 'CPU' }) + const memory = page.getByRole('region', { name: 'Memory' }) + const storage = page.getByRole('region', { name: 'Storage' }) + await expect(cpu).toContainText('50 vCPUs') + await expect(cpu).toContainText('Provisioned30 vCPUs') + await expect(cpu).toContainText('Available20 vCPUs') + await expect(memory).toContainText('300 GiB') + await expect(memory).toContainText('Provisioned234 GiB') + await expect(storage).toContainText('7,168 GiB') + await expect(storage).toContainText('Provisioned4,403.2 GiB') const sideModal = page.getByRole('dialog', { name: 'Edit quotas' }) const edit = page.getByRole('button', { name: 'Edit quotas' }) @@ -566,23 +560,24 @@ test('Quotas tab', async ({ page }) => { await expect(sideModal).toBeVisible() // test validation on empty field - const memory = page.getByRole('textbox', { name: 'Memory' }) - await memory.clear() + const memoryInput = sideModal.getByRole('textbox', { name: 'Memory' }) + await memoryInput.clear() await submit.click() - await expect(sideModal.getByText('Memory is required')).toBeVisible() + await expect(sideModal.getByText('Memory quota is required')).toBeVisible() // try to type in a negative number HAHA YOU CAN'T - await memory.fill('-5') - await expect(memory).toHaveValue('') + await memoryInput.fill('-5') + await expect(memoryInput).toHaveValue('') // only change one - await memory.fill('50') + await memoryInput.fill('50') await submit.click() await expect(sideModal).toBeHidden() // only one changes, the others stay the same - await expectRowVisible(table, { Resource: 'CPU', Quota: '50 vCPUs' }) - await expectRowVisible(table, { Resource: 'Memory', Quota: '50 GiB' }) - await expectRowVisible(table, { Resource: 'Storage', Quota: '7168 GiB' }) + await expect(cpu).toContainText('50 vCPUs') + // quota now below provisioned + await expect(memory).toContainText('Over quota184 GiB') + await expect(storage).toContainText('7,168 GiB') }) From 2f53ba08be0c09d66ded011b4c540296a63bb18f Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Thu, 1 Oct 2026 17:06:45 -0400 Subject: [PATCH 02/10] font size adjustment --- app/components/QuotaTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/QuotaTile.tsx b/app/components/QuotaTile.tsx index 10cc9edd47..b57bdfdc2f 100644 --- a/app/components/QuotaTile.tsx +++ b/app/components/QuotaTile.tsx @@ -74,7 +74,7 @@ function Pct({ pct }: { pct: number }) { return ( {wholeNumber} - {decimal}% + {decimal}% ) } From c2cc92a46cb3dcb4b174c55ca44166867c83b127 Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Fri, 2 Oct 2026 16:27:43 -0400 Subject: [PATCH 03/10] more refactoring --- app/components/QuotaTile.tsx | 32 ++++++++++++++++---------------- test/e2e/silos.e2e.ts | 9 ++++----- test/e2e/utilization.e2e.ts | 12 +++++++++--- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/app/components/QuotaTile.tsx b/app/components/QuotaTile.tsx index b57bdfdc2f..3e7c627b8f 100644 --- a/app/components/QuotaTile.tsx +++ b/app/components/QuotaTile.tsx @@ -56,14 +56,21 @@ function getResources( } const IconBox = ({ children }: { children: ReactNode }) => ( -
+
{children}
) -function Pct({ pct }: { pct: number }) { - // NaN happens when both provisioned and quota are 0 - if (Number.isNaN(pct)) { +// isCompact controls the size of the decimal part of the percentage; true for sidebar usage +function Pct({ + pct, + decimalClass, +}: { + pct: number + decimalClass: 'text-sans-md' | 'text-sans-xl' +}) { + // NaN when provisioned and quota are both 0, Infinity when only quota is 0 + if (!Number.isFinite(pct)) { return ( —% @@ -74,7 +81,7 @@ function Pct({ pct }: { pct: number }) { return ( {wholeNumber} - {decimal}% + {decimal}% ) } @@ -98,14 +105,7 @@ type QuotaTileProps = Resource & { showBar?: boolean } -export function QuotaTile({ - icon, - title, - unit, - provisioned, - quota, - showBar, -}: QuotaTileProps) { +function QuotaTile({ icon, title, unit, provisioned, quota, showBar }: QuotaTileProps) { const available = round(quota - provisioned, 2) const pct = percentage(provisioned, quota) return ( @@ -118,7 +118,7 @@ export function QuotaTile({ {icon}
{title}
-
+
{' '} {unit}
@@ -126,7 +126,7 @@ export function QuotaTile({
{showBar && (
- +
)}
@@ -202,7 +202,7 @@ export const QuotaUsageChips = ({
{title}
- +
diff --git a/test/e2e/silos.e2e.ts b/test/e2e/silos.e2e.ts index 47c10ebf47..12f5b51fa9 100644 --- a/test/e2e/silos.e2e.ts +++ b/test/e2e/silos.e2e.ts @@ -545,12 +545,11 @@ test('Quotas tab', async ({ page }) => { const memory = page.getByRole('region', { name: 'Memory' }) const storage = page.getByRole('region', { name: 'Storage' }) await expect(cpu).toContainText('50 vCPUs') - await expect(cpu).toContainText('Provisioned30 vCPUs') - await expect(cpu).toContainText('Available20 vCPUs') + await expect(cpu).toContainText('Provisioned30Available20') await expect(memory).toContainText('300 GiB') - await expect(memory).toContainText('Provisioned234 GiB') + await expect(memory).toContainText('Provisioned234Available66') await expect(storage).toContainText('7,168 GiB') - await expect(storage).toContainText('Provisioned4,403.2 GiB') + await expect(storage).toContainText('Provisioned4,403.2Available2,764.8') const sideModal = page.getByRole('dialog', { name: 'Edit quotas' }) const edit = page.getByRole('button', { name: 'Edit quotas' }) @@ -578,6 +577,6 @@ test('Quotas tab', async ({ page }) => { // only one changes, the others stay the same await expect(cpu).toContainText('50 vCPUs') // quota now below provisioned - await expect(memory).toContainText('Over quota184 GiB') + await expect(memory).toContainText('Over quota184') await expect(storage).toContainText('7,168 GiB') }) diff --git a/test/e2e/utilization.e2e.ts b/test/e2e/utilization.e2e.ts index b3cbd56f6e..aff50860a9 100644 --- a/test/e2e/utilization.e2e.ts +++ b/test/e2e/utilization.e2e.ts @@ -24,7 +24,9 @@ test.describe('System utilization', () => { await page.goto('/system/utilization') await expect(page.getByRole('heading', { name: 'Utilization' })).toBeVisible() - await expect(page.getByText('Provisioned416 GiB')).toBeVisible() + await expect(page.getByRole('region', { name: 'Memory' })).toContainText( + 'Provisioned416' + ) await expect(page.getByText('Provisioned / Quota')).toBeVisible() @@ -147,7 +149,9 @@ test.describe('Silo utilization', () => { await page.goto('/utilization') await expect(page.getByRole('heading', { name: 'Utilization' })).toBeVisible() // Capacity bars are showing up - await expect(page.getByText('Provisioned234 GiB')).toBeVisible() + await expect(page.getByRole('region', { name: 'Memory' })).toContainText( + 'Provisioned234Available66' + ) }) test('works for dev user', async ({ browser }) => { @@ -155,7 +159,9 @@ test.describe('Silo utilization', () => { await page.goto('/utilization') await expect(page.getByRole('heading', { name: 'Utilization' })).toBeVisible() // Capacity bars are showing up - await expect(page.getByText('Provisioned234 GiB')).toBeVisible() + await expect(page.getByRole('region', { name: 'Memory' })).toContainText( + 'Provisioned234Available66' + ) }) }) From b95e108c7af93269553ae5e5bcde3dfde18e7d7d Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Fri, 2 Oct 2026 17:08:19 -0400 Subject: [PATCH 04/10] a few more tweaks --- app/components/QuotaTile.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/components/QuotaTile.tsx b/app/components/QuotaTile.tsx index 3e7c627b8f..fde5211f66 100644 --- a/app/components/QuotaTile.tsx +++ b/app/components/QuotaTile.tsx @@ -113,15 +113,15 @@ function QuotaTile({ icon, title, unit, provisioned, quota, showBar }: QuotaTile aria-label={title} className="border-default bg-default w-full min-w-min rounded-lg border" > -
+
{icon}
{title}
-
+ {' '} {unit} -
+
{showBar && ( From fc337744482614fed6904afd14612c897605c44a Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Sat, 3 Oct 2026 09:31:02 -0400 Subject: [PATCH 05/10] cleanup --- app/components/QuotaTile.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/components/QuotaTile.tsx b/app/components/QuotaTile.tsx index fde5211f66..9992aee040 100644 --- a/app/components/QuotaTile.tsx +++ b/app/components/QuotaTile.tsx @@ -61,14 +61,7 @@ const IconBox = ({ children }: { children: ReactNode }) => (
) -// isCompact controls the size of the decimal part of the percentage; true for sidebar usage -function Pct({ - pct, - decimalClass, -}: { - pct: number - decimalClass: 'text-sans-md' | 'text-sans-xl' -}) { +function Pct({ pct, decimalClass }: { pct: number; decimalClass: string }) { // NaN when provisioned and quota are both 0, Infinity when only quota is 0 if (!Number.isFinite(pct)) { return ( From 77c60198adfa294e1267a683c2056afb837a8922 Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Mon, 5 Oct 2026 10:04:44 -0400 Subject: [PATCH 06/10] revert copy change --- app/forms/silo-quotas-edit.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/forms/silo-quotas-edit.tsx b/app/forms/silo-quotas-edit.tsx index 7d78a94469..c3f81854df 100644 --- a/app/forms/silo-quotas-edit.tsx +++ b/app/forms/silo-quotas-edit.tsx @@ -97,7 +97,7 @@ export function EditQuotasSideModalForm({ silo, quotas, provisioned, onDismiss }
From ac31d1e4de0485db84e327f55857cfd2daaf962a Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Mon, 5 Oct 2026 10:48:43 -0400 Subject: [PATCH 07/10] update test --- test/e2e/silos.e2e.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/silos.e2e.ts b/test/e2e/silos.e2e.ts index 12f5b51fa9..b391f73385 100644 --- a/test/e2e/silos.e2e.ts +++ b/test/e2e/silos.e2e.ts @@ -221,11 +221,11 @@ test('Create silo', async ({ page }) => { ]) await expect(page.getByText('Silo viewerFleet viewer')).toBeHidden() - // now go check the quotas in its entry in the utilization table + // now go check the quotas in its Quotas tab await page.getByRole('tab', { name: 'Quotas' }).click() - await expectRowVisible(table, { Resource: 'CPU', Quota: '30 vCPUs' }) - await expectRowVisible(table, { Resource: 'Memory', Quota: '58 GiB' }) - await expectRowVisible(table, { Resource: 'Storage', Quota: '735 GiB' }) + await expect(page.getByRole('region', { name: 'CPU' })).toContainText('30 vCPUs') + await expect(page.getByRole('region', { name: 'Memory' })).toContainText('58 GiB') + await expect(page.getByRole('region', { name: 'Storage' })).toContainText('735 GiB') // Go back to the silos list page to delete the silo using breadcrumbs await page From fc4e1253d7fb1244fa0c6ca6e0fdd2b891fb2b15 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Fri, 20 Nov 2026 11:57:42 -0600 Subject: [PATCH 08/10] Show units on quota tile amounts --- app/components/QuotaTile.tsx | 6 +++--- test/e2e/silos.e2e.ts | 8 ++++---- test/e2e/utilization.e2e.ts | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/components/QuotaTile.tsx b/app/components/QuotaTile.tsx index 9992aee040..3dc9e333b4 100644 --- a/app/components/QuotaTile.tsx +++ b/app/components/QuotaTile.tsx @@ -132,21 +132,21 @@ function QuotaTile({ icon, title, unit, provisioned, quota, showBar }: QuotaTile
Provisioned
- + {unit}
{available < 0 ? (
Over quota
- + {unit}
) : (
Available
- + {unit}
)} diff --git a/test/e2e/silos.e2e.ts b/test/e2e/silos.e2e.ts index b391f73385..930f854fa2 100644 --- a/test/e2e/silos.e2e.ts +++ b/test/e2e/silos.e2e.ts @@ -545,11 +545,11 @@ test('Quotas tab', async ({ page }) => { const memory = page.getByRole('region', { name: 'Memory' }) const storage = page.getByRole('region', { name: 'Storage' }) await expect(cpu).toContainText('50 vCPUs') - await expect(cpu).toContainText('Provisioned30Available20') + await expect(cpu).toContainText('Provisioned30 vCPUsAvailable20 vCPUs') await expect(memory).toContainText('300 GiB') - await expect(memory).toContainText('Provisioned234Available66') + await expect(memory).toContainText('Provisioned234 GiBAvailable66 GiB') await expect(storage).toContainText('7,168 GiB') - await expect(storage).toContainText('Provisioned4,403.2Available2,764.8') + await expect(storage).toContainText('Provisioned4,403.2 GiBAvailable2,764.8 GiB') const sideModal = page.getByRole('dialog', { name: 'Edit quotas' }) const edit = page.getByRole('button', { name: 'Edit quotas' }) @@ -577,6 +577,6 @@ test('Quotas tab', async ({ page }) => { // only one changes, the others stay the same await expect(cpu).toContainText('50 vCPUs') // quota now below provisioned - await expect(memory).toContainText('Over quota184') + await expect(memory).toContainText('Over quota184 GiB') await expect(storage).toContainText('7,168 GiB') }) diff --git a/test/e2e/utilization.e2e.ts b/test/e2e/utilization.e2e.ts index 33a84567a5..5ec125bdde 100644 --- a/test/e2e/utilization.e2e.ts +++ b/test/e2e/utilization.e2e.ts @@ -25,7 +25,7 @@ test.describe('System utilization', () => { await expect(page.getByRole('heading', { name: 'Utilization' })).toBeVisible() await expect(page.getByRole('region', { name: 'Memory' })).toContainText( - 'Provisioned416' + 'Provisioned416 GiB' ) await expect(page.getByText('Provisioned / Quota')).toBeVisible() @@ -149,7 +149,7 @@ test.describe('Silo utilization', () => { await expect(page.getByRole('heading', { name: 'Utilization' })).toBeVisible() // Capacity bars are showing up await expect(page.getByRole('region', { name: 'Memory' })).toContainText( - 'Provisioned234Available66' + 'Provisioned234 GiBAvailable66 GiB' ) }) @@ -159,7 +159,7 @@ test.describe('Silo utilization', () => { await expect(page.getByRole('heading', { name: 'Utilization' })).toBeVisible() // Capacity bars are showing up await expect(page.getByRole('region', { name: 'Memory' })).toContainText( - 'Provisioned234Available66' + 'Provisioned234 GiBAvailable66 GiB' ) }) }) From 39354a4232c84f482e135c0cd22e4f0dd8d3fb0f Mon Sep 17 00:00:00 2001 From: David Crespo Date: Fri, 20 Nov 2026 11:59:30 -0600 Subject: [PATCH 09/10] Calculate quota usage before rounding --- app/components/QuotaTile.browser.spec.tsx | 45 +++++++++++++++++++ app/components/QuotaTile.tsx | 54 ++++++++++++++++------- 2 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 app/components/QuotaTile.browser.spec.tsx diff --git a/app/components/QuotaTile.browser.spec.tsx b/app/components/QuotaTile.browser.spec.tsx new file mode 100644 index 0000000000..a51d277e8d --- /dev/null +++ b/app/components/QuotaTile.browser.spec.tsx @@ -0,0 +1,45 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * Copyright Oxide Computer Company + */ + +import { expect, test } from 'vitest' +import { render } from 'vitest-browser-react' + +import { GiB, TiB } from '~/util/units' + +import { QuotaTiles } from './QuotaTile' + +test('shows a storage overage smaller than the displayed TiB precision', async () => { + const screen = await render( + + ) + const storage = screen.getByRole('region', { name: 'Storage' }) + await expect.element(storage.getByText('Over quota')).toBeVisible() + await expect.element(storage.getByText('1 GiB', { exact: true })).toBeVisible() + await expect.element(storage.getByText('100.1%', { exact: true })).toBeVisible() +}) + +test('shows amounts under 1 TiB in a smaller unit', async () => { + const screen = await render( + + ) + const storage = screen.getByRole('region', { name: 'Storage' }) + await expect.element(storage.getByText('1,018.5 GiB', { exact: true })).toBeVisible() + await expect.element(storage.getByText('Available')).toBeVisible() + // 5.5 GiB would round to 0.01 TiB, which is nearly double + await expect.element(storage.getByText('5.5 GiB', { exact: true })).toBeVisible() +}) diff --git a/app/components/QuotaTile.tsx b/app/components/QuotaTile.tsx index 3dc9e333b4..2ed686be45 100644 --- a/app/components/QuotaTile.tsx +++ b/app/components/QuotaTile.tsx @@ -13,23 +13,21 @@ import { Cpu16Icon, Ram16Icon, Ssd16Icon } from '@oxide/design-system/icons/reac import { BigNum } from '~/ui/lib/BigNum' import { percentage, round, splitDecimal } from '~/util/math' -import { bytesToGiB, bytesToTiB } from '~/util/units' +import { formatBytes, GiB, TiB } from '~/util/units' type Resource = { icon: ReactNode title: string - unit: string + unit: 'vCPUs' | 'GiB' | 'TiB' provisioned: number quota: number } -/** Convert API byte counts into the display units for each tile */ function getResources( provisioned: VirtualResourceCounts, allocated: VirtualResourceCounts, storageUnit: 'GiB' | 'TiB' ): Resource[] { - const toStorageUnit = storageUnit === 'GiB' ? bytesToGiB : bytesToTiB return [ { icon: , @@ -42,15 +40,15 @@ function getResources( icon: , title: 'Memory', unit: 'GiB', - provisioned: bytesToGiB(provisioned.memory), - quota: bytesToGiB(allocated.memory), + provisioned: provisioned.memory, + quota: allocated.memory, }, { icon: , title: 'Storage', unit: storageUnit, - provisioned: toStorageUnit(provisioned.storage), - quota: toStorageUnit(allocated.storage), + provisioned: provisioned.storage, + quota: allocated.storage, }, ] } @@ -93,13 +91,36 @@ function Bar({ pct }: { pct: number }) { ) } +const unitSize = { vCPUs: 1, GiB, TiB } + +function QuotaAmount({ + value, + unit, + unitClassName, +}: { + value: number + unit: Resource['unit'] + unitClassName?: string +}) { + const size = unitSize[unit] + // two decimals lose too much below 1 of the tile's unit, so use a smaller one + const small = + unit !== 'vCPUs' && value > 0 && value < size ? formatBytes(value) : undefined + return ( + <> + {' '} + {small?.unit ?? unit} + + ) +} + type QuotaTileProps = Resource & { /** Show a bar and percentage of the quota that is provisioned */ showBar?: boolean } function QuotaTile({ icon, title, unit, provisioned, quota, showBar }: QuotaTileProps) { - const available = round(quota - provisioned, 2) + const available = quota - provisioned const pct = percentage(provisioned, quota) return (
{icon}
{title}
- - {' '} - {unit} + +
@@ -132,21 +156,21 @@ function QuotaTile({ icon, title, unit, provisioned, quota, showBar }: QuotaTile
Provisioned
- {unit} +
{available < 0 ? (
Over quota
- {unit} +
) : (
Available
- {unit} +
)} From acf9361c0aa80d21a85418105673a5526d36e0ed Mon Sep 17 00:00:00 2001 From: David Crespo Date: Fri, 20 Nov 2026 13:58:04 -0600 Subject: [PATCH 10/10] Drop unit from CPU tile amounts --- app/components/QuotaTile.tsx | 23 +++++++++++++---------- test/e2e/silos.e2e.ts | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/components/QuotaTile.tsx b/app/components/QuotaTile.tsx index 2ed686be45..c21de76305 100644 --- a/app/components/QuotaTile.tsx +++ b/app/components/QuotaTile.tsx @@ -99,17 +99,18 @@ function QuotaAmount({ unitClassName, }: { value: number - unit: Resource['unit'] + /** Leave out for a plain count shown without a unit */ + unit?: Resource['unit'] unitClassName?: string }) { - const size = unitSize[unit] - // two decimals lose too much below 1 of the tile's unit, so use a smaller one - const small = - unit !== 'vCPUs' && value > 0 && value < size ? formatBytes(value) : undefined + const size = unit ? unitSize[unit] : 1 + // Only byte units have a size over 1. Two decimals lose too much below 1 of + // the tile's unit, so use a smaller one. + const small = size > 1 && value > 0 && value < size ? formatBytes(value) : undefined return ( <> - {' '} - {small?.unit ?? unit} + + {unit && {small?.unit ?? unit}} ) } @@ -122,6 +123,8 @@ type QuotaTileProps = Resource & { function QuotaTile({ icon, title, unit, provisioned, quota, showBar }: QuotaTileProps) { const available = quota - provisioned const pct = percentage(provisioned, quota) + // byte amounts can be in a smaller unit than the quota, but a count can't + const amountUnit = unit === 'vCPUs' ? undefined : unit return (
Provisioned
- +
{available < 0 ? (
Over quota
- +
) : (
Available
- +
)} diff --git a/test/e2e/silos.e2e.ts b/test/e2e/silos.e2e.ts index 930f854fa2..9e05c48723 100644 --- a/test/e2e/silos.e2e.ts +++ b/test/e2e/silos.e2e.ts @@ -545,7 +545,7 @@ test('Quotas tab', async ({ page }) => { const memory = page.getByRole('region', { name: 'Memory' }) const storage = page.getByRole('region', { name: 'Storage' }) await expect(cpu).toContainText('50 vCPUs') - await expect(cpu).toContainText('Provisioned30 vCPUsAvailable20 vCPUs') + await expect(cpu).toContainText('Provisioned30Available20') await expect(memory).toContainText('300 GiB') await expect(memory).toContainText('Provisioned234 GiBAvailable66 GiB') await expect(storage).toContainText('7,168 GiB')