LCOV - code coverage report
Current view: top level - src/components/queue/job - JobAssetsList.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 78.5 % 144 113
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2              :   <div
       3              :     ref="scrollContainer"
       4              :     :tabindex="hasJobRows ? 0 : -1"
       5              :     :role="hasJobRows ? 'region' : undefined"
       6              :     :aria-label="hasJobRows ? $t('g.jobs') : undefined"
       7              :     v-bind="$attrs"
       8              :     data-testid="job-assets-list"
       9              :     class="h-full overflow-y-auto pb-4"
      10              :     @scroll="onListScroll"
      11              :   >
      12              :     <div :style="virtualWrapperStyle">
      13          138 :       <template v-for="{ row, virtualItem } in virtualRows" :key="row.key">
      14              :         <div
      15              :           v-if="row.type === 'header'"
      16              :           class="px-3 pb-2 text-xs leading-none text-muted-foreground"
      17              :           :style="getVirtualRowStyle(virtualItem)"
      18              :         >
      19              :           {{ row.label }}
      20              :         </div>
      21              :         <div
      22              :           v-else-if="row.type === 'job'"
      23              :           class="px-3"
      24              :           :style="getVirtualRowStyle(virtualItem)"
      25              :         >
      26              :           <div
      27              :             :data-job-id="row.job.id"
      28              :             class="h-12"
      29              :             @mouseenter="onJobEnter(row.job, $event)"
      30              :             @mouseleave="onJobLeave(row.job.id)"
      31              :           >
      32              :             <AssetsListItem
      33              :               :class="
      34              :                 cn(
      35              :                   'size-full shrink-0 cursor-default text-foreground transition-colors hover:bg-accent',
      36              :                   row.job.state === 'running' && 'bg-secondary'
      37              :                 )
      38              :               "
      39              :               :preview-url="getJobPreviewUrl(row.job)"
      40              :               :is-video-preview="isVideoPreviewJob(row.job)"
      41              :               :preview-alt="row.job.title"
      42              :               :icon-name="row.job.iconName ?? iconForJobState(row.job.state)"
      43              :               :icon-class="getJobIconClass(row.job)"
      44              :               :primary-text="row.job.title"
      45              :               :secondary-text="row.job.meta"
      46              :               :progress-total-percent="row.job.progressTotalPercent"
      47              :               :progress-current-percent="row.job.progressCurrentPercent"
      48              :               @contextmenu.prevent.stop="$emit('menu', row.job, $event)"
      49              :               @dblclick.stop="emitViewItem(row.job)"
      50              :               @preview-click="emitViewItem(row.job)"
      51              :               @click.stop
      52              :             >
      53              :               <template v-if="hoveredJobId === row.job.id" #actions>
      54              :                 <Button
      55              :                   v-if="isCancelable(row.job)"
      56              :                   variant="destructive"
      57              :                   size="icon"
      58              :                   :aria-label="t('g.cancel')"
      59              :                   @click.stop="emitCancelItem(row.job)"
      60              :                 >
      61              :                   <i class="icon-[lucide--x]" />
      62              :                 </Button>
      63              :                 <Button
      64              :                   v-else-if="isFailedDeletable(row.job)"
      65              :                   variant="destructive"
      66              :                   size="icon"
      67              :                   :aria-label="t('g.delete')"
      68              :                   @click.stop="emitDeleteItem(row.job)"
      69              :                 >
      70              :                   <i class="icon-[lucide--trash-2]" />
      71              :                 </Button>
      72              :                 <Button
      73              :                   v-else-if="row.job.state === 'completed'"
      74              :                   variant="textonly"
      75              :                   size="sm"
      76              :                   @click.stop="emitCompletedViewItem(row.job)"
      77              :                 >
      78              :                   {{ t('menuLabels.View') }}
      79              :                 </Button>
      80              :                 <Button
      81              :                   variant="secondary"
      82              :                   size="icon"
      83              :                   :aria-label="t('g.more')"
      84              :                   @click.stop="$emit('menu', row.job, $event)"
      85              :                 >
      86              :                   <i class="icon-[lucide--ellipsis]" />
      87              :                 </Button>
      88              :               </template>
      89              :             </AssetsListItem>
      90              :           </div>
      91              :         </div>
      92              :       </template>
      93              :     </div>
      94              :   </div>
      95              : 
      96              :   <JobDetailsHoverPopover
      97              :     :open="isDetailsOpen && !!activeDetails && !!activeRowElement"
      98              :     :job-id="activeDetails?.jobId"
      99              :     :workflow-id="activeDetails?.workflowId"
     100              :     :reference-element="activeRowElement"
     101              :     @content-enter="onPopoverEnter"
     102              :     @content-leave="onPopoverLeave"
     103              :     @update:open="onPopoverOpenChange"
     104              :   />
     105              : </template>
     106              : 
     107              : <script setup lang="ts">
     108              : import type { VirtualItem } from '@tanstack/vue-virtual'
     109              : import type { CSSProperties } from 'vue'
     110              : import { useVirtualizer } from '@tanstack/vue-virtual'
     111              : import { useI18n } from 'vue-i18n'
     112              : import { computed, onBeforeUnmount, ref, watch } from 'vue'
     113              : 
     114              : import JobDetailsHoverPopover from '@/components/queue/job/JobDetailsHoverPopover.vue'
     115              : import Button from '@comfyorg/design-system/button/Button'
     116              : import type { JobGroup, JobListItem } from '@/composables/queue/useJobList'
     117              : import { resultItemPreviewUrl } from '@/utils/resultItemUrl'
     118              : import { isImageResult, isVideoResult } from '@/utils/resultItem'
     119              : import AssetsListItem from '@/platform/assets/components/AssetsListItem.vue'
     120              : import { cn } from '@comfyorg/tailwind-utils'
     121              : import { iconForJobState } from '@/utils/queueDisplay'
     122              : import { isActiveJobState } from '@/utils/queueUtil'
     123              : 
     124              : import { buildVirtualJobRows } from './buildVirtualJobRows'
     125              : import type { VirtualJobRow } from './buildVirtualJobRows'
     126              : 
     127         2355 : const HEADER_ROW_HEIGHT = 20
     128         2355 : const GROUP_ROW_GAP = 16
     129         2355 : const JOB_ROW_HEIGHT = 48
     130         2355 : const DETAILS_SHOW_DELAY_MS = 200
     131         2355 : const DETAILS_HIDE_DELAY_MS = 150
     132              : 
     133              : defineOptions({
     134              :   inheritAttrs: false
     135              : })
     136              : 
     137              : const { displayedJobGroups } = defineProps<{ displayedJobGroups: JobGroup[] }>()
     138              : 
     139           30 : const emit = defineEmits<{
     140              :   (e: 'cancelItem', item: JobListItem): void
     141              :   (e: 'deleteItem', item: JobListItem): void
     142              :   (e: 'menu', item: JobListItem, ev: MouseEvent): void
     143              :   (e: 'viewItem', item: JobListItem): void
     144              : }>()
     145              : 
     146           30 : const { t } = useI18n()
     147           30 : const scrollContainer = ref<HTMLElement | null>(null)
     148           30 : const hoveredJobId = ref<string | null>(null)
     149           30 : const activeRowElement = ref<HTMLElement | null>(null)
     150           30 : const activeDetails = ref<{ jobId: string; workflowId?: string } | null>(null)
     151           30 : const isDetailsOpen = ref(false)
     152           30 : const hideTimer = ref<number | null>(null)
     153           30 : const hideTimerJobId = ref<string | null>(null)
     154           30 : const showTimer = ref<number | null>(null)
     155           30 : const flatRows = computed(() => buildVirtualJobRows(displayedJobGroups))
     156           30 : const hasJobRows = computed(() =>
     157              :   flatRows.value.some((row) => row.type === 'job')
     158              : )
     159           30 : const virtualizer = useVirtualizer({
     160              :   get count(): number {
     161           41 :     return flatRows.value.length
     162              :   },
     163              :   getItemKey(index: number) {
     164          220 :     return flatRows.value[index]?.key ?? index
     165              :   },
     166              :   estimateSize(index: number) {
     167          110 :     const row = flatRows.value[index]
     168          110 :     return row ? getRowHeight(row, index, flatRows.value) : JOB_ROW_HEIGHT
     169              :   },
     170              :   getScrollElement() {
     171          142 :     return scrollContainer.value
     172              :   },
     173              :   overscan: 12
     174              : })
     175           30 : const virtualRows = computed(() => {
     176           59 :   const rows = flatRows.value
     177           59 :   return virtualizer.value
     178              :     .getVirtualItems()
     179              :     .flatMap((virtualItem: VirtualItem) => {
     180          122 :       const row = rows[virtualItem.index]
     181          122 :       return row ? [{ row, virtualItem }] : []
     182              :     })
     183              : })
     184           30 : const virtualWrapperStyle = computed<CSSProperties>(() => ({
     185              :   position: 'relative',
     186              :   width: '100%',
     187              :   ...(flatRows.value.length > 0 && {
     188              :     height: `${virtualizer.value.getTotalSize()}px`
     189              :   })
     190              : }))
     191          138 : function getVirtualRowStyle(virtualItem: VirtualItem): CSSProperties {
     192          138 :   return {
     193              :     position: 'absolute',
     194              :     top: 0,
     195              :     left: 0,
     196              :     width: '100%',
     197              :     height: `${virtualItem.size}px`,
     198              :     transform: `translateY(${virtualItem.start}px)`,
     199              :     overflowAnchor: 'none'
     200              :   }
     201              : }
     202              : 
     203          110 : function getRowHeight(
     204              :   row: VirtualJobRow,
     205              :   index: number,
     206              :   rows: VirtualJobRow[]
     207              : ): number {
     208          110 :   if (row.type === 'header') {
     209           23 :     return HEADER_ROW_HEIGHT
     210              :   }
     211              : 
     212          110 :   return (
     213              :     JOB_ROW_HEIGHT + (rows[index + 1]?.type === 'header' ? GROUP_ROW_GAP : 0)
     214              :   )
     215              : }
     216              : 
     217            1 : function onListScroll() {
     218            1 :   hoveredJobId.value = null
     219            1 :   resetActiveDetails()
     220              : }
     221              : 
     222            5 : function clearPopoverAnchor() {
     223            5 :   activeRowElement.value = null
     224              : }
     225              : 
     226            6 : function clearHideTimer() {
     227            6 :   if (hideTimer.value !== null) {
     228            0 :     clearTimeout(hideTimer.value)
     229            0 :     hideTimer.value = null
     230              :   }
     231            6 :   hideTimerJobId.value = null
     232              : }
     233              : 
     234            8 : function clearShowTimer() {
     235            8 :   if (showTimer.value !== null) {
     236            1 :     clearTimeout(showTimer.value)
     237            1 :     showTimer.value = null
     238              :   }
     239              : }
     240              : 
     241            5 : function clearHoverTimers() {
     242            5 :   clearHideTimer()
     243            5 :   clearShowTimer()
     244              : }
     245              : 
     246            5 : function resetActiveDetails() {
     247            5 :   clearHoverTimers()
     248            5 :   isDetailsOpen.value = false
     249            5 :   activeDetails.value = null
     250            5 :   clearPopoverAnchor()
     251              : }
     252              : 
     253            1 : function hasDisplayedJob(jobId: string) {
     254            1 :   return displayedJobGroups.some((group) =>
     255              :     group.items.some((item) => item.id === jobId)
     256              :   )
     257              : }
     258              : 
     259            2 : function scheduleDetailsShow(nextActive: {
     260              :   jobId: string
     261              :   workflowId?: string
     262              : }) {
     263            2 :   clearShowTimer()
     264            2 :   showTimer.value = window.setTimeout(() => {
     265            1 :     showTimer.value = null
     266            1 :     if (!hasDisplayedJob(nextActive.jobId)) return
     267              : 
     268            1 :     activeDetails.value = nextActive
     269            1 :     isDetailsOpen.value = true
     270              :   }, DETAILS_SHOW_DELAY_MS)
     271              : }
     272              : 
     273            0 : function showDetailsNow(nextActive: { jobId: string; workflowId?: string }) {
     274            0 :   clearHoverTimers()
     275            0 :   if (!hasDisplayedJob(nextActive.jobId)) return
     276              : 
     277            0 :   activeDetails.value = nextActive
     278            0 :   isDetailsOpen.value = true
     279              : }
     280              : 
     281            1 : function scheduleDetailsHide(jobId?: string) {
     282            1 :   if (!jobId) return
     283              : 
     284            1 :   clearShowTimer()
     285            1 :   if (hideTimerJobId.value && hideTimerJobId.value !== jobId) {
     286            0 :     return
     287              :   }
     288              : 
     289            1 :   clearHideTimer()
     290            1 :   hideTimerJobId.value = jobId
     291            1 :   hideTimer.value = window.setTimeout(() => {
     292              :     const currentActive = activeDetails.value
     293            1 :     if (currentActive?.jobId === jobId) {
     294            0 :       isDetailsOpen.value = false
     295              :     }
     296            1 :     hideTimer.value = null
     297            1 :     hideTimerJobId.value = null
     298              :   }, DETAILS_HIDE_DELAY_MS)
     299              : }
     300              : 
     301            1 : function onJobLeave(jobId: string) {
     302            1 :   if (hoveredJobId.value === jobId) {
     303            1 :     hoveredJobId.value = null
     304              :   }
     305            1 :   scheduleDetailsHide(jobId)
     306              : }
     307              : 
     308            2 : function onJobEnter(job: JobListItem, event: MouseEvent) {
     309            2 :   hoveredJobId.value = job.id
     310              : 
     311            2 :   const rowElement = event.currentTarget
     312            2 :   if (!(rowElement instanceof HTMLElement)) return
     313              : 
     314            2 :   activeRowElement.value = rowElement
     315            2 :   const nextActive = {
     316              :     jobId: job.id,
     317              :     workflowId: job.taskRef?.workflowId
     318              :   }
     319              : 
     320            2 :   if (isDetailsOpen.value && activeDetails.value?.jobId === job.id) {
     321            0 :     clearHoverTimers()
     322            0 :     return
     323              :   }
     324              : 
     325              :   const isSwitchingVisibleDetails = isDetailsOpen.value
     326              :   const showDetails = isSwitchingVisibleDetails
     327              :     ? showDetailsNow
     328              :     : scheduleDetailsShow
     329              : 
     330            2 :   showDetails(nextActive)
     331              : }
     332              : 
     333            5 : function isCancelable(job: JobListItem) {
     334            5 :   return job.showClear !== false && isActiveJobState(job.state)
     335              : }
     336              : 
     337            5 : function isFailedDeletable(job: JobListItem) {
     338            5 :   return job.showClear !== false && job.state === 'failed'
     339              : }
     340              : 
     341          215 : function getPreviewOutput(job: JobListItem) {
     342          215 :   return job.taskRef?.previewOutput
     343              : }
     344              : 
     345          107 : function getJobPreviewUrl(job: JobListItem) {
     346          107 :   const preview = getPreviewOutput(job)
     347          107 :   if (preview && (isImageResult(preview) || isVideoResult(preview))) {
     348          107 :     return resultItemPreviewUrl(preview)
     349              :   }
     350            0 :   return job.iconImageUrl
     351              : }
     352              : 
     353          107 : function isVideoPreviewJob(job: JobListItem) {
     354          107 :   const preview = getPreviewOutput(job)
     355          107 :   return job.state === 'completed' && !!preview && isVideoResult(preview)
     356              : }
     357              : 
     358            1 : function isPreviewableCompletedJob(job: JobListItem) {
     359            1 :   return job.state === 'completed' && !!getPreviewOutput(job)
     360              : }
     361              : 
     362            1 : function emitViewItem(job: JobListItem) {
     363            1 :   if (isPreviewableCompletedJob(job)) {
     364            1 :     resetActiveDetails()
     365            1 :     emit('viewItem', job)
     366              :   }
     367              : }
     368              : 
     369            0 : function emitCompletedViewItem(job: JobListItem) {
     370            0 :   resetActiveDetails()
     371            0 :   emit('viewItem', job)
     372              : }
     373              : 
     374            0 : function emitCancelItem(job: JobListItem) {
     375            0 :   resetActiveDetails()
     376            0 :   emit('cancelItem', job)
     377              : }
     378              : 
     379            0 : function emitDeleteItem(job: JobListItem) {
     380            0 :   resetActiveDetails()
     381            0 :   emit('deleteItem', job)
     382              : }
     383              : 
     384            0 : function onPopoverEnter() {
     385            0 :   clearHoverTimers()
     386              : }
     387              : 
     388            0 : function onPopoverLeave() {
     389            0 :   scheduleDetailsHide(activeDetails.value?.jobId)
     390              : }
     391              : 
     392            0 : function onPopoverOpenChange(open: boolean) {
     393            0 :   if (!open) {
     394            0 :     resetActiveDetails()
     395              :   }
     396              : }
     397              : 
     398          107 : function getJobIconClass(job: JobListItem): string | undefined {
     399          107 :   const iconName = job.iconName ?? iconForJobState(job.state)
     400          107 :   if (!job.iconImageUrl && iconName === iconForJobState('pending')) {
     401            0 :     return 'animate-spin'
     402              :   }
     403              :   return undefined
     404              : }
     405              : 
     406           30 : watch(
     407              :   () => displayedJobGroups,
     408              :   () => {
     409           11 :     const currentActive = activeDetails.value
     410           11 :     if (!currentActive) return
     411              : 
     412            0 :     if (!hasDisplayedJob(currentActive.jobId)) {
     413            0 :       resetActiveDetails()
     414              :     }
     415              :   }
     416              : )
     417              : 
     418           30 : onBeforeUnmount(resetActiveDetails)
     419              : </script>
        

Generated by: LCOV version 2.0-1