Line data Source code
1 : <template>
2 : <template v-if="notice || changeSinceBootMessage">
3 : <div
4 : v-if="notice"
5 : role="status"
6 : class="flex w-0 min-w-full items-start gap-2 px-2 py-1.5 text-xs text-muted-foreground"
7 : data-testid="deployment-switcher-notice"
8 : >
9 : <i
10 : class="mt-px icon-[lucide--triangle-alert] size-3.5 text-warning"
11 : aria-hidden="true"
12 : />
13 : <span class="text-pretty">{{ notice }}</span>
14 : </div>
15 : <template v-if="changeSinceBootMessage">
16 : <p
17 : role="status"
18 : class="m-0 w-0 min-w-full px-2 py-1.5 text-xs text-pretty text-muted-foreground"
19 : data-testid="deployment-switcher-changed"
20 : >
21 : {{ changeSinceBootMessage }}
22 : </p>
23 : <MenuItem
24 : :class="switcherItemClass"
25 : data-testid="deployment-switcher-reload"
26 : :disabled="isSwitching"
27 : @select="emit('reload')"
28 : >
29 : <i
30 : class="icon-[lucide--refresh-cw] size-3.5 text-muted-foreground"
31 : aria-hidden="true"
32 : />
33 : {{ $t('deploymentSwitcher.reload') }}
34 : </MenuItem>
35 : </template>
36 : <MenuSeparator />
37 : </template>
38 0 : <template v-for="section in listedSections" :key="section.key">
39 : <DropdownMenuLabel
40 : :id="section.labelId"
41 : :class="cn('px-2 pb-1 text-xs text-muted-foreground', section.labelClass)"
42 : >
43 : {{ section.label }}
44 : </DropdownMenuLabel>
45 : <DropdownMenuRadioGroup
46 : :model-value="pickedValue"
47 : :aria-labelledby="section.labelId"
48 : >
49 0 : <DeploymentSwitcherRow
50 : v-for="row in section.rows"
51 : :key="row.value"
52 : :value="row.value"
53 : :title="row.title"
54 : :deployment="row.name"
55 : :detail="row.detail"
56 : :tooltip="row.tooltip"
57 : :tone="row.tone"
58 : :note="row.note"
59 : :action-label="row.actionLabel"
60 : :action-icon="row.actionIcon"
61 : :problem="row.problem"
62 : :muted="row.muted"
63 : :switching="row.switching"
64 : :disabled="row.disabled"
65 : :data-focus-row="row.value"
66 : :aria-label="row.ariaLabel"
67 : :data-testid="row.testId"
68 : @select="chooseRow($event, row)"
69 : />
70 : </DropdownMenuRadioGroup>
71 : </template>
72 : <p
73 : v-if="deployments.length === 0"
74 : class="m-0 w-0 min-w-full px-2 py-1.5 text-xs text-pretty text-muted-foreground"
75 : data-testid="deployment-switcher-empty"
76 : >
77 : {{ $t('deploymentSwitcher.noDeployments') }}
78 : </p>
79 : <MenuSeparator v-else />
80 : <DeploymentSwitcherDefaultMenu
81 : v-if="canSetDefault && (deployments.length > 0 || defaultGone)"
82 : :disabled="isSwitching"
83 : @set-default="emit('setDefault', $event)"
84 : />
85 : <DeploymentSwitcherBuildAction
86 : :has-deployments="deployments.length > 0"
87 : @create-custom-deployment="emit('createCustomDeployment')"
88 : />
89 : <template v-if="deployments.length > 0">
90 : <MenuSeparator />
91 : <p
92 : class="m-0 w-0 min-w-full px-2 py-1.5 text-xs text-pretty text-muted-foreground"
93 : >
94 : {{ switchingNote }}
95 : </p>
96 : </template>
97 : </template>
98 :
99 : <script setup lang="ts">
100 : import { cn } from '@comfyorg/tailwind-utils'
101 : import { storeToRefs } from 'pinia'
102 : import { DropdownMenuLabel, DropdownMenuRadioGroup } from 'reka-ui'
103 : import { computed, useId } from 'vue'
104 : import { useI18n } from 'vue-i18n'
105 :
106 : import MenuItem from '@comfyorg/design-system/menu/MenuItem'
107 : import MenuSeparator from '@comfyorg/design-system/menu/MenuSeparator'
108 : import { getComfyPlatformBaseUrl } from '@/config/comfyApi'
109 : import { useSettingStore } from '@/platform/settings/settingStore'
110 : import DeploymentSwitcherBuildAction from '@/platform/workspace/components/DeploymentSwitcherBuildAction.vue'
111 : import DeploymentSwitcherDefaultMenu from '@/platform/workspace/components/DeploymentSwitcherDefaultMenu.vue'
112 : import DeploymentSwitcherRow from '@/platform/workspace/components/DeploymentSwitcherRow.vue'
113 : import { switcherItemClass } from '@/platform/workspace/components/deploymentSwitcherStyles'
114 : import { useDeploymentLabels } from '@/platform/workspace/composables/useDeploymentLabels'
115 : import type { DeploymentRow } from '@/platform/workspace/composables/useDeploymentRows'
116 : import { useDeploymentRows } from '@/platform/workspace/composables/useDeploymentRows'
117 : import { useKeepRowFocus } from '@/platform/workspace/composables/useKeepRowFocus'
118 : import type { DeploymentRowAction } from '@/platform/workspace/deploymentStartState'
119 : import { useDeploymentPickStore } from '@/platform/workspace/stores/deploymentPickStore'
120 : import { useDeploymentStartStore } from '@/platform/workspace/stores/deploymentStartStore'
121 :
122 0 : const STOPPED_PICK_ACTIONS = new Set<DeploymentRowAction>([
123 : 'start',
124 : 'retry',
125 : 'open'
126 : ])
127 :
128 : const { switchingTo } = defineProps<{
129 : switchingTo: string | null
130 : }>()
131 :
132 0 : const emit = defineEmits<{
133 : choose: [deploymentId: string | null]
134 : follow: [deploymentId: string]
135 : reload: []
136 : setDefault: [deploymentId: string | null]
137 : createCustomDeployment: []
138 : }>()
139 :
140 0 : const { t } = useI18n()
141 0 : const settingStore = useSettingStore()
142 0 : const {
143 : deployments,
144 : pickedDeploymentId,
145 : defaultDeploymentId,
146 : goneDefaultDeploymentId,
147 : goneDeployment,
148 : canSetDefault,
149 : isSwitching,
150 : followsWorkspace
151 : } = storeToRefs(useDeploymentPickStore())
152 0 : const { currentLabel, changeSinceBootMessage } = useDeploymentLabels()
153 0 : const { sections, pickedValue, pickedRow } = useDeploymentRows()
154 0 : const startStore = useDeploymentStartStore()
155 0 : const sectionLabelId = useId()
156 0 : useKeepRowFocus(sections)
157 :
158 0 : const platformUrl = getComfyPlatformBaseUrl()
159 :
160 0 : const listedSections = computed(() =>
161 : sections.value.map((section, index) => ({
162 : ...section,
163 : labelId: `${sectionLabelId}-${section.key}`,
164 : labelClass: index === 0 ? 'pt-1.5' : 'pt-2.5',
165 : rows: section.rows.map((row) => ({
166 : ...row,
167 : testId: `deployment-row-${row.deploymentId ?? 'cloud'}`,
168 : muted: row.action !== 'pick' && !isSwitching.value,
169 : switching: isSwitching.value && switchingTo === row.value,
170 : disabled: isSwitching.value || row.action === 'none'
171 : }))
172 : }))
173 : )
174 0 : const defaultGone = computed(() => goneDefaultDeploymentId.value !== null)
175 :
176 0 : const notice = computed(() => {
177 0 : if (goneDeployment.value === 'pick') return t('deploymentSwitcher.pickGone')
178 0 : const picked = pickedRow.value
179 0 : if (picked && STOPPED_PICK_ACTIONS.has(picked.action)) {
180 0 : return t(
181 : picked.tone === 'failed'
182 : ? 'deploymentSwitcher.pickFailed'
183 : : 'deploymentSwitcher.pickStopped',
184 : { deployment: currentLabel.value },
185 : { escapeParameter: false }
186 : )
187 : }
188 0 : if (goneDeployment.value !== 'default') return null
189 0 : return canSetDefault.value
190 : ? t('deploymentSwitcher.defaultGoneOwner')
191 : : t('deploymentSwitcher.defaultGone')
192 : })
193 :
194 0 : const switchingNote = computed(() =>
195 : settingStore.get('Comfy.Workflow.Persist')
196 : ? t('deploymentSwitcher.switchingNote')
197 : : t('deploymentSwitcher.switchingNoteWithoutDrafts')
198 : )
199 :
200 0 : function chooseRow(event: Event, row: DeploymentRow) {
201 0 : if (row.action === 'pick') {
202 0 : choose(event, row.deploymentId)
203 0 : return
204 : }
205 0 : if (row.deploymentId === null) return
206 0 : if (row.action === 'open') {
207 0 : openDeploymentPage(row.deploymentId)
208 0 : return
209 : }
210 0 : event.preventDefault()
211 0 : if (row.action === 'none') return
212 0 : void startStore.start(row.deploymentId)
213 : }
214 :
215 0 : function openDeploymentPage(deploymentId: string) {
216 0 : window.open(
217 : `${platformUrl}/profile/deployments/${encodeURIComponent(deploymentId)}`,
218 : '_blank',
219 : 'noopener,noreferrer'
220 : )
221 : }
222 :
223 0 : function choose(event: Event, deploymentId: string | null) {
224 0 : if (
225 : deploymentId !== null &&
226 : deploymentId === defaultDeploymentId.value &&
227 : !followsWorkspace.value
228 : ) {
229 0 : event.preventDefault()
230 0 : emit('follow', deploymentId)
231 0 : return
232 : }
233 0 : if (deploymentId === pickedDeploymentId.value) return
234 0 : event.preventDefault()
235 0 : emit('choose', deploymentId)
236 : }
237 : </script>
|