Skip to content

Commit 0a323a6

Browse files
fix: [M3-9805] - Revert Object Storage Size Conversions from Base10 to Base2 (#12075)
* fix: [M3-9805] - Revert Object Storage Size Conversions from Base10 to Base2 * More tests * Added changeset: Revert Object Storage Size Conversions from Base10 to Base2 --------- Co-authored-by: Jaalah Ramos <[email protected]>
1 parent eceb873 commit 0a323a6

File tree

12 files changed

+69
-34
lines changed

12 files changed

+69
-34
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Fixed
3+
---
4+
5+
Revert Object Storage Size Conversions from Base10 to Base2 ([#12075](https://github.com/linode/manager/pull/12075))

packages/manager/src/components/Uploaders/FileUpload.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ export const FileUpload = React.memo((props: FileUploadProps) => {
9292
})}
9393
variant="body1"
9494
>
95-
{/* to convert from binary units (GiB) to decimal units (GB) we need to pass the base10 flag */}
96-
{readableBytes(props.sizeInBytes, { base10: true }).formatted}
95+
{readableBytes(props.sizeInBytes).formatted}
9796
</StyledFileSizeTypography>
9897
{props.percentCompleted === 100 ? (
9998
<FileUploadComplete

packages/manager/src/features/ObjectStorage/BucketDetail/ObjectDetailsDrawer.test.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ describe('ObjectDetailsDrawer', () => {
4949
screen.findByText(/^Last modified: 2019-12-31/)
5050
).resolves.toBeInTheDocument();
5151

52-
expect(screen.getByText('12.3 KB')).toBeVisible();
5352
expect(screen.getByText(/^https:\/\/my-bucket/)).toBeVisible();
5453
});
5554

@@ -62,4 +61,28 @@ describe('ObjectDetailsDrawer', () => {
6261
expect(() => screen.getByTestId('lastModified')).toThrow();
6362
});
6463
});
64+
65+
describe('readableBytes edge cases in Object Storage', () => {
66+
it('displays bytes correctly for sizes under 1 KB threshold', () => {
67+
renderWithTheme(<ObjectDetailsDrawer {...props} size={1000} />);
68+
69+
// Values under 1024 bytes should remain as bytes
70+
expect(screen.getByText('1000 bytes')).toBeVisible();
71+
});
72+
73+
it('uses base2 calculations (1024-based) for KB display', () => {
74+
renderWithTheme(<ObjectDetailsDrawer {...props} size={1024} />);
75+
76+
// 1024 bytes = 1 KB in base2 (not 1.02 KB as it would be in base10)
77+
expect(screen.getByText('1 KB')).toBeVisible();
78+
});
79+
80+
it('converts base10 MB values correctly to base2 display', () => {
81+
renderWithTheme(<ObjectDetailsDrawer {...props} size={1000000} />);
82+
83+
// 1,000,000 bytes / 1024 = 976.56 KB (rounded to 977 KB)
84+
// Since this is less than 1 MB in base2, it displays as KB
85+
expect(screen.getByText('977 KB')).toBeVisible();
86+
});
87+
});
6588
});

packages/manager/src/features/ObjectStorage/BucketDetail/ObjectDetailsDrawer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ export const ObjectDetailsDrawer = React.memo(
7474
>
7575
{size ? (
7676
<Typography variant="subtitle2">
77-
{/* to convert from binary units (GiB) to decimal units (GB) we need to pass the base10 flag */}
78-
{readableBytes(size, { base10: true }).formatted}
77+
{readableBytes(size).formatted}
7978
</Typography>
8079
) : null}
8180
{formattedLastModified && Boolean(profile) ? (

packages/manager/src/features/ObjectStorage/BucketDetail/ObjectTableRow.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export const ObjectTableRow = (props: Props) => {
3737
<Grid
3838
container
3939
spacing={2}
40-
wrap="nowrap"
4140
sx={{
4241
alignItems: 'center',
4342
}}
43+
wrap="nowrap"
4444
>
4545
<Grid className="py0">
4646
<ObjectIcon size={20} />
@@ -56,10 +56,7 @@ export const ObjectTableRow = (props: Props) => {
5656
</Grid>
5757
</Grid>
5858
</TableCell>
59-
<TableCell noWrap>
60-
{/* to convert from binary units (GiB) to decimal units (GB) we need to pass the base10 flag */}
61-
{readableBytes(objectSize, { base10: true }).formatted}
62-
</TableCell>
59+
<TableCell noWrap>{readableBytes(objectSize).formatted}</TableCell>
6360
<Hidden mdDown>
6461
<TableCell noWrap>
6562
<DateTimeDisplay value={objectLastModified} />

packages/manager/src/features/ObjectStorage/BucketLanding/BucketDetailsDrawer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ export const BucketDetailsDrawer = React.memo(
117117
)}
118118
{typeof size === 'number' && (
119119
<Typography variant="subtitle2">
120-
{/* to convert from binary units (GiB) to decimal units (GB) we need to pass the base10 flag */}
121-
{readableBytes(size, { base10: true }).formatted}
120+
{readableBytes(size).formatted}
122121
</Typography>
123122
)}
124123
{/* @TODO OBJ Multicluster: use region instead of cluster if isObjMultiClusterEnabled. */}

packages/manager/src/features/ObjectStorage/BucketLanding/BucketLanding.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ describe('ObjectStorageLanding', () => {
179179
await screen.findByText(buckets[1].label);
180180
});
181181

182-
it('renders a "Total usage" section if there is more than one Bucket', async () => {
182+
it('renders a "Total usage" section using base2 calculations if there is more than one Bucket', async () => {
183183
const buckets = objectStorageBucketFactory.buildList(2, {
184-
size: 1e9 * 5,
184+
size: 1024 * 1024 * 1024 * 5, // 5 GB in base2 (5 GiB)
185185
});
186186

187187
// Mock Clusters

packages/manager/src/features/ObjectStorage/BucketLanding/BucketLanding.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ export const BucketLanding = (props: Props) => {
193193
style={{ marginTop: 18, textAlign: 'center', width: '100%' }}
194194
variant="body1"
195195
>
196-
Total storage used:{' '}
197-
{/* to convert from binary units (GiB) to decimal units (GB) we need to pass the base10 flag */}
198-
{readableBytes(totalUsage, { base10: true }).formatted}
196+
Total storage used: {readableBytes(totalUsage).formatted}
199197
</Typography>
200198
) : null}
201199
<TransferDisplay

packages/manager/src/features/ObjectStorage/BucketLanding/BucketTableRow.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ describe('BucketTableRow', () => {
3737
getByText('test-bucket-001.alpha.linodeobjects.com');
3838
});
3939

40-
it('should render a size with the correct size abbreviation', () => {
40+
it('should render size with base2 calculations (displaying GB but representing GiB)', () => {
4141
const { getByText } = renderWithTheme(
4242
wrapWithTableBody(<BucketTableRow {...props} />)
4343
);
44-
getByText('5.42 GB');
44+
getByText('5.05 GB');
4545
});
4646
});

packages/manager/src/features/ObjectStorage/BucketLanding/BucketTableRow.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const BucketTableRow = (props: BucketTableRowProps) => {
8989
<Typography data-qa-region variant="body1">
9090
{isObjMultiClusterEnabled && regionsLookup && region
9191
? regionsLookup[region].label
92-
: clusterRegion?.label ?? cluster}
92+
: (clusterRegion?.label ?? cluster)}
9393
</Typography>
9494
</StyledBucketRegionCell>
9595
</Hidden>
@@ -109,8 +109,7 @@ export const BucketTableRow = (props: BucketTableRowProps) => {
109109
</Hidden>
110110
<StyledBucketSizeCell noWrap>
111111
<Typography data-qa-size variant="body1">
112-
{/* to convert from binary units (GiB) to decimal units (GB) we need to pass the base10 flag */}
113-
{readableBytes(size, { base10: true }).formatted}
112+
{readableBytes(size).formatted}
114113
</Typography>
115114
</StyledBucketSizeCell>
116115

0 commit comments

Comments
 (0)