diff --git a/packages/@uppy/dashboard/src/components/StatusBar/StatusBar.tsx b/packages/@uppy/dashboard/src/components/StatusBar/StatusBar.tsx index 72338ccfd..58920b18d 100644 --- a/packages/@uppy/dashboard/src/components/StatusBar/StatusBar.tsx +++ b/packages/@uppy/dashboard/src/components/StatusBar/StatusBar.tsx @@ -22,18 +22,24 @@ type StatusBarProps = { } /** - * Minimal shape of a Transloadit assembly status, read from - * `state.plugins.Transloadit.assemblyStatus`. Kept structural here so that - * `@uppy/dashboard` does not depend on `@uppy/transloadit`. + * Mirror of Transloadit's `AssemblyStatus['ok']` union (see `@transloadit/types`). + * Kept structural here so `@uppy/dashboard` does not depend on `@uppy/transloadit`. */ -export type AssemblyStatus = { ok?: string } +export type AssemblyOk = + | 'ASSEMBLY_UPLOADING' + | 'ASSEMBLY_EXECUTING' + | 'ASSEMBLY_COMPLETED' + | 'ASSEMBLY_CANCELED' + | 'ASSEMBLY_EXPIRED' + | 'ASSEMBLY_REPLAYING' + | 'REQUEST_ABORTED' export function getUploadingState( error: unknown, isAllComplete: boolean, recoveredState: State['recoveredState'], files: Record>, - assemblyStatus?: AssemblyStatus, + assemblyOk?: AssemblyOk, ): StatusBarUIProps['uploadState'] { if (error) { return statusBarStates.STATE_ERROR @@ -58,10 +64,10 @@ export function getUploadingState( // 'restore-confirmed' → uppy.restore(uploadId), which is the only path that // re-invokes tus / Companion (Transloadit disables tus auto-resume via // `storeFingerprintForResuming: false`). - if (assemblyStatus?.ok === 'ASSEMBLY_EXECUTING') { + if (assemblyOk === 'ASSEMBLY_EXECUTING') { return statusBarStates.STATE_POSTPROCESSING } - if (assemblyStatus?.ok === 'ASSEMBLY_UPLOADING') { + if (assemblyOk === 'ASSEMBLY_UPLOADING') { const allUploadsComplete = Object.values(files).every( (f) => f.progress.uploadStarted && f.progress.uploadComplete, ) @@ -243,13 +249,13 @@ export default class StatusBar< error, recoveredState, } = state - // Read Transloadit's live assembly status (if installed) so a live assembly - // can outrank the recovery prompt — see issue #6017. - const assemblyStatus = ( + // Read Transloadit's live assembly status `.ok` (if installed) so a live + // assembly can outrank the recovery prompt — see issue #6017. + const assemblyOk = ( state.plugins?.Transloadit as - | { assemblyStatus?: AssemblyStatus } + | { assemblyStatus?: { ok?: AssemblyOk } } | undefined - )?.assemblyStatus + )?.assemblyStatus?.ok const { newFiles, @@ -300,7 +306,7 @@ export default class StatusBar< isAllComplete, recoveredState, files || {}, - assemblyStatus, + assemblyOk, )} allowNewUpload={allowNewUpload} totalProgress={totalProgress} diff --git a/packages/@uppy/status-bar/src/StatusBar.tsx b/packages/@uppy/status-bar/src/StatusBar.tsx index 19d5800a2..f511b2237 100644 --- a/packages/@uppy/status-bar/src/StatusBar.tsx +++ b/packages/@uppy/status-bar/src/StatusBar.tsx @@ -25,18 +25,26 @@ const speedFilterHalfLife = 2000 const ETAFilterHalfLife = 2000 /** - * Minimal shape of a Transloadit assembly status, read from - * `state.plugins.Transloadit.assemblyStatus` (set by `@uppy/transloadit`). + * Mirror of Transloadit's `AssemblyStatus['ok']` union (see `@transloadit/types`). * Kept structural here so `@uppy/status-bar` does not depend on `@uppy/transloadit`. + * Errors leave `ok` absent on the server side, so this is the full set of + * non-error values the server can send. */ -type AssemblyStatus = { ok?: string } +type AssemblyOk = + | 'ASSEMBLY_UPLOADING' + | 'ASSEMBLY_EXECUTING' + | 'ASSEMBLY_COMPLETED' + | 'ASSEMBLY_CANCELED' + | 'ASSEMBLY_EXPIRED' + | 'ASSEMBLY_REPLAYING' + | 'REQUEST_ABORTED' export function getUploadingState( error: unknown, isAllComplete: boolean, recoveredState: unknown, files: Record>, - assemblyStatus?: AssemblyStatus, + assemblyOk?: AssemblyOk, ): StatusBarUIProps['uploadState'] { if (error) { return statusBarStates.STATE_ERROR @@ -61,10 +69,10 @@ export function getUploadingState( // 'restore-confirmed' → uppy.restore(uploadId), which is the only path that // re-invokes tus / Companion (Transloadit disables tus auto-resume via // `storeFingerprintForResuming: false`). - if (assemblyStatus?.ok === 'ASSEMBLY_EXECUTING') { + if (assemblyOk === 'ASSEMBLY_EXECUTING') { return statusBarStates.STATE_POSTPROCESSING } - if (assemblyStatus?.ok === 'ASSEMBLY_UPLOADING') { + if (assemblyOk === 'ASSEMBLY_UPLOADING') { const allUploadsComplete = Object.values(files).every( (f) => f.progress.uploadStarted && f.progress.uploadComplete, ) @@ -254,13 +262,13 @@ export default class StatusBar extends UIPlugin< }) // Transloadit's plugin state, if installed, exposes the live assembly - // status. Reading it here lets a non-terminal assembly outrank the + // status. Reading `.ok` here lets a non-terminal assembly outrank the // "press Upload to resume" UI on restore — see issue #6017. - const assemblyStatus = ( + const assemblyOk = ( state.plugins?.Transloadit as - | { assemblyStatus?: AssemblyStatus } + | { assemblyStatus?: { ok?: AssemblyOk } } | undefined - )?.assemblyStatus + )?.assemblyStatus?.ok return StatusBarUI({ error, @@ -269,7 +277,7 @@ export default class StatusBar extends UIPlugin< isAllComplete, recoveredState, state.files || {}, - assemblyStatus, + assemblyOk, ), allowNewUpload, totalProgress,