All files / src/lib/uploads resolveUploadActivityStatus.ts

100% Statements 4/4
75% Branches 6/8
100% Functions 0/0
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                    79x             53x               156x           63x          
import type { MultipartUploadStatus } from "./types";
 
type ResolveUploadActivityStatusArgs = {
  uploadStatus: MultipartUploadStatus;
  progressPercentage: number;
  uploadingLabel: string;
  finalizingUploadLabel: string;
  processingLabel?: string | null;
  isProcessing?: boolean;
};
 
/** Resolve the copy shown beside the spinner while a CSV upload/import workflow is still active. */
export function resolveUploadActivityStatus({
  uploadStatus,
  progressPercentage,
  uploadingLabel,
  finalizingUploadLabel,
  processingLabel = null,
  isProcessing = false,
}: ResolveUploadActivityStatusArgs): {
  activeLabel: string | null;
  inactiveLabel: string | null;
} {
  // Terminal import labels should not keep the spinner active, even if
  // upload state momentarily lags behind and still reports "uploading".
  if (!isProcessing && processingLabel) {
    return {
      activeLabel: null,
      inactiveLabel: processingLabel,
    };
  }
 
  if (uploadStatus === "uploading") {
    return {
      activeLabel:
        progressPercentage >= 100 ? finalizingUploadLabel : uploadingLabel,
      inactiveLabel: null,
    };
  }
 
  if (isProcessing && processingLabel) {
    return {
      activeLabel: processingLabel,
      inactiveLabel: null,
    };
  }
 
  return {
    activeLabel: null,
    inactiveLabel: processingLabel,
  };
}