Skip to content

Commit

Permalink
Merge pull request #1473 from nickgros/SWC-7213
Browse files Browse the repository at this point in the history
SWC-7213 - Handle case where `projectStorageLocationUsage` is undefined
  • Loading branch information
xschildw authored Dec 19, 2024
2 parents 3a8d5ca + 1f204a4 commit 0169fdb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const EntityUpload = forwardRef(function EntityUpload(
).length

function uploadFileList(fileList: ArrayLike<File>) {
if (uploadDestination?.projectStorageLocationUsage.isOverLimit) {
if (uploadDestination?.projectStorageLocationUsage?.isOverLimit) {
displayToast(
'Cannot upload files because the storage limit has been exceeded.',
'danger',
Expand All @@ -145,7 +145,7 @@ export const EntityUpload = forwardRef(function EntityUpload(
return (
<div>
<EntityUploadPromptDialog activePrompts={activePrompts} />
{uploadDestination && (
{uploadDestination?.projectStorageLocationUsage && (
<ProjectStorageLimitAlert
usage={uploadDestination.projectStorageLocationUsage}
didUploadsExceedLimit={didUploadsExceedStorageLimit}
Expand All @@ -164,7 +164,7 @@ export const EntityUpload = forwardRef(function EntityUpload(
border: '1px dashed #D9D9D9',
backgroundColor: 'grey.100',
textAlign: 'center',
...(uploadDestination?.projectStorageLocationUsage.isOverLimit
...(uploadDestination?.projectStorageLocationUsage?.isOverLimit
? disabledUploadPaneSx
: {}),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,13 @@ describe('willUploadsExceedStorageLimit', () => {
),
).toEqual(true)
})

test('undefined usage', () => {
const usage = undefined

const pendingUploadsInBytes = 0
expect(
willUploadsExceedStorageLimit([], usage, pendingUploadsInBytes),
).toEqual(false)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { ProjectStorageLocationUsage } from '@sage-bionetworks/synapse-types'
*/
export function willUploadsExceedStorageLimit(
files: ArrayLike<File>,
usage: ProjectStorageLocationUsage,
usage: ProjectStorageLocationUsage | undefined,
pendingUploadsInBytes: number,
): boolean {
if (usage == null) {
return false
}
if (usage.isOverLimit) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion packages/synapse-types/src/File/UploadDestination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface UploadDestination {
uploadType: UploadType
/* If set, the client should show this banner every time an upload is initiated */
banner?: string
projectStorageLocationUsage: ProjectStorageLocationUsage
projectStorageLocationUsage?: ProjectStorageLocationUsage
}

/**
Expand Down

0 comments on commit 0169fdb

Please sign in to comment.