File tree Expand file tree Collapse file tree 4 files changed +138
-6
lines changed
packages/databases-collections-list/src Expand file tree Collapse file tree 4 files changed +138
-6
lines changed Original file line number Diff line number Diff line change @@ -554,4 +554,37 @@ describe('Collections', () => {
554554 'Derived from foo'
555555 ) ;
556556 } ) ;
557+
558+ it ( 'renders a tooltip for storage size cell with storage breakdown and data size' , async function ( ) {
559+ renderCollectionsList ( {
560+ collections : colls ,
561+ } ) ;
562+
563+ const fooRow = screen . getByTestId ( 'collections-list-row-foo' ) ;
564+ expect ( fooRow ) . to . exist ;
565+
566+ const storageCell = fooRow . querySelector ( 'td:nth-child(3)' ) ;
567+ expect ( storageCell ) . to . exist ;
568+
569+ // Hover over the span inside the cell (the tooltip trigger)
570+ const span = storageCell ?. querySelector ( 'span' ) ;
571+ expect ( span ) . to . exist ;
572+ userEvent . hover ( span as Element ) ;
573+
574+ await waitFor (
575+ function ( ) {
576+ expect ( screen . getByRole ( 'tooltip' ) ) . to . exist ;
577+ } ,
578+ {
579+ timeout : 5000 ,
580+ }
581+ ) ;
582+
583+ const tooltipText = screen . getByRole ( 'tooltip' ) . textContent ;
584+ expect ( tooltipText ) . to . include ( 'Storage Size:' ) ;
585+ expect ( tooltipText ) . to . include ( '1.00 kB' ) ;
586+ expect ( tooltipText ) . to . include ( 'Used:' ) ;
587+ expect ( tooltipText ) . to . include ( 'Free:' ) ;
588+ expect ( tooltipText ) . to . include ( 'Data Size:' ) ;
589+ } ) ;
557590} ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313 Placeholder ,
1414 compactBytes ,
1515 compactNumber ,
16+ InlineDefinition ,
1617} from '@mongodb-js/compass-components' ;
1718import { ItemsTable , VirtualItemsTable } from './items-table' ;
1819import type { CollectionProps } from 'mongodb-collection-model' ;
@@ -291,9 +292,46 @@ function collectionColumns({
291292 if ( type === 'view' ) {
292293 return '-' ;
293294 }
294- return enableDbAndCollStats && collection . storage_size !== undefined
295- ? compactBytes ( collection . storage_size )
296- : '-' ;
295+
296+ if ( ! enableDbAndCollStats || collection . storage_size === undefined ) {
297+ return '-' ;
298+ }
299+
300+ const storageSize = collection . storage_size ;
301+ const freeStorageSize = collection . free_storage_size ?? 0 ;
302+ const usedStorageSize = storageSize - freeStorageSize ;
303+ const documentSize = collection . document_size ;
304+ const displayValue = compactBytes ( storageSize ) ;
305+
306+ const definition = (
307+ < div >
308+ < div >
309+ < strong > Storage Size:</ strong > { compactBytes ( storageSize ) } (total
310+ allocated)
311+ </ div >
312+ < div >
313+ < strong > Used:</ strong > { compactBytes ( usedStorageSize ) }
314+ </ div >
315+ < div >
316+ < strong > Free:</ strong > { compactBytes ( freeStorageSize ) }
317+ </ div >
318+ { documentSize !== undefined && (
319+ < div >
320+ < strong > Data Size:</ strong > { compactBytes ( documentSize ) } { ' ' }
321+ (uncompressed)
322+ </ div >
323+ ) }
324+ </ div >
325+ ) ;
326+
327+ return (
328+ < InlineDefinition
329+ definition = { definition }
330+ tooltipProps = { { align : 'top' , justify : 'start' } }
331+ >
332+ { displayValue }
333+ </ InlineDefinition >
334+ ) ;
297335 } ,
298336 } ,
299337 /*
Original file line number Diff line number Diff line change @@ -272,4 +272,36 @@ describe('Databases', function () {
272272 'Your privileges grant you access to this namespace, but it might not currently exist'
273273 ) ;
274274 } ) ;
275+
276+ it ( 'renders a tooltip for storage size cell with storage and data size' , async function ( ) {
277+ renderDatabasesList ( {
278+ databases : dbs ,
279+ } ) ;
280+
281+ const fooRow = screen . getByTestId ( 'databases-list-row-foo' ) ;
282+ expect ( fooRow ) . to . exist ;
283+
284+ const storageCell = fooRow . querySelector ( 'td:nth-child(2)' ) ;
285+ expect ( storageCell ) . to . exist ;
286+
287+ // Hover over the span inside the cell (the tooltip trigger)
288+ const span = storageCell ?. querySelector ( 'span' ) ;
289+ expect ( span ) . to . exist ;
290+ userEvent . hover ( span as Element ) ;
291+
292+ await waitFor (
293+ function ( ) {
294+ expect ( screen . getByRole ( 'tooltip' ) ) . to . exist ;
295+ } ,
296+ {
297+ timeout : 5000 ,
298+ }
299+ ) ;
300+
301+ const tooltipText = screen . getByRole ( 'tooltip' ) . textContent ;
302+ expect ( tooltipText ) . to . include ( 'Storage Size:' ) ;
303+ expect ( tooltipText ) . to . include ( '5.00 kB' ) ;
304+ expect ( tooltipText ) . to . include ( 'Data Size:' ) ;
305+ expect ( tooltipText ) . to . include ( '1.00 kB' ) ;
306+ } ) ;
275307} ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import {
1717 useDarkMode ,
1818 compactBytes ,
1919 compactNumber ,
20+ InlineDefinition ,
2021} from '@mongodb-js/compass-components' ;
2122
2223const databaseNameWrapStyles = css ( {
@@ -129,9 +130,37 @@ function databaseColumns({
129130 return < Placeholder maxChar = { 10 } > </ Placeholder > ;
130131 }
131132
132- return enableDbAndCollStats && database . storage_size !== undefined
133- ? compactBytes ( database . storage_size )
134- : '-' ;
133+ if ( ! enableDbAndCollStats || database . storage_size === undefined ) {
134+ return '-' ;
135+ }
136+
137+ const storageSize = database . storage_size ;
138+ const dataSize = database . data_size ;
139+ const displayValue = compactBytes ( storageSize ) ;
140+
141+ const definition = (
142+ < div >
143+ < div >
144+ < strong > Storage Size:</ strong > { compactBytes ( storageSize ) } (total
145+ allocated)
146+ </ div >
147+ { dataSize !== undefined && (
148+ < div >
149+ < strong > Data Size:</ strong > { compactBytes ( dataSize ) } { ' ' }
150+ (uncompressed)
151+ </ div >
152+ ) }
153+ </ div >
154+ ) ;
155+
156+ return (
157+ < InlineDefinition
158+ definition = { definition }
159+ tooltipProps = { { align : 'top' , justify : 'start' } }
160+ >
161+ { displayValue }
162+ </ InlineDefinition >
163+ ) ;
135164 } ,
136165 } ,
137166 /*
You can’t perform that action at this time.
0 commit comments