LCOV - code coverage report
Current view: top level - src/components/searchbox/v2 - NodeSearchFilterBar.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 96.7 % 30 29
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2         3400 :   <div class="flex min-w-0 items-center gap-2.5 pl-3">
       3              :     <button
       4              :       type="button"
       5              :       data-testid="toggle-category-sidebar"
       6              :       aria-controls="node-search-category-sidebar"
       7              :       :aria-expanded="isSidebarOpen"
       8              :       :aria-label="isSidebarOpen ? t('g.hideLeftPanel') : t('g.showLeftPanel')"
       9              :       :class="chipClass(isSidebarOpen)"
      10              :       @click="isSidebarOpen = !isSidebarOpen"
      11              :     >
      12              :       <i class="icon-[lucide--panel-left]" />
      13              :     </button>
      14              : 
      15              :     <div class="h-5 w-px shrink-0 bg-border/50" />
      16              : 
      17              :     <div
      18              :       data-testid="filter-chips-scroll"
      19              :       class="flex min-w-0 flex-1 items-center gap-2.5 overflow-x-auto pr-3"
      20              :     >
      21              :       <!-- Category filter buttons -->
      22        13578 :       <button
      23              :         v-for="btn in categoryButtons"
      24              :         :key="btn.id"
      25              :         type="button"
      26              :         :data-testid="`search-category-${btn.id}`"
      27              :         :aria-pressed="activeCategory === btn.id"
      28              :         :class="chipClass(activeCategory === btn.id)"
      29              :         @click="emit('selectCategory', btn.id)"
      30              :       >
      31              :         {{ btn.label }}
      32              :       </button>
      33              : 
      34              :       <div class="h-5 w-px shrink-0 bg-border/50" />
      35              : 
      36              :       <!-- Type filter popovers (Input / Output) -->
      37         6800 :       <NodeSearchTypeFilterPopover
      38              :         v-for="tf in typeFilters"
      39              :         :key="tf.chip.key"
      40              :         :chip="tf.chip"
      41              :         :selected-values="tf.values"
      42              :         @toggle="(v) => emit('toggleFilter', tf.chip.filter, v)"
      43              :         @clear="emit('clearFilterGroup', tf.chip.filter.id)"
      44              :         @escape-close="emit('focusSearch')"
      45              :       >
      46              :         <button
      47              :           type="button"
      48              :           :data-testid="`search-filter-${tf.chip.key}`"
      49              :           :class="chipClass(false, tf.values.length > 0)"
      50              :         >
      51              :           <span v-if="tf.values.length > 0" class="flex items-center">
      52           25 :             <span
      53              :               v-for="val in tf.values.slice(0, MAX_VISIBLE_DOTS)"
      54              :               :key="val"
      55              :               class="mx-[-2px] text-lg leading-none"
      56              :               :style="{ color: getLinkTypeColor(val) }"
      57              :               >&bull;</span
      58              :             >
      59              :           </span>
      60              :           {{ tf.chip.label }}
      61              :           <i class="icon-[lucide--chevron-down] size-3.5" />
      62              :         </button>
      63              :       </NodeSearchTypeFilterPopover>
      64              :     </div>
      65              :   </div>
      66              : </template>
      67              : 
      68              : <script setup lang="ts">
      69              : import { computed } from 'vue'
      70              : import { useI18n } from 'vue-i18n'
      71              : 
      72              : import type { FilterChip } from '@/components/searchbox/v2/filterChip'
      73              : import NodeSearchTypeFilterPopover from '@/components/searchbox/v2/NodeSearchTypeFilterPopover.vue'
      74              : import { RootCategory } from '@/components/searchbox/v2/rootCategories'
      75              : import type { RootCategoryId } from '@/components/searchbox/v2/rootCategories'
      76              : import type { ComfyNodeDefImpl } from '@/core/graph/nodeDef/ComfyNodeDefImpl'
      77              : import { useNodeDefStore } from '@/stores/nodeDefStore'
      78              : import type { FuseFilter, FuseFilterWithValue } from '@/utils/fuseUtil'
      79              : import { getLinkTypeColor } from '@/utils/litegraphUtil'
      80              : import { cn } from '@comfyorg/tailwind-utils'
      81              : 
      82              : const {
      83              :   filters = [],
      84              :   activeCategory = null,
      85              :   hasFavorites = false,
      86              :   hasEssentialNodes = false,
      87              :   hasBlueprintNodes = false,
      88              :   hasPartnerNodes = false,
      89              :   hasCustomNodes = false
      90              : } = defineProps<{
      91              :   filters?: FuseFilterWithValue<ComfyNodeDefImpl, string>[]
      92              :   activeCategory?: string | null
      93              :   hasFavorites?: boolean
      94              :   hasEssentialNodes?: boolean
      95              :   hasBlueprintNodes?: boolean
      96              :   hasPartnerNodes?: boolean
      97              :   hasCustomNodes?: boolean
      98              : }>()
      99              : 
     100          109 : const isSidebarOpen = defineModel<boolean>('isSidebarOpen', { default: true })
     101              : 
     102          109 : const emit = defineEmits<{
     103              :   toggleFilter: [filterDef: FuseFilter<ComfyNodeDefImpl, string>, value: string]
     104              :   clearFilterGroup: [filterId: string]
     105              :   focusSearch: []
     106              :   selectCategory: [category: RootCategoryId]
     107              : }>()
     108              : 
     109          109 : const { t } = useI18n()
     110          109 : const nodeDefStore = useNodeDefStore()
     111              : 
     112         2355 : const MAX_VISIBLE_DOTS = 4
     113              : 
     114          109 : const categoryButtons = computed(() => {
     115          119 :   const buttons: { id: RootCategoryId; label: string }[] = []
     116          119 :   if (hasFavorites) {
     117            1 :     buttons.push({ id: RootCategory.Favorites, label: t('g.bookmarked') })
     118              :   }
     119          119 :   if (hasBlueprintNodes) {
     120          109 :     buttons.push({ id: RootCategory.Blueprint, label: t('g.blueprints') })
     121              :   }
     122          119 :   buttons.push({ id: RootCategory.Comfy, label: t('g.comfy') })
     123          119 :   if (hasEssentialNodes) {
     124            0 :     buttons.push({ id: RootCategory.Essentials, label: t('g.essentials') })
     125              :   }
     126          119 :   if (hasPartnerNodes) {
     127          119 :     buttons.push({ id: RootCategory.PartnerNodes, label: t('g.partner') })
     128              :   }
     129          119 :   if (hasCustomNodes) {
     130          118 :     buttons.push({ id: RootCategory.Custom, label: t('g.extensions') })
     131              :   }
     132          119 :   return buttons
     133              : })
     134              : 
     135          109 : const inputChip = computed<FilterChip>(() => ({
     136              :   key: 'input',
     137              :   label: t('g.input'),
     138              :   filter: nodeDefStore.nodeSearchService.inputTypeFilter
     139              : }))
     140              : 
     141          109 : const outputChip = computed<FilterChip>(() => ({
     142              :   key: 'output',
     143              :   label: t('g.output'),
     144              :   filter: nodeDefStore.nodeSearchService.outputTypeFilter
     145              : }))
     146              : 
     147          109 : const selectedInputValues = computed(() =>
     148              :   filters.filter((f) => f.filterDef.id === 'input').map((f) => f.value)
     149              : )
     150              : 
     151          109 : const selectedOutputValues = computed(() =>
     152              :   filters.filter((f) => f.filterDef.id === 'output').map((f) => f.value)
     153              : )
     154              : 
     155          109 : const typeFilters = computed(() => [
     156              :   { chip: inputChip.value, values: selectedInputValues.value },
     157              :   { chip: outputChip.value, values: selectedOutputValues.value }
     158              : ])
     159              : 
     160        23797 : function chipClass(isActive: boolean, hasSelections = false) {
     161        23797 :   return cn(
     162              :     'flex shrink-0 cursor-pointer items-center justify-center gap-1 rounded-md border border-secondary px-3 py-1 font-inter text-sm transition-colors',
     163              :     isActive
     164              :       ? 'border-foreground bg-foreground text-background'
     165              :       : hasSelections
     166              :         ? 'border-foreground/60 bg-transparent text-foreground/60 hover:border-foreground/60 hover:text-foreground/60'
     167              :         : 'bg-transparent text-muted-foreground hover:border-foreground/60 hover:text-foreground/60'
     168              :   )
     169              : }
     170              : </script>
        

Generated by: LCOV version 2.0-1