Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,20 @@ describe('QuotaUsageBanner', () => {
const quotaUsageText = getByText('1 of 10 Bytes used');
expect(quotaUsageText).toBeVisible();
});

it.each([1000000000, 100000000, 10000000, 1000000])(
'should display content usage in proper format',
(usage) => {
const { getByText } = renderWithTheme(
<QuotaUsageBar
limit={109951162777600}
resourceMetric="byte"
usage={usage}
/>
);

const quotaUsageText = getByText('<0.01 of 100 TB used');
expect(quotaUsageText).toBeVisible();
}
);
});
18 changes: 13 additions & 5 deletions packages/manager/src/components/QuotaUsageBar/QuotaUsageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ export const QuotaUsageBar = ({ limit, usage, resourceMetric }: Props) => {
initialLimit: limit,
});

function getUsageText() {
let convertedUsageString = convertedUsage.toLocaleString();
const convertedLimitString = convertedLimit.toLocaleString();

// Special case to display storage usage
if (convertedUsage === 0 && convertedResourceMetric === 'TB') {
convertedUsageString = '<0.01';
}

return `${convertedUsageString} of ${convertedLimitString} ${convertedResourceMetric} used`;
}

return (
<>
<BarPercent
Expand All @@ -45,11 +57,7 @@ export const QuotaUsageBar = ({ limit, usage, resourceMetric }: Props) => {
sx={{ mb: 1, mt: 2, padding: '3px' }}
value={usage}
/>
<Typography sx={{ mb: 1, mt: -0.5 }}>
{`${convertedUsage?.toLocaleString() ?? 'unknown'} of ${
convertedLimit?.toLocaleString() ?? 'unknown'
} ${convertedResourceMetric} used`}
</Typography>
<Typography sx={{ mb: 1, mt: -0.5 }}>{getUsageText()}</Typography>
</>
);
};