LCOV - code coverage report
Current view: top level - src/platform/assets/components - AssetExportProgressDialog.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 76.3 % 38 29
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <script setup lang="ts">
       2              : import { computed, ref } from 'vue'
       3              : import { useI18n } from 'vue-i18n'
       4              : 
       5              : import Loader from '@/components/loader/Loader.vue'
       6              : import ToastPanel from '@comfyorg/design-system/toast/ToastPanel'
       7              : import Button from '@comfyorg/design-system/button/Button'
       8              : import Tooltip from '@comfyorg/design-system/tooltip/Tooltip'
       9              : import TooltipContent from '@comfyorg/design-system/tooltip/TooltipContent'
      10              : import TooltipTrigger from '@comfyorg/design-system/tooltip/TooltipTrigger'
      11              : import type { AssetExport } from '@/stores/assetExportStore'
      12              : import { useAssetExportStore } from '@/stores/assetExportStore'
      13              : import { cn } from '@comfyorg/tailwind-utils'
      14              : 
      15         2355 : const { t } = useI18n()
      16         2355 : const assetExportStore = useAssetExportStore()
      17              : 
      18         2355 : const visible = computed(() => assetExportStore.hasExports)
      19         2355 : const isExpanded = ref(false)
      20              : 
      21         2355 : const exportJobs = computed(() => assetExportStore.exportList)
      22         2355 : const failedJobs = computed(() =>
      23              :   assetExportStore.finishedExports.filter((e) => e.status === 'failed')
      24              : )
      25         2355 : const cancelledJobs = computed(() =>
      26              :   assetExportStore.finishedExports.filter((e) => e.status === 'cancelled')
      27              : )
      28              : 
      29         2355 : const isInProgress = computed(() => assetExportStore.hasActiveExports)
      30         2355 : const currentJobName = computed(() => {
      31              :   const activeJob = exportJobs.value.find((job) => job.status === 'running')
      32            1 :   return activeJob?.exportName || t('exportToast.preparingExport')
      33              : })
      34              : 
      35            2 : function jobDisplayName(job: AssetExport): string {
      36            2 :   if (job.status === 'failed') return job.error || t('exportToast.exportError')
      37            2 :   return job.exportName || t('exportToast.preparingExport')
      38              : }
      39              : 
      40         2355 : const completedCount = computed(() => assetExportStore.finishedExports.length)
      41         2355 : const totalCount = computed(() => exportJobs.value.length)
      42              : 
      43         2355 : const footerLabel = computed(() => {
      44         2364 :   if (isInProgress.value) return currentJobName.value
      45         2364 :   if (failedJobs.value.length > 0)
      46            0 :     return t('exportToast.exportFailed', { count: failedJobs.value.length })
      47         2364 :   if (cancelledJobs.value.length > 0) return t('electronFileDownload.cancelled')
      48         2363 :   return t('exportToast.allExportsCompleted')
      49              : })
      50              : 
      51         2355 : const announcement = computed(() =>
      52              :   isInProgress.value ? t('exportToast.exportingAssets') : footerLabel.value
      53              : )
      54              : 
      55         2355 : const footerIconClass = computed(() => {
      56            1 :   if (isInProgress.value)
      57            1 :     return 'icon-[lucide--loader-circle] animate-spin text-muted-foreground'
      58            0 :   if (failedJobs.value.length > 0)
      59            0 :     return 'icon-[lucide--circle-alert] text-destructive'
      60            0 :   if (cancelledJobs.value.length > 0)
      61            0 :     return 'icon-[lucide--circle-x] text-muted-foreground'
      62            0 :   return 'icon-[lucide--check-circle] text-success'
      63              : })
      64              : 
      65            2 : function progressPercent(job: AssetExport): number {
      66            2 :   return Math.round(job.progress * 100)
      67              : }
      68              : 
      69            0 : function closeDialog() {
      70            0 :   assetExportStore.clearFinishedExports()
      71            0 :   isExpanded.value = false
      72              : }
      73         2355 : </script>
      74              : 
      75              : <template>
      76         2365 :   <ToastPanel v-model:expanded="isExpanded" :visible :announcement>
      77              :     <template #default>
      78              :       <div class="flex h-12 items-center justify-between border-b px-4">
      79              :         <h3 class="text-sm font-bold">
      80              :           {{ t('exportToast.exportingAssets') }}
      81              :         </h3>
      82              :       </div>
      83              : 
      84              :       <div class="relative max-h-75 overflow-y-auto p-4">
      85              :         <div class="flex flex-col gap-2">
      86            2 :           <div
      87              :             v-for="job in exportJobs"
      88              :             :key="job.taskId"
      89              :             :class="
      90              :               cn(
      91              :                 'flex items-center justify-between rounded-lg bg-secondary px-4 py-3',
      92              :                 job.status === 'completed' && 'opacity-50'
      93              :               )
      94              :             "
      95              :           >
      96              :             <div class="min-w-0 flex-1">
      97              :               <span
      98              :                 :class="
      99              :                   cn(
     100              :                     'block truncate text-sm',
     101              :                     job.status === 'failed'
     102              :                       ? 'text-destructive'
     103              :                       : 'text-foreground'
     104              :                   )
     105              :                 "
     106              :               >
     107              :                 {{ jobDisplayName(job) }}
     108              :               </span>
     109              :               <span
     110              :                 v-if="job.assetsTotal > 0"
     111              :                 class="text-xs text-muted-foreground"
     112              :               >
     113              :                 {{ job.assetsAttempted }}/{{ job.assetsTotal }}
     114              :               </span>
     115              :             </div>
     116              : 
     117              :             <div class="flex items-center gap-2">
     118              :               <template v-if="job.status === 'failed'">
     119              :                 <i class="icon-[lucide--circle-alert] text-destructive" />
     120              :               </template>
     121              :               <template
     122              :                 v-else-if="job.status === 'completed' && job.downloadError"
     123              :               >
     124              :                 <span class="max-w-32 truncate text-xs text-destructive">
     125              :                   {{ job.downloadError }}
     126              :                 </span>
     127              :                 <Button
     128              :                   variant="muted-textonly"
     129              :                   size="icon"
     130              :                   :aria-label="t('exportToast.retryDownload')"
     131              :                   @click.stop="assetExportStore.triggerDownload(job, true)"
     132              :                 >
     133              :                   <i class="icon-[lucide--rotate-ccw] text-destructive" />
     134              :                 </Button>
     135              :               </template>
     136              :               <template v-else-if="job.status === 'completed'">
     137              :                 <Button
     138              :                   variant="muted-textonly"
     139              :                   size="icon"
     140              :                   :aria-label="t('exportToast.downloadExport')"
     141              :                   @click.stop="assetExportStore.triggerDownload(job, true)"
     142              :                 >
     143              :                   <i class="icon-[lucide--download] text-success" />
     144              :                 </Button>
     145              :               </template>
     146              :               <template v-else-if="job.status === 'cancelled'">
     147              :                 <span class="text-xs text-muted-foreground">
     148              :                   {{ t('electronFileDownload.cancelled') }}
     149              :                 </span>
     150              :               </template>
     151              :               <template v-else-if="job.status === 'running'">
     152              :                 <Loader size="sm" class="text-foreground" />
     153              :                 <span class="text-xs"> {{ progressPercent(job) }}% </span>
     154              :               </template>
     155              :               <template v-else>
     156              :                 <span class="text-xs text-muted-foreground">
     157              :                   {{ t('progressToast.pending') }}
     158              :                 </span>
     159              :               </template>
     160              :             </div>
     161              :           </div>
     162              :         </div>
     163              : 
     164              :         <div
     165              :           v-if="exportJobs.length === 0"
     166              :           class="flex flex-col items-center justify-center py-6 text-center"
     167              :         >
     168              :           <span class="text-sm text-muted-foreground">
     169              :             {{
     170              :               t('exportToast.noExportsInQueue', {
     171              :                 filter: t('progressToast.filter.all')
     172              :               })
     173              :             }}
     174              :           </span>
     175              :         </div>
     176              :       </div>
     177              :     </template>
     178              : 
     179              :     <template #footer="{ toggle }">
     180              :       <div
     181              :         class="flex h-12 min-w-0 flex-1 items-center justify-between gap-2 border-t px-4"
     182              :       >
     183              :         <div class="flex min-w-0 flex-1 items-center gap-2 text-sm">
     184              :           <Tooltip :disabled="isExpanded">
     185              :             <TooltipTrigger as-child>
     186              :               <i :class="footerIconClass" />
     187              :             </TooltipTrigger>
     188              :             <TooltipContent>{{ footerLabel }}</TooltipContent>
     189              :           </Tooltip>
     190              :           <span
     191              :             :class="
     192              :               cn(
     193              :                 'truncate overflow-hidden font-bold transition-all duration-300',
     194              :                 isExpanded ? 'min-w-0 flex-1' : 'w-0'
     195              :               )
     196              :             "
     197              :           >
     198              :             {{ footerLabel }}
     199              :           </span>
     200              :         </div>
     201              : 
     202              :         <div class="flex items-center gap-2">
     203              :           <span
     204              :             v-if="isInProgress"
     205              :             :class="
     206              :               cn(
     207              :                 'overflow-hidden text-sm text-muted-foreground transition-all duration-300',
     208              :                 isExpanded ? 'whitespace-nowrap' : 'w-0'
     209              :               )
     210              :             "
     211              :           >
     212              :             {{
     213              :               t('progressToast.progressCount', {
     214              :                 completed: completedCount,
     215              :                 total: totalCount
     216              :               })
     217              :             }}
     218              :           </span>
     219              : 
     220              :           <div class="flex items-center">
     221              :             <Button
     222              :               variant="muted-textonly"
     223              :               size="icon"
     224              :               :aria-label="
     225              :                 isExpanded ? t('contextMenu.Collapse') : t('contextMenu.Expand')
     226              :               "
     227              :               @click.stop="toggle"
     228              :             >
     229              :               <i
     230              :                 :class="
     231              :                   isExpanded
     232              :                     ? 'icon-[lucide--chevron-down]'
     233              :                     : 'icon-[lucide--chevron-up]'
     234              :                 "
     235              :               />
     236              :             </Button>
     237              : 
     238              :             <Button
     239              :               v-if="!isInProgress"
     240              :               variant="muted-textonly"
     241              :               size="icon"
     242              :               :aria-label="t('g.close')"
     243              :               @click.stop="closeDialog"
     244              :             >
     245              :               <i class="icon-[lucide--x]" />
     246              :             </Button>
     247              :           </div>
     248              :         </div>
     249              :       </div>
     250              :     </template>
     251              :   </ToastPanel>
     252              : </template>
        

Generated by: LCOV version 2.0-1