Add guard against dividing by zero when calculating used percentage
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -22,8 +22,14 @@ interface StorageListItemProps {
|
||||
const calculateUsed = (folder?: FolderStorageDto) => {
|
||||
if (typeof folder?.UsedSpace === 'undefined') return 0;
|
||||
if (typeof folder.FreeSpace === 'undefined') return 100;
|
||||
|
||||
return folder.UsedSpace / (folder.FreeSpace + folder.UsedSpace) * 100;
|
||||
|
||||
const totalSpace = folder.FreeSpace + folder.UsedSpace;
|
||||
if (totalSpace === 0) return 0;
|
||||
|
||||
// Ensure we don't have negative values
|
||||
const usedSpace = Math.max(0, folder.UsedSpace);
|
||||
|
||||
return Math.min(100, (usedSpace / totalSpace) * 100);
|
||||
};
|
||||
|
||||
const getStatusColor = (percent: number) => {
|
||||
|
||||
Reference in New Issue
Block a user