From 6fd4c8c2d8478a8ce7810ddff822364e1426c8e6 Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:12:49 -0400 Subject: [PATCH] update memory units update tests apply concatenation to units in workbenches table view update parsing logic fix TS errors revert to text component to initial content formatting --- .../tests/mocked/projects/clusterStorage.cy.ts | 2 +- .../cypress/tests/mocked/projects/workbench.cy.ts | 2 +- .../pages/projects/components/StorageSizeBars.tsx | 2 +- .../detail/notebooks/NotebookSizeDetails.tsx | 14 ++++++++++++-- frontend/src/pages/projects/utils.ts | 6 ++++-- frontend/src/utilities/valueUnits.ts | 4 ++-- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/frontend/src/__tests__/cypress/cypress/tests/mocked/projects/clusterStorage.cy.ts b/frontend/src/__tests__/cypress/cypress/tests/mocked/projects/clusterStorage.cy.ts index 605c917649..e1787e9575 100644 --- a/frontend/src/__tests__/cypress/cypress/tests/mocked/projects/clusterStorage.cy.ts +++ b/frontend/src/__tests__/cypress/cypress/tests/mocked/projects/clusterStorage.cy.ts @@ -386,7 +386,7 @@ describe('ClusterStorage', () => { clusterStorageRow.findKebabAction('Edit storage').click(); updateClusterStorageModal.findNameInput().should('have.value', 'Test Storage'); updateClusterStorageModal.findPVSizeInput().should('have.value', '5'); - updateClusterStorageModal.shouldHavePVSizeSelectValue('Gi'); + updateClusterStorageModal.shouldHavePVSizeSelectValue('GiB'); updateClusterStorageModal.findPersistentStorageWarning().should('exist'); updateClusterStorageModal.findSubmitButton().should('be.enabled'); updateClusterStorageModal.findNameInput().fill('test-updated'); diff --git a/frontend/src/__tests__/cypress/cypress/tests/mocked/projects/workbench.cy.ts b/frontend/src/__tests__/cypress/cypress/tests/mocked/projects/workbench.cy.ts index fef7f93dff..6ce5b34aa0 100644 --- a/frontend/src/__tests__/cypress/cypress/tests/mocked/projects/workbench.cy.ts +++ b/frontend/src/__tests__/cypress/cypress/tests/mocked/projects/workbench.cy.ts @@ -284,7 +284,7 @@ describe('Workbench page', () => { createSpawnerPage.findPVSizeInput().should('have.value', '19'); createSpawnerPage.findPVSizePlusButton().click(); createSpawnerPage.findPVSizeInput().should('have.value', '20'); - createSpawnerPage.selectPVSize('Mi'); + createSpawnerPage.selectPVSize('MiB'); //add existing cluster storage createSpawnerPage.findExistingStorageRadio().click(); diff --git a/frontend/src/pages/projects/components/StorageSizeBars.tsx b/frontend/src/pages/projects/components/StorageSizeBars.tsx index 3402111567..4a4e6dd199 100644 --- a/frontend/src/pages/projects/components/StorageSizeBars.tsx +++ b/frontend/src/pages/projects/components/StorageSizeBars.tsx @@ -33,7 +33,7 @@ const StorageSizeBar: React.FC = ({ pvc }) => { ); } - const inUseValue = `${bytesAsRoundedGiB(inUseInBytes)}Gi`; + const inUseValue = `${bytesAsRoundedGiB(inUseInBytes)}GiB`; const percentage = ((parseFloat(inUseValue) / parseFloat(maxValue)) * 100).toFixed(2); const percentageLabel = error ? '' : `Storage is ${percentage}% full`; diff --git a/frontend/src/pages/projects/screens/detail/notebooks/NotebookSizeDetails.tsx b/frontend/src/pages/projects/screens/detail/notebooks/NotebookSizeDetails.tsx index 8321cf87bc..64428ae104 100644 --- a/frontend/src/pages/projects/screens/detail/notebooks/NotebookSizeDetails.tsx +++ b/frontend/src/pages/projects/screens/detail/notebooks/NotebookSizeDetails.tsx @@ -16,18 +16,28 @@ const NotebookSizeDetails: React.FC = ({ notebookSize resources: { requests, limits }, } = notebookSize; + const formatMemory = (memory: string | undefined): string => { + if (!memory) { + return 'Unknown'; + } + if (/(Gi|Mi)$/.test(memory)) { + return `${memory}B`; + } + return memory; + }; + return ( Limits - {limits?.cpu ?? 'Unknown'} CPU, {limits?.memory ?? 'Unknown'} Memory + {limits?.cpu ?? 'Unknown'} CPU, {formatMemory(limits?.memory)} Memory Requests - {requests?.cpu ?? 'Unknown'} CPU, {requests?.memory ?? 'Unknown'} Memory + {requests?.cpu ?? 'Unknown'} CPU, {formatMemory(requests?.memory)} Memory diff --git a/frontend/src/pages/projects/utils.ts b/frontend/src/pages/projects/utils.ts index a045afdd67..d674cab1dd 100644 --- a/frontend/src/pages/projects/utils.ts +++ b/frontend/src/pages/projects/utils.ts @@ -5,8 +5,10 @@ import { NotebookState } from './notebook/types'; export const getNotebookStatusPriority = (notebookState: NotebookState): number => notebookState.isRunning ? 1 : notebookState.isStarting ? 2 : 3; -export const getPvcTotalSize = (pvc: PersistentVolumeClaimKind): string => - pvc.status?.capacity?.storage || pvc.spec.resources.requests.storage; +export const getPvcTotalSize = (pvc: PersistentVolumeClaimKind): string => { + const storage = pvc.status?.capacity?.storage || pvc.spec.resources.requests.storage; + return /(Gi|Mi)$/.test(storage) ? `${storage}B` : storage; +}; export const getCustomNotebookSize = ( existingNotebook: NotebookKind | undefined, diff --git a/frontend/src/utilities/valueUnits.ts b/frontend/src/utilities/valueUnits.ts index 32c88ebbf1..c9620fed2b 100644 --- a/frontend/src/utilities/valueUnits.ts +++ b/frontend/src/utilities/valueUnits.ts @@ -22,8 +22,8 @@ export const CPU_UNITS: UnitOption[] = [ { name: 'Milicores', unit: 'm', weight: 1 }, ]; export const MEMORY_UNITS_FOR_SELECTION: UnitOption[] = [ - { name: 'Gi', unit: 'Gi', weight: 1024 }, - { name: 'Mi', unit: 'Mi', weight: 1 }, + { name: 'GiB', unit: 'Gi', weight: 1024 }, + { name: 'MiB', unit: 'Mi', weight: 1 }, ]; export const MEMORY_UNITS_FOR_PARSING: UnitOption[] = [ { name: 'EB', unit: 'E', weight: 1000 ** 6 },