LCOV - code coverage report
Current view: top level - src/components/topbar - WorkflowTab.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 98.4 % 64 63
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2              :   <ContextMenuRoot :modal="false">
       3              :     <ContextMenuTrigger as-child>
       4              :       <div
       5              :         ref="workflowTabRef"
       6              :         data-testid="workflow-tab"
       7              :         :class="
       8              :           cn(
       9              :             'workflow-tab group/tab relative h-full min-w-22.5 motion-safe:transition-[flex-shrink] motion-safe:duration-200 motion-safe:ease-out',
      10              :             isActiveTab ? 'shrink-0' : 'shrink'
      11              :           )
      12              :         "
      13              :         v-bind="$attrs"
      14              :         @mouseenter="handleMouseEnter"
      15              :         @mouseleave="handleMouseLeave"
      16              :         @click="handleClick"
      17              :       >
      18              :         <TabsTrigger
      19              :           :value="workflowOption.workflow.path"
      20              :           class="h-full w-full py-2 pr-2 pl-3"
      21              :         >
      22              :           <template v-if="showModeIcon">
      23              :             <i
      24              :               v-if="isBuilderState"
      25              :               data-testid="workflow-mode-icon"
      26              :               class="icon-[lucide--hammer] bg-muted-foreground"
      27              :             />
      28              :             <i
      29              :               v-else-if="workflowOption.workflow.initialMode === 'app'"
      30              :               data-testid="workflow-mode-icon"
      31              :               class="icon-[lucide--panels-top-left] bg-primary"
      32              :             />
      33              :           </template>
      34              :           <WorkflowAgentTargetIndicator
      35              :             :workflow-path="workflowOption.workflow.path"
      36              :           />
      37              :           <span
      38              :             class="workflow-label inline-block max-w-[150px] truncate font-inter text-sm leading-none font-normal text-inherit"
      39              :           >
      40              :             {{ workflowOption.workflow.filename }}
      41              :           </span>
      42              :           <span
      43              :             :class="
      44              :               cn(
      45              :                 'relative size-4 shrink-0 group-focus-within/tab:invisible',
      46              :                 revealsCloseOnHover && 'group-hover/tab:invisible'
      47              :               )
      48              :             "
      49              :           >
      50              :             <span
      51              :               v-if="isAgentAwaitingApproval"
      52              :               role="img"
      53              :               :aria-label="t('g.agentNeedsApproval')"
      54              :               class="absolute top-1/2 left-1/2 z-10 size-2 -translate-1/2 rounded-full bg-warning"
      55              :             />
      56              :             <i
      57              :               v-else-if="isAgentEditing"
      58              :               role="img"
      59              :               :aria-label="t('g.agentWorking')"
      60              :               class="absolute top-1/2 left-1/2 z-10 icon-[lucide--loader-circle] -translate-1/2 text-muted-foreground motion-safe:animate-spin"
      61              :             />
      62              :             <span
      63              :               v-else-if="showUnseenAgentDot"
      64              :               role="img"
      65              :               :aria-label="t('g.agentModified')"
      66              :               data-testid="agent-modified-indicator"
      67              :               class="absolute top-1/2 left-1/2 z-10 size-2 -translate-1/2 rounded-full bg-primary"
      68              :             />
      69              :             <i
      70              :               v-else-if="workflowStatus"
      71              :               role="img"
      72              :               :aria-label="workflowStatusLabel"
      73              :               :class="
      74              :                 cn(
      75              :                   'absolute top-1/2 left-1/2 z-10 -translate-1/2',
      76              :                   workflowStatusIconClasses[workflowStatus]
      77              :                 )
      78              :               "
      79              :             />
      80              :             <span
      81              :               v-else-if="shouldShowUnsavedIndicator"
      82              :               data-testid="workflow-dirty-indicator"
      83              :               :class="
      84              :                 cn(
      85              :                   'absolute top-1/2 left-1/2 z-10 size-2 -translate-1/2 rounded-full',
      86              :                   isActiveTab ? 'bg-foreground' : 'bg-muted-foreground'
      87              :                 )
      88              :               "
      89              :             />
      90              :           </span>
      91              :         </TabsTrigger>
      92              :         <Button
      93              :           :class="
      94              :             cn(
      95              :               'close-button absolute top-1/2 right-2 size-4 -translate-y-1/2 rounded-none p-0 group-focus-within/tab:visible',
      96              :               closeButtonVisibility,
      97              :               revealsCloseOnHover && 'group-hover/tab:visible'
      98              :             )
      99              :           "
     100              :           variant="muted-textonly"
     101              :           size="unset"
     102              :           :aria-label="t('g.close')"
     103              :           data-testid="close-workflow-button"
     104              :           @click.stop="onCloseWorkflow(workflowOption)"
     105              :         >
     106              :           <i data-testid="close-workflow-icon" class="icon-[lucide--x]" />
     107              :         </Button>
     108              :       </div>
     109              :     </ContextMenuTrigger>
     110              :     <ContextMenuContent class="min-w-56">
     111              :       <MenuItems :items="contextMenuItems" />
     112              :     </ContextMenuContent>
     113              :   </ContextMenuRoot>
     114              :   <WorkflowTabPopover
     115              :     v-model:open="popoverOpen"
     116              :     v-model:clicked="popoverClicked"
     117              :     :anchor="workflowTabRef"
     118              :     :hovered="popoverHovered"
     119              :     :workflow-filename="workflowOption.workflow.filename"
     120              :     :thumbnail-url="thumbnailUrl"
     121              :     :is-active-tab="isActiveTab"
     122              :   />
     123              : </template>
     124              : 
     125              : <script setup lang="ts">
     126              : import { ContextMenuRoot, ContextMenuTrigger } from 'reka-ui'
     127              : import { computed, ref } from 'vue'
     128              : import { useI18n } from 'vue-i18n'
     129              : 
     130              : import Button from '@comfyorg/design-system/button/Button'
     131              : import MenuItems from '@comfyorg/design-system/menu/MenuItems'
     132              : import ContextMenuContent from '@comfyorg/design-system/menu/ContextMenuContent'
     133              : import TabsTrigger from '@comfyorg/design-system/tabs/TabsTrigger'
     134              : import {
     135              :   usePragmaticDraggable,
     136              :   usePragmaticDroppable
     137              : } from '@/composables/usePragmaticDragAndDrop'
     138              : import { useWorkflowActionsMenu } from '@/composables/useWorkflowActionsMenu'
     139              : import { useSettingStore } from '@/platform/settings/settingStore'
     140              : import { useWorkflowService } from '@/platform/workflow/core/services/workflowService'
     141              : import type { ComfyWorkflow } from '@/platform/workflow/management/stores/workflowStore'
     142              : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
     143              : import { useWorkflowThumbnail } from '@/renderer/core/thumbnail/useWorkflowThumbnail'
     144              : import { useCommandStore } from '@/platform/keybindings/commandStore'
     145              : import type { WorkflowExecutionStatus } from '@/stores/executionStore'
     146              : import {
     147              :   useExecutionStore,
     148              :   WORKFLOW_STATUS_I18N_KEYS
     149              : } from '@/stores/executionStore'
     150              : import { useWorkflowTabActivityStore } from '@/stores/workflowTabActivityStore'
     151              : import { useWorkspaceStore } from '@/stores/workspaceStore'
     152              : import type { WorkflowMenuItem } from '@/types/workflowMenuItem'
     153              : import { cn } from '@comfyorg/tailwind-utils'
     154              : 
     155              : import WorkflowTabPopover from './WorkflowTabPopover.vue'
     156              : import WorkflowAgentTargetIndicator from './WorkflowAgentTargetIndicator.vue'
     157              : 
     158              : defineOptions({ inheritAttrs: false })
     159              : 
     160              : interface WorkflowOption {
     161              :   value: string
     162              :   workflow: ComfyWorkflow
     163              : }
     164              : 
     165              : const {
     166              :   workflowOption,
     167              :   isFirst,
     168              :   isLast,
     169              :   compact = false
     170              : } = defineProps<{
     171              :   workflowOption: WorkflowOption
     172              :   isFirst: boolean
     173              :   isLast: boolean
     174              :   compact?: boolean
     175              : }>()
     176              : 
     177         3370 : const emit = defineEmits<{
     178              :   closeToLeft: []
     179              :   closeToRight: []
     180              :   closeOthers: []
     181              : }>()
     182              : 
     183         3370 : const { t } = useI18n()
     184              : 
     185         3370 : const workspaceStore = useWorkspaceStore()
     186         3370 : const workflowStore = useWorkflowStore()
     187         3370 : const settingStore = useSettingStore()
     188         3370 : const executionStore = useExecutionStore()
     189         3370 : const workflowTabRef = ref<HTMLElement | null>(null)
     190         3370 : const popoverOpen = ref(false)
     191         3370 : const popoverHovered = ref(false)
     192         3370 : const popoverClicked = ref(false)
     193         3370 : const workflowThumbnail = useWorkflowThumbnail()
     194              : 
     195              : // Use computed refs to cache autosave settings
     196         3370 : const autoSaveSetting = computed(() =>
     197              :   settingStore.get('Comfy.Workflow.AutoSave')
     198              : )
     199         3370 : const autoSaveDelay = computed(() =>
     200              :   settingStore.get('Comfy.Workflow.AutoSaveDelay')
     201              : )
     202              : 
     203         3370 : const shouldShowUnsavedIndicator = computed(() => {
     204         5537 :   if (workspaceStore.shiftDown) {
     205              :     // Branch 1: Shift key is held down, do not show the status indicator.
     206           63 :     return false
     207              :   }
     208         5474 :   if (!workflowOption.workflow.isPersisted) {
     209              :     // Branch 2: Workflow is not persisted, show the status indicator.
     210         5077 :     return true
     211              :   }
     212          961 :   if (workflowOption.workflow.isModified) {
     213              :     // Branch 3: Workflow is modified.
     214           49 :     if (autoSaveSetting.value === 'off') {
     215              :       // Sub-branch 3a: Autosave is off, so show the status indicator.
     216           47 :       return true
     217              :     }
     218           49 :     if (autoSaveSetting.value === 'after delay' && autoSaveDelay.value > 3000) {
     219              :       // Sub-branch 3b: Autosave delay is too high, so show the status indicator.
     220            0 :       return true
     221              :     }
     222              :     // Sub-branch 3c: Workflow is modified but no condition applies, do not show the status indicator.
     223            2 :     return false
     224              :   }
     225              :   // Default: do not show the status indicator. This should not be reachable.
     226          348 :   return false
     227              : })
     228              : 
     229         3370 : const isBuilderState = computed(() => {
     230         5415 :   const currentMode = workflowOption.workflow.activeMode
     231         5415 :   return typeof currentMode === 'string' && currentMode.startsWith('builder:')
     232              : })
     233              : 
     234         3370 : const isActiveTab = computed(() => {
     235         9940 :   return workflowStore.isActive(workflowOption.workflow)
     236              : })
     237              : 
     238         3370 : const showModeIcon = computed(() => !compact || isActiveTab.value)
     239              : 
     240         3370 : const workflowStatusIconClasses: Record<WorkflowExecutionStatus, string> = {
     241              :   running:
     242              :     'text-foreground icon-[lucide--loader-circle] motion-safe:animate-spin',
     243              :   completed: 'icon-[lucide--circle-check] text-success',
     244              :   failed: 'icon-[lucide--octagon-alert] text-destructive'
     245              : }
     246              : 
     247         3370 : const tabActivity = useWorkflowTabActivityStore()
     248              : 
     249         3370 : const isAgentAwaitingApproval = computed(() =>
     250              :   tabActivity.awaitingApprovalPaths.has(workflowOption.workflow.path)
     251              : )
     252              : 
     253         3370 : const isAgentEditing = computed(() =>
     254              :   tabActivity.editingPaths.has(workflowOption.workflow.path)
     255              : )
     256              : 
     257              : // The active tab doesn't badge its own status - the user is already looking
     258              : // at it. Background tabs surface the recorded execution status.
     259         3370 : const workflowStatus = computed(() =>
     260              :   isActiveTab.value
     261              :     ? undefined
     262              :     : executionStore.getWorkflowStatus(workflowOption.workflow)
     263              : )
     264              : 
     265              : // A failed run outranks the unseen-changes dot so the failure isn't masked.
     266         3370 : const showUnseenAgentDot = computed(
     267              :   () =>
     268              :     tabActivity.unseenModifiedPaths.has(workflowOption.workflow.path) &&
     269              :     workflowStatus.value !== 'failed'
     270              : )
     271              : 
     272         3370 : const workflowStatusLabel = computed(() =>
     273              :   workflowStatus.value
     274              :     ? t(WORKFLOW_STATUS_I18N_KEYS[workflowStatus.value])
     275              :     : undefined
     276              : )
     277              : 
     278         3370 : const hasStatusIndicator = computed(
     279              :   () =>
     280              :     isAgentAwaitingApproval.value ||
     281              :     isAgentEditing.value ||
     282              :     showUnseenAgentDot.value ||
     283              :     workflowStatus.value !== undefined ||
     284              :     shouldShowUnsavedIndicator.value
     285              : )
     286              : 
     287         3370 : const revealsCloseOnHover = computed(
     288              :   () => isActiveTab.value || !compact || !hasStatusIndicator.value
     289              : )
     290              : 
     291         3370 : const closeButtonVisibility = computed(() =>
     292              :   isActiveTab.value && !hasStatusIndicator.value ? 'visible' : 'invisible'
     293              : )
     294              : 
     295         3370 : const thumbnailUrl = computed(() => {
     296         6338 :   return workflowThumbnail.getThumbnail(workflowOption.workflow.key)
     297              : })
     298              : 
     299         3370 : const handleMouseEnter = () => {
     300          156 :   popoverClicked.value = false
     301          156 :   popoverHovered.value = true
     302              : }
     303              : 
     304         3370 : const handleMouseLeave = () => {
     305          107 :   popoverHovered.value = false
     306              : }
     307              : 
     308         3370 : const handleClick = () => {
     309           45 :   if (!popoverOpen.value) popoverClicked.value = true
     310           45 :   popoverOpen.value = !popoverOpen.value
     311              : }
     312              : 
     313         3370 : const onCloseWorkflow = (option: WorkflowOption) =>
     314              :   useWorkflowService().closeWorkflows([option.workflow], {
     315              :     warnIfUnsaved: !workspaceStore.shiftDown,
     316              :     hint: t('sideToolbar.workflowTab.dirtyCloseHint'),
     317              :     initiator: 'user'
     318              :   })
     319              : 
     320         3370 : const commandStore = useCommandStore()
     321              : const workflow = computed(() => workflowOption.workflow)
     322              : 
     323         3370 : const { menuItems: baseMenuItems } = useWorkflowActionsMenu(
     324              :   () => commandStore.execute('Comfy.RenameWorkflow'),
     325              :   { includeDelete: false, workflow }
     326              : )
     327              : 
     328         3370 : const contextMenuItems = computed<WorkflowMenuItem[]>(() => [
     329              :   ...baseMenuItems.value,
     330              :   { separator: true },
     331              :   {
     332              :     id: 'close-tab',
     333              :     label: t('tabMenu.closeTab'),
     334              :     icon: 'icon-[lucide--x]',
     335              :     command: () => onCloseWorkflow(workflowOption)
     336              :   },
     337              :   {
     338              :     id: 'close-tabs-to-left',
     339              :     label: t('tabMenu.closeTabsToLeft'),
     340              :     overlayIcon: {
     341              :       mainIcon: 'icon-[lucide--x]',
     342              :       subIcon: 'icon-[lucide--arrow-left]',
     343              :       positionX: 'right',
     344              :       positionY: 'bottom',
     345              :       subIconScale: 0.5
     346              :     },
     347              :     command: () => emit('closeToLeft'),
     348              :     disabled: isFirst
     349              :   },
     350              :   {
     351              :     id: 'close-tabs-to-right',
     352              :     label: t('tabMenu.closeTabsToRight'),
     353              :     overlayIcon: {
     354              :       mainIcon: 'icon-[lucide--x]',
     355              :       subIcon: 'icon-[lucide--arrow-right]',
     356              :       positionX: 'right',
     357              :       positionY: 'bottom',
     358              :       subIconScale: 0.5
     359              :     },
     360              :     command: () => emit('closeToRight'),
     361              :     disabled: isLast
     362              :   },
     363              :   {
     364              :     id: 'close-other-tabs',
     365              :     label: t('tabMenu.closeOtherTabs'),
     366              :     overlayIcon: {
     367              :       mainIcon: 'icon-[lucide--x]',
     368              :       subIcon: 'icon-[lucide--move-horizontal]',
     369              :       positionX: 'right',
     370              :       positionY: 'bottom',
     371              :       subIconScale: 0.5
     372              :     },
     373              :     command: () => emit('closeOthers'),
     374              :     disabled: isFirst && isLast
     375              :   }
     376              : ])
     377              : 
     378         3370 : const tabGetter = () => workflowTabRef.value as HTMLElement
     379              : 
     380         3370 : usePragmaticDraggable(tabGetter, {
     381              :   getInitialData: () => {
     382            4 :     return {
     383              :       workflowKey: workflowOption.workflow.key
     384              :     }
     385              :   }
     386              : })
     387              : 
     388         3370 : usePragmaticDroppable(tabGetter, {
     389              :   getData: () => {
     390           10 :     return {
     391              :       workflowKey: workflowOption.workflow.key
     392              :     }
     393              :   },
     394              :   onDrop: (e) => {
     395            3 :     const fromIndex = workflowStore.openWorkflows.findIndex(
     396              :       (wf) => wf.key === e.source.data.workflowKey
     397              :     )
     398            3 :     const toIndex = workflowStore.openWorkflows.findIndex(
     399              :       (wf) => wf.key === e.location.current.dropTargets[0]?.data.workflowKey
     400              :     )
     401            3 :     if (fromIndex !== toIndex) {
     402            3 :       workflowStore.reorderWorkflows(fromIndex, toIndex)
     403              :     }
     404              :   }
     405              : })
     406              : </script>
        

Generated by: LCOV version 2.0-1