LCOV - code coverage report
Current view: top level - src/renderer/extensions/linearMode - LinearPreview.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 50.0 % 42 21
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 { downloadFile } from '@/base/common/downloadUtil'
       6              : import Button from '@comfyorg/design-system/button/Button'
       7              : import Menu from '@comfyorg/design-system/menu/Menu'
       8              : import type { MenuItem } from '@comfyorg/design-system/lib/menu/types'
       9              : import { useAppMode } from '@/composables/useAppMode'
      10              : import { useMediaAssetActions } from '@/platform/assets/composables/useMediaAssetActions'
      11              : import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
      12              : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
      13              : import { extractWorkflowFromAsset } from '@/platform/workflow/utils/workflowExtractionUtil'
      14              : import ImagePreview from '@/renderer/extensions/linearMode/ImagePreview.vue'
      15              : import LatentPreview from '@/renderer/extensions/linearMode/LatentPreview.vue'
      16              : import LinearWelcome from '@/renderer/extensions/linearMode/LinearWelcome.vue'
      17              : import LinearArrange from '@/renderer/extensions/linearMode/LinearArrange.vue'
      18              : import MediaOutputPreview from '@/renderer/extensions/linearMode/MediaOutputPreview.vue'
      19              : import OutputHistory from '@/renderer/extensions/linearMode/OutputHistory.vue'
      20              : import { useOutputHistory } from '@/renderer/extensions/linearMode/useOutputHistory'
      21              : import type { OutputSelection } from '@/renderer/extensions/linearMode/linearModeTypes'
      22              : import { app } from '@/scripts/app'
      23              : import type { AugmentedResultItem } from '@/utils/resultItem'
      24              : import { resultItemUrl } from '@/utils/resultItemUrl'
      25              : import { cn } from '@comfyorg/tailwind-utils'
      26              : 
      27         2355 : const { t } = useI18n()
      28           90 : const mediaActions = useMediaAssetActions()
      29           90 : const { isBuilderMode, isArrangeMode } = useAppMode()
      30           90 : const { outputs, allOutputs, isWorkflowActive, cancelActiveWorkflowJobs } =
      31              :   useOutputHistory()
      32              : const { runButtonClick, mobile } = defineProps<{
      33              :   runButtonClick?: (e: Event) => void
      34              :   mobile?: boolean
      35              : }>()
      36              : 
      37           90 : const selectedItem = ref<AssetItem>()
      38           90 : const selectedOutput = ref<AugmentedResultItem>()
      39           90 : const canShowPreview = ref(true)
      40           90 : const latentPreview = ref<string>()
      41           90 : const showSkeleton = ref(false)
      42           90 : const menuSeparator: MenuItem = { separator: true }
      43              : 
      44           90 : const selectedItemMenuEntries = computed<MenuItem[]>(() => {
      45            7 :   const item = selectedItem.value
      46            7 :   if (!item) return []
      47              : 
      48            7 :   return [
      49              :     ...(allOutputs(item).length > 1
      50              :       ? [
      51              :           {
      52              :             icon: 'icon-[lucide--download]',
      53              :             label: t('linearMode.downloadAll', {
      54              :               count: allOutputs(item).length
      55              :             }),
      56              :             command: () => downloadAsset(item)
      57              :           },
      58              :           menuSeparator
      59              :         ]
      60              :       : []),
      61              :     {
      62              :       icon: 'icon-[lucide--trash-2]',
      63              :       label: t('g.delete'),
      64              :       command: async () => {
      65            0 :         if (await mediaActions.deleteAssets(item)) await outputs.invalidate()
      66              :       }
      67              :     }
      68              :   ]
      69              : })
      70              : 
      71          134 : function handleSelection(sel: OutputSelection) {
      72          134 :   selectedItem.value = sel.asset
      73          134 :   selectedOutput.value = sel.output
      74          134 :   canShowPreview.value = sel.canShowPreview
      75          134 :   latentPreview.value = sel.latentPreviewUrl
      76          134 :   showSkeleton.value = sel.showSkeleton ?? false
      77              : }
      78              : 
      79            0 : function downloadAsset(item?: AssetItem) {
      80            0 :   for (const output of allOutputs(item))
      81            0 :     downloadFile(resultItemUrl(output), output.filename)
      82              : }
      83              : 
      84            0 : function downloadOutput(output?: AugmentedResultItem) {
      85            0 :   if (!output) return
      86            0 :   const url = resultItemUrl(output)
      87            0 :   if (url) downloadFile(url)
      88              : }
      89              : 
      90            0 : async function loadWorkflow(item: AssetItem | undefined) {
      91            0 :   if (!item) return
      92            0 :   const { workflow } = await extractWorkflowFromAsset(item)
      93            0 :   if (!workflow) return
      94              : 
      95            0 :   if (workflow.id !== app.rootGraph.id) return app.loadGraphData(workflow)
      96              :   //update graph to new version, set old to top of undo queue
      97            0 :   const changeTracker = useWorkflowStore().activeWorkflow?.changeTracker
      98            0 :   if (!changeTracker) return app.loadGraphData(workflow)
      99            0 :   changeTracker.redoQueue = []
     100            0 :   await changeTracker.updateState([workflow], changeTracker.undoQueue)
     101              : }
     102              : 
     103            0 : async function rerun(e: Event) {
     104            0 :   if (!runButtonClick) return
     105            0 :   await loadWorkflow(selectedItem.value)
     106            0 :   runButtonClick(e)
     107              : }
     108           90 : </script>
     109              : <template>
     110              :   <section
     111              :     v-if="selectedItem || selectedOutput || showSkeleton || isWorkflowActive"
     112              :     data-testid="linear-output-info"
     113              :     class="flex w-full flex-wrap justify-center gap-2 p-4 text-sm tabular-nums md:z-10"
     114              :   >
     115              :     <template v-if="selectedItem">
     116              :       <Button size="md" @click="rerun">
     117              :         {{ t('linearMode.rerun') }}
     118              :         <i class="icon-[lucide--refresh-cw]" />
     119              :       </Button>
     120              :       <Button size="md" @click="() => loadWorkflow(selectedItem)">
     121              :         {{ t('linearMode.reuseParameters') }}
     122              :         <i class="icon-[lucide--list-restart]" />
     123              :       </Button>
     124              :       <div class="mx-1 border-r border-border/50" />
     125              :     </template>
     126              :     <Button
     127              :       v-if="selectedOutput"
     128              :       :tooltip="t('g.download')"
     129              :       size="icon"
     130              :       :aria-label="t('g.download')"
     131              :       @click="() => downloadOutput(selectedOutput)"
     132              :     >
     133              :       <i class="icon-[lucide--download]" />
     134              :     </Button>
     135              :     <Button
     136              :       v-if="isWorkflowActive && !selectedItem"
     137              :       data-testid="linear-cancel-run"
     138              :       variant="destructive"
     139              :       @click="cancelActiveWorkflowJobs()"
     140              :     >
     141              :       <i class="icon-[lucide--x]" />
     142              :       {{ t('linearMode.cancelThisRun') }}
     143              :     </Button>
     144              :     <Menu v-if="selectedItem" :items="selectedItemMenuEntries">
     145              :       <template #trigger>
     146              :         <Button
     147              :           size="icon"
     148              :           :aria-label="t('g.moreOptions')"
     149              :           icon="icon-[lucide--ellipsis]"
     150              :         />
     151              :       </template>
     152              :     </Menu>
     153              :   </section>
     154              :   <ImagePreview
     155              :     v-if="canShowPreview && latentPreview"
     156              :     :mobile
     157              :     :src="latentPreview"
     158              :     :show-size="false"
     159              :   />
     160              :   <MediaOutputPreview
     161              :     v-else-if="selectedOutput"
     162              :     :output="selectedOutput"
     163              :     :mobile
     164              :   />
     165              :   <LatentPreview v-else-if="showSkeleton || isWorkflowActive" />
     166              :   <LinearArrange v-else-if="isArrangeMode" />
     167              :   <LinearWelcome v-else />
     168              :   <OutputHistory
     169              :     v-if="!isBuilderMode"
     170              :     :class="cn(!mobile && 'z-10 min-w-0')"
     171              :     @update-selection="handleSelection"
     172              :   />
     173              : </template>
        

Generated by: LCOV version 2.0-1