Line data Source code
1 : <template>
2 21 : <div class="px-3">
3 : <TransitionGroup
4 : tag="ul"
5 : name="list-scale"
6 : class="relative m-0 list-none space-y-1 p-0"
7 : >
8 25 : <li
9 : v-for="item in missingMediaItems"
10 : :key="item.key"
11 : data-testid="missing-media-row"
12 : :aria-current="
13 : highlightedNodeIds?.has(item.nodeId) ? 'true' : undefined
14 : "
15 : class="min-w-0"
16 : >
17 : <!-- Emphasis lives on an inner element: the li is a TransitionGroup
18 : child, and the emphasis transition-property would override the
19 : list-scale move/enter/leave transitions. -->
20 : <div
21 : :class="
22 : cn(
23 : 'flex min-w-0 items-center gap-2',
24 : selectionEmphasisClass(highlightedNodeIds?.has(item.nodeId))
25 : )
26 : "
27 : >
28 : <span class="flex min-w-0 flex-1">
29 : <button
30 : type="button"
31 : class="m-0 inline max-w-full cursor-pointer appearance-none rounded-sm border-0 bg-transparent p-0 text-left text-xs/relaxed font-normal wrap-break-word text-muted-foreground outline-none hover:text-foreground focus:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-inset"
32 : @click="emit('locateNode', item.nodeId)"
33 : >
34 : {{ item.displayItemLabel }}
35 : </button>
36 : </span>
37 : <Button
38 : data-testid="missing-media-locate-button"
39 : variant="muted-textonly"
40 : size="icon-sm"
41 : class="size-8 shrink-0 hover:text-foreground focus-visible:ring-inset"
42 : :aria-label="
43 : t(
44 : 'rightSidePanel.locateNodeFor',
45 : {
46 : item: item.displayItemLabel
47 : },
48 : { escapeParameter: false }
49 : )
50 : "
51 : @click.stop="emit('locateNode', item.nodeId)"
52 : >
53 : <i aria-hidden="true" class="icon-[lucide--locate]" />
54 : </Button>
55 : </div>
56 : </li>
57 : </TransitionGroup>
58 : </div>
59 : </template>
60 :
61 : <script setup lang="ts">
62 : import { computed } from 'vue'
63 : import { useI18n } from 'vue-i18n'
64 : import { cn } from '@comfyorg/tailwind-utils'
65 :
66 : import Button from '@comfyorg/design-system/button/Button'
67 : import { selectionEmphasisClass } from '@/platform/workflowErrors/panel/selectionEmphasis'
68 : import { resolveMissingMediaItemLabel } from '@/platform/workflowErrors/errorCatalog/errorMessageResolver'
69 : import { getMissingMediaReferences } from '@/platform/workflowErrors/missingMedia/missingMediaGrouping'
70 : import type { MissingMediaGroup } from '@/platform/workflowErrors/missingMedia/types'
71 : import { app } from '@/scripts/app'
72 : import { getNodeByExecutionId } from '@/utils/graphTraversalUtil'
73 : import { resolveNodeDisplayName } from '@/utils/nodeTitleUtil'
74 :
75 : const { missingMediaGroups } = defineProps<{
76 : missingMediaGroups: MissingMediaGroup[]
77 : /** Execution node ids to emphasize (current canvas selection). */
78 : highlightedNodeIds?: Set<string>
79 : }>()
80 :
81 15 : const emit = defineEmits<{
82 : locateNode: [nodeId: string]
83 : }>()
84 :
85 15 : const { t } = useI18n()
86 :
87 : interface MissingMediaItemEntry {
88 : key: string
89 : nodeId: string
90 : displayItemLabel: string
91 : }
92 :
93 15 : const missingMediaItems = computed(() => {
94 15 : return getMissingMediaReferences(missingMediaGroups)
95 : .map(({ mediaItem, nodeRef }) => {
96 17 : const nodeId = String(nodeRef.nodeId)
97 17 : return {
98 : key: `${nodeId}:${nodeRef.widgetName}:${mediaItem.name}`,
99 : nodeId,
100 : displayItemLabel: getDisplayItemLabel(
101 : nodeId,
102 : nodeRef.nodeType ?? mediaItem.representative.nodeType,
103 : nodeRef.widgetName
104 : )
105 : }
106 : })
107 : .sort(compareMissingMediaItems)
108 : })
109 :
110 17 : function getDisplayItemLabel(
111 : nodeId: string,
112 : nodeType: string,
113 : widgetName: string
114 : ) {
115 17 : const nodeDisplayName = getNodeDisplayLabel(nodeId, '')
116 17 : return resolveMissingMediaItemLabel({
117 : nodeDisplayName,
118 : nodeType,
119 : widgetName
120 : }).displayItemLabel
121 : }
122 :
123 2 : function compareMissingMediaItems(
124 : a: MissingMediaItemEntry,
125 : b: MissingMediaItemEntry
126 : ) {
127 2 : return (
128 : a.nodeId.localeCompare(b.nodeId, undefined, { numeric: true }) ||
129 : a.displayItemLabel.localeCompare(b.displayItemLabel)
130 : )
131 : }
132 :
133 17 : function getNodeDisplayLabel(nodeId: string, fallback: string): string {
134 17 : const graph = app.rootGraph
135 17 : if (!graph) return fallback
136 17 : const node = getNodeByExecutionId(graph, nodeId)
137 17 : return resolveNodeDisplayName(node, {
138 : emptyLabel: fallback,
139 : untitledLabel: fallback
140 : })
141 : }
142 : </script>
|