-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
UI(storage): display per-folder storage usage in Paths widget #7326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,11 +28,9 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const getStorageTypeText = (type?: string | null) => { | ||||||||||||||||||||||||||
| if (!type) return undefined; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (Object.keys(StorageType).includes(type)) { | ||||||||||||||||||||||||||
| return globalize.translate(`StorageType.${type}`); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return type; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -43,10 +41,16 @@ | |||||||||||||||||||||||||
| const readableUsedSpace = (typeof folder?.UsedSpace === 'undefined' || folder.UsedSpace < 0) ? | ||||||||||||||||||||||||||
| '?' : getReadableSize(folder.UsedSpace); | ||||||||||||||||||||||||||
| const totalSpace = calculateTotal(folder); | ||||||||||||||||||||||||||
| const readableTotalSpace = (totalSpace < 0) ? '?' : getReadableSize(totalSpace); | ||||||||||||||||||||||||||
|
Check failure on line 44 in src/apps/dashboard/features/storage/components/StorageListItem.tsx
|
||||||||||||||||||||||||||
| const usedPercentage = calculateUsedPercentage(folder); | ||||||||||||||||||||||||||
| const statusColor = folder ? getStatusColor(usedPercentage) : 'primary'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size; | ||||||||||||||||||||||||||
|
Check failure on line 48 in src/apps/dashboard/features/storage/components/StorageListItem.tsx
|
||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
|
||||||||||||||||||||||||||
| const hasFolderSize = typeof folderSize === 'number' && folderSize >= 0; | ||||||||||||||||||||||||||
| const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity; | ||||||||||||||||||||||||||
|
Check failure on line 50 in src/apps/dashboard/features/storage/components/StorageListItem.tsx
|
||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
|
||||||||||||||||||||||||||
| const readableFolderSize = hasFolderSize ? getReadableSize(folderSize) : undefined; | ||||||||||||||||||||||||||
| const readableDriveTotal = typeof driveTotal === 'number' && driveTotal >= 0 ? getReadableSize(driveTotal) : undefined; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||
| <ListItem> | ||||||||||||||||||||||||||
| <ListItemIcon title={getStorageTypeText(folder?.StorageType)}> | ||||||||||||||||||||||||||
|
|
@@ -70,24 +74,33 @@ | |||||||||||||||||||||||||
| lineBreak: 'anywhere' | ||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||
| {folder ? folder.Path : ( | ||||||||||||||||||||||||||
| <Skeleton /> | ||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||
| </Typography> | ||||||||||||||||||||||||||
| <LinearProgress | ||||||||||||||||||||||||||
| variant={folder ? 'determinate' : 'indeterminate'} | ||||||||||||||||||||||||||
| color={statusColor} | ||||||||||||||||||||||||||
| value={usedPercentage} | ||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||
| <Typography | ||||||||||||||||||||||||||
| variant='body2' | ||||||||||||||||||||||||||
| color='textSecondary' | ||||||||||||||||||||||||||
| sx={{ | ||||||||||||||||||||||||||
| textAlign: 'end' | ||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||
| {`${readableUsedSpace} / ${readableTotalSpace}`} | ||||||||||||||||||||||||||
| {folder ? folder.Path : <Skeleton />} | ||||||||||||||||||||||||||
| </Typography> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| {hasFolderSize ? ( | ||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||
| <LinearProgress | ||||||||||||||||||||||||||
| variant='determinate' | ||||||||||||||||||||||||||
| color={statusColor} | ||||||||||||||||||||||||||
| value={usedPercentage} | ||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||
| <Typography | ||||||||||||||||||||||||||
| variant='body2' | ||||||||||||||||||||||||||
| color='textSecondary' | ||||||||||||||||||||||||||
| sx={{ textAlign: 'end' }} | ||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||
| {`${readableFolderSize}${readableDriveTotal ? ` / ${readableDriveTotal}` : ''}`} | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor this code to not use nested template literals. sonarjs/no-nested-template-literals |
||||||||||||||||||||||||||
| </Typography> | ||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||
| <Typography | ||||||||||||||||||||||||||
| variant='body2' | ||||||||||||||||||||||||||
| color='textSecondary' | ||||||||||||||||||||||||||
| sx={{ textAlign: 'end' }} | ||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||
| {readableUsedSpace === '?' ? '' : `${readableUsedSpace}`} | ||||||||||||||||||||||||||
| </Typography> | ||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| slots={{ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,20 +1,31 @@ | ||||||||||||||||||||||||||
| import type { FolderStorageDto } from '@jellyfin/sdk/lib/generated-client/models/folder-storage-dto'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export const calculateTotal = (folder?: FolderStorageDto) => { | ||||||||||||||||||||||||||
| if (typeof folder?.UsedSpace === 'undefined' || folder.UsedSpace < 0) { | ||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (!folder) return -1; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const folderSize = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size; | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
|
||||||||||||||||||||||||||
| if (typeof folderSize === 'number' && folderSize >= 0) return folderSize; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (typeof folder?.UsedSpace === 'undefined' || folder.UsedSpace < 0) return -1; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const freeSpace = Math.max(0, folder.FreeSpace || 0); | ||||||||||||||||||||||||||
| const usedSpace = Math.max(0, folder.UsedSpace); | ||||||||||||||||||||||||||
| return freeSpace + usedSpace; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export const calculateUsedPercentage = (folder?: FolderStorageDto) => { | ||||||||||||||||||||||||||
| const totalSpace = calculateTotal(folder); | ||||||||||||||||||||||||||
| if (totalSpace <= 0) return 0; | ||||||||||||||||||||||||||
| if (!folder) return 0; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const usedSpace = folder?.UsedSpace || 0; | ||||||||||||||||||||||||||
| const used = Math.max(0, folder.UsedSpace || 0); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return Math.min(100, (usedSpace / totalSpace) * 100); | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| const driveTotal = (folder as any)?.DriveTotalBytes ?? (folder as any)?.DriveCapacity; | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
|
||||||||||||||||||||||||||
| const folderTotal = (folder as any)?.FolderSizeBytes ?? (folder as any)?.SizeBytes ?? (folder as any)?.Size; | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected any. Specify a different type. @typescript-eslint/no-explicit-any Suggestion(s) available:
Suggested change
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const total = (typeof driveTotal === 'number' && driveTotal > 0) ? driveTotal | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not nest ternary expressions. no-nested-ternary |
||||||||||||||||||||||||||
| : (typeof folderTotal === 'number' && folderTotal > 0) ? folderTotal | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extract this nested ternary operation into an independent statement. sonarjs/no-nested-conditional |
||||||||||||||||||||||||||
| : calculateTotal(folder); | ||||||||||||||||||||||||||
|
Comment on lines
+25
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ':' should be placed at the end of the line. @stylistic/operator-linebreak Fix available:
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected indentation of 12 spaces but found 8. @stylistic/indent Fix available:
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+26
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ':' should be placed at the end of the line. @stylistic/operator-linebreak Fix available:
Suggested change
|
||||||||||||||||||||||||||
| if (total <= 0) return 0; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return Math.min(100, (used / total) * 100); | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newline required at end of file but not found. @stylistic/eol-last Fix available:
Suggested change
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected trailing comma. @stylistic/comma-dangle
Fix available: