LCOV - code coverage report
Current view: top level - src/components/breadcrumb - SubgraphBreadcrumb.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 56 56
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2         5581 :   <div
       3              :     data-testid="subgraph-breadcrumb"
       4              :     :data-collapsed="collapseTabs || undefined"
       5              :     class="flex min-w-30 flex-auto shrink-10000 items-center overflow-hidden drop-shadow-(--interface-panel-drop-shadow)"
       6              :     :style="{
       7              :       '--breadcrumb-item-margin': `${ITEM_GAP / 2}px`,
       8              :       '--breadcrumb-item-min-width': `${MIN_WIDTH}px`,
       9              :       '--breadcrumb-item-padding': `${ITEM_PADDING}px`
      10              :     }"
      11              :   >
      12              :     <WorkflowActionsDropdown
      13              :       v-if="!canvasStore.linearMode"
      14              :       source="breadcrumb_subgraph_menu_selected"
      15              :     />
      16              :     <Button
      17              :       v-if="isInSubgraph"
      18              :       class="pointer-events-auto ml-1.5 shrink-0 border border-transparent p-0 transition-all hover:rounded-lg hover:border-border hover:bg-background"
      19              :       data-testid="subgraph-breadcrumb-back"
      20              :       variant="muted-textonly"
      21              :       size="icon"
      22              :       @click="handleBackClick"
      23              :     >
      24              :       <i class="icon-[lucide--undo-2]" />
      25              :     </Button>
      26              :     <nav
      27              :       :class="
      28              :         cn(
      29              :           'w-full overflow-hidden rounded-lg bg-transparent p-0',
      30              :           !isInSubgraph && 'hidden'
      31              :         )
      32              :       "
      33              :       :aria-label="$t('g.graphNavigation')"
      34              :     >
      35              :       <ol
      36              :         ref="breadcrumbListRef"
      37              :         :class="
      38              :           cn(
      39              :             'm-0 flex list-none items-center p-0 text-muted-foreground',
      40              :             collapseTabs && '[&>li]:hidden [&>li:nth-last-child(-n+3)]:flex'
      41              :           )
      42              :         "
      43              :       >
      44         5696 :         <template v-for="(item, index) in items" :key="item.key">
      45              :           <li
      46              :             data-breadcrumb-item
      47              :             class="pointer-events-auto flex h-8 min-w-[calc(var(--breadcrumb-item-min-width)+1rem)] shrink-10000 items-center overflow-hidden border border-transparent transition-all duration-200 first:shrink-5000 last:shrink hover:rounded-lg hover:border-border hover:bg-background hover:text-foreground has-data-active:min-w-[calc(var(--breadcrumb-item-min-width)+1rem+20px)]"
      48              :           >
      49              :             <SubgraphBreadcrumbItem
      50              :               :item
      51              :               :is-active="item.key === activeItemKey"
      52              :             />
      53              :           </li>
      54              :           <li
      55              :             v-if="index < items.length - 1"
      56              :             data-breadcrumb-separator
      57              :             class="flex border border-transparent px-(--breadcrumb-item-margin)"
      58              :             aria-hidden="true"
      59              :           >
      60              :             <span class="scale-150">/</span>
      61              :           </li>
      62              :         </template>
      63              :       </ol>
      64              :     </nav>
      65              :   </div>
      66              : </template>
      67              : 
      68              : <script setup lang="ts">
      69              : import { cn } from '@comfyorg/tailwind-utils'
      70              : import { computed, onBeforeUnmount, onMounted, onUpdated, ref } from 'vue'
      71              : 
      72              : import SubgraphBreadcrumbItem from '@/components/breadcrumb/SubgraphBreadcrumbItem.vue'
      73              : import type { BreadcrumbItem } from '@/components/breadcrumb/SubgraphBreadcrumbItem.vue'
      74              : import WorkflowActionsDropdown from '@/components/common/WorkflowActionsDropdown.vue'
      75              : import Button from '@comfyorg/design-system/button/Button'
      76              : import { useOverflowObserver } from '@/composables/element/useOverflowObserver'
      77              : import { useTelemetry } from '@comfyorg/telemetry'
      78              : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
      79              : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
      80              : import { useCommandStore } from '@/platform/keybindings/commandStore'
      81              : import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore'
      82              : import { useSubgraphStore } from '@/stores/subgraphStore'
      83              : import { forEachSubgraphNode } from '@/utils/graphTraversalUtil'
      84              : 
      85         2355 : const MIN_WIDTH = 28
      86         2355 : const ITEM_GAP = 8
      87         2355 : const ITEM_PADDING = 8
      88         2355 : const ICON_WIDTH = 20
      89              : 
      90         2009 : const workflowStore = useWorkflowStore()
      91         2009 : const navigationStore = useSubgraphNavigationStore()
      92         2009 : const canvasStore = useCanvasStore()
      93         2009 : const breadcrumbListRef = ref<HTMLElement | null>(null)
      94         2009 : const workflowName = computed(() => workflowStore.activeWorkflow?.filename)
      95         2009 : const isBlueprint = computed(() =>
      96              :   useSubgraphStore().isSubgraphBlueprint(workflowStore.activeWorkflow)
      97              : )
      98         2009 : const collapseTabs = ref(false)
      99              : 
     100         2009 : const isInSubgraph = computed(() => navigationStore.navigationStack.length > 0)
     101              : 
     102         2009 : const home = computed(() => ({
     103              :   label: workflowName.value,
     104              :   icon: 'icon-[lucide--house]',
     105              :   key: 'root',
     106              :   isBlueprint: isBlueprint.value,
     107              :   command: () => {
     108           15 :     useTelemetry()?.trackUiButtonClicked({
     109              :       button_id: 'breadcrumb_subgraph_root_selected',
     110              :       element_group: 'breadcrumb'
     111              :     })
     112           15 :     const canvas = canvasStore.getCanvas()
     113           15 :     if (!canvas.graph) throw new TypeError('Canvas has no graph')
     114              : 
     115           15 :     canvas.setGraph(canvas.graph.rootGraph)
     116              :   }
     117              : }))
     118              : 
     119         2009 : const items = computed(() => {
     120         5492 :   const items = navigationStore.navigationStack.map<BreadcrumbItem>(
     121              :     (subgraph) => ({
     122              :       label: subgraph.name,
     123              :       key: `subgraph-${subgraph.id}`,
     124              :       command: () => {
     125            1 :         useTelemetry()?.trackUiButtonClicked({
     126              :           button_id: 'breadcrumb_subgraph_item_selected',
     127              :           element_group: 'breadcrumb'
     128              :         })
     129            1 :         const canvas = canvasStore.getCanvas()
     130            1 :         if (!canvas.graph) throw new TypeError('Canvas has no graph')
     131              : 
     132            1 :         canvas.setGraph(subgraph)
     133              :       },
     134              :       updateTitle: (title: string) => {
     135            1 :         const rootGraph = canvasStore.getCanvas().graph?.rootGraph
     136            1 :         if (!rootGraph) return
     137              : 
     138            1 :         forEachSubgraphNode(rootGraph, subgraph.id, (node) => {
     139            1 :           node.title = title
     140              :         })
     141              :       }
     142              :     })
     143              :   )
     144              : 
     145         5492 :   return [home.value, ...items]
     146              : })
     147              : 
     148         2009 : const activeItemKey = computed(() => items.value.at(-1)?.key)
     149              : 
     150         2009 : const handleBackClick = () => {
     151            3 :   void useCommandStore().execute('Comfy.Graph.ExitSubgraph')
     152              : }
     153              : 
     154         2009 : let overflowObserver: ReturnType<typeof useOverflowObserver> | undefined
     155         2009 : onMounted(() => {
     156         2009 :   const el = breadcrumbListRef.value
     157         2009 :   if (!el) return
     158              : 
     159         2009 :   overflowObserver = useOverflowObserver(el, {
     160              :     onCheck: (isOverflowing) => {
     161         3620 :       if (collapseTabs.value) {
     162            1 :         if (!isOverflowing) {
     163            1 :           const items = [
     164              :             ...el.querySelectorAll<HTMLElement>('[data-breadcrumb-item]')
     165              :           ]
     166              : 
     167            1 :           if (items.length < 3) return
     168              : 
     169            1 :           const itemsWithIcon = items.filter((item) =>
     170              :             item.querySelector('[data-active]')
     171              :           ).length
     172            1 :           const separators = el.querySelectorAll<HTMLElement>(
     173              :             '[data-breadcrumb-separator]'
     174              :           )
     175              :           const separator = separators[separators.length - 1]
     176            1 :           const separatorWidth = separator.offsetWidth
     177              : 
     178            1 :           const itemsWidth =
     179              :             (MIN_WIDTH + ITEM_PADDING + ITEM_PADDING) * items.length +
     180              :             itemsWithIcon * ICON_WIDTH
     181            1 :           const separatorsWidth = (items.length - 1) * separatorWidth
     182            1 :           const gapsWidth = (items.length - 1) * (ITEM_GAP * 2)
     183              :           const totalWidth = itemsWidth + separatorsWidth + gapsWidth
     184              :           const containerWidth = el.clientWidth
     185              : 
     186            1 :           if (totalWidth <= containerWidth) {
     187            1 :             collapseTabs.value = false
     188              :           }
     189              :         }
     190         3619 :       } else if (isOverflowing) {
     191            1 :         collapseTabs.value = true
     192              :       }
     193              :     }
     194              :   })
     195              : })
     196              : 
     197         2009 : onBeforeUnmount(() => overflowObserver?.dispose())
     198              : 
     199         2009 : onUpdated(() => {
     200         3571 :   if (!overflowObserver?.disposed.value) {
     201         3571 :     overflowObserver?.checkOverflow()
     202              :   }
     203              : })
     204              : </script>
        

Generated by: LCOV version 2.0-1