Line data Source code
1 : <template>
2 : <TextTooltip :text="tooltipText" side="left">
3 : <MenuRadioItem
4 : v-bind="$attrs"
5 : :value
6 : :disabled
7 : :aria-describedby="describedBy"
8 : :class="
9 : cn(
10 : switcherItemClass,
11 : 'aria-checked:bg-secondary aria-checked:data-highlighted:bg-accent',
12 : muted && 'data-disabled:opacity-100'
13 : )
14 : "
15 : @select="emit('select', $event)"
16 : >
17 : <DeploymentStatusIcon
18 : :tone
19 : icon-class="size-3.5 text-muted-foreground"
20 : ring-class="ring-1 ring-background group-data-highlighted:ring-accent group-aria-checked:ring-secondary group-aria-checked:group-data-highlighted:ring-accent"
21 : />
22 : <span
23 : ref="titleText"
24 : :class="
25 : cn(
26 : 'min-w-0 flex-1 truncate',
27 : muted ? 'text-muted-foreground' : 'text-foreground'
28 : )
29 : "
30 : >
31 : {{ title }}
32 : </span>
33 : <span
34 : ref="deploymentText"
35 : class="w-16 shrink-0 truncate text-muted-foreground"
36 : >
37 : {{ deployment }}
38 : </span>
39 : <span v-if="showsAction" class="flex min-w-14 shrink-0">
40 : <span
41 : class="flex h-6 items-center rounded-md bg-accent px-2.5 whitespace-nowrap text-foreground group-data-highlighted:bg-muted"
42 : aria-hidden="true"
43 : >
44 : {{ actionLabel }}
45 : <i
46 : v-if="actionIcon"
47 : :class="cn(actionIcon, 'ml-1 size-3')"
48 : aria-hidden="true"
49 : />
50 : </span>
51 : </span>
52 : <span v-else ref="detailCell" :class="detailClass">
53 : {{ switching ? $t('deploymentSwitcher.switching') : detail }}
54 : </span>
55 : <span :class="switcherTrailingSlotClass">
56 : <i
57 : v-if="switching"
58 : class="icon-[lucide--loader-circle] size-3.5 animate-spin text-muted-foreground"
59 : aria-hidden="true"
60 : />
61 : <DropdownMenuItemIndicator v-else class="flex">
62 : <i
63 : class="icon-[lucide--check] size-3.5 text-foreground"
64 : aria-hidden="true"
65 : />
66 : </DropdownMenuItemIndicator>
67 : </span>
68 : <span v-if="note" :id="noteId" hidden>{{ note }}</span>
69 : </MenuRadioItem>
70 : </TextTooltip>
71 : <div
72 : v-if="problem"
73 : :id="problemId"
74 : role="status"
75 : class="w-0 min-w-full pr-2 pb-2 pl-7.5 text-xs text-pretty"
76 : data-testid="deployment-row-problem"
77 : >
78 : <p class="m-0 text-warning">
79 : {{ problem.summary }}
80 : <template v-if="problem.message">{{ problem.message }}</template>
81 : </p>
82 : <p class="m-0 mt-0.5 text-muted-foreground">{{ problem.fix }}</p>
83 : </div>
84 : </template>
85 :
86 : <script setup lang="ts">
87 : import { cn } from '@comfyorg/tailwind-utils'
88 : import { useResizeObserver } from '@vueuse/core'
89 : import { DropdownMenuItemIndicator } from 'reka-ui'
90 : import { computed, onMounted, onUpdated, ref, useId, useTemplateRef } from 'vue'
91 :
92 : import MenuRadioItem from '@comfyorg/design-system/menu/MenuRadioItem'
93 : import TextTooltip from '@comfyorg/design-system/tooltip/TextTooltip'
94 : import DeploymentStatusIcon from '@/platform/workspace/components/DeploymentStatusIcon.vue'
95 : import {
96 : switcherItemClass,
97 : switcherTrailingSlotClass
98 : } from '@/platform/workspace/components/deploymentSwitcherStyles'
99 : import type { DeploymentStatusTone } from '@/platform/workspace/composables/useDeploymentLabels'
100 :
101 : defineOptions({ inheritAttrs: false })
102 :
103 : const {
104 : value,
105 : title,
106 : deployment = null,
107 : detail = null,
108 : tooltip,
109 : tone,
110 : note = null,
111 : actionLabel = null,
112 : actionIcon = null,
113 : problem = null,
114 : muted = false,
115 : switching = false,
116 : disabled = false
117 : } = defineProps<{
118 : value: string
119 : title: string
120 : deployment?: string | null
121 : detail?: string | null
122 : tooltip: string
123 : /** The deployment's status; leave it out for Comfy Cloud. */
124 : tone?: DeploymentStatusTone
125 : note?: string | null
126 : actionLabel?: string | null
127 : actionIcon?: string | null
128 : problem?: { summary: string; message: string | null; fix: string } | null
129 : muted?: boolean
130 : switching?: boolean
131 : disabled?: boolean
132 : }>()
133 :
134 0 : const emit = defineEmits<{
135 : select: [event: Event]
136 : }>()
137 :
138 0 : const noteId = useId()
139 0 : const problemId = useId()
140 0 : const describedBy = computed(
141 : () =>
142 : [note && noteId, problem && problemId].filter(Boolean).join(' ') ||
143 : undefined
144 : )
145 :
146 0 : const showsAction = computed(() => actionLabel !== null && !switching)
147 0 : const detailClass = computed(() =>
148 : cn(
149 : 'w-14 shrink-0 truncate tabular-nums',
150 : tone === 'failed' && !switching ? 'text-warning' : 'text-muted-foreground'
151 : )
152 : )
153 :
154 0 : const titleText = useTemplateRef<HTMLElement>('titleText')
155 0 : const deploymentText = useTemplateRef<HTMLElement>('deploymentText')
156 0 : const detailCell = useTemplateRef<HTMLElement>('detailCell')
157 0 : const isTruncated = ref(false)
158 :
159 0 : const tooltipText = computed(() => {
160 0 : if (note) return note
161 0 : return isTruncated.value ? tooltip : ''
162 : })
163 :
164 0 : function overflows(element: HTMLElement | null): boolean {
165 0 : return element !== null && element.scrollWidth > element.clientWidth
166 : }
167 :
168 0 : function measureTruncation() {
169 0 : isTruncated.value = [titleText, deploymentText, detailCell].some((cell) =>
170 : overflows(cell.value)
171 : )
172 : }
173 :
174 0 : onMounted(measureTruncation)
175 0 : onUpdated(measureTruncation)
176 0 : useResizeObserver([titleText, deploymentText, detailCell], measureTruncation)
177 : </script>
|