Line data Source code
1 : <template>
2 0 : <MenuSub>
3 : <MenuSubTrigger
4 : :disabled
5 : :class="cn(switcherItemClass, 'data-[state=open]:bg-accent')"
6 : data-testid="deployment-switcher-default"
7 : >
8 : <i
9 : class="icon-[lucide--users] size-3.5 text-muted-foreground"
10 : aria-hidden="true"
11 : />
12 : <span>{{ $t('deploymentSwitcher.workspaceDefault') }}</span>
13 : <span
14 : :class="
15 : cn(
16 : 'ml-auto truncate pl-4',
17 : defaultGone ? 'text-warning' : 'text-muted-foreground'
18 : )
19 : "
20 : data-testid="deployment-switcher-default-current"
21 : >
22 : {{ currentDefault }}
23 : </span>
24 : <span :class="switcherTrailingSlotClass">
25 : <i
26 : class="icon-[lucide--chevron-right] size-3.5 text-muted-foreground group-data-[state=open]:text-foreground"
27 : aria-hidden="true"
28 : />
29 : </span>
30 : </MenuSubTrigger>
31 : <MenuSubContent
32 : :side-offset="2"
33 : :align-offset="-5"
34 : :class="cn(switcherMenuWidthClass, switcherMenuMotionClass)"
35 : >
36 : <DropdownMenuLabel class="px-2 pt-1.5 pb-1 text-xs text-muted-foreground">
37 : {{ $t('deploymentSwitcher.membersStartOn') }}
38 : </DropdownMenuLabel>
39 : <DropdownMenuRadioGroup :model-value="checkedValue">
40 0 : <DeploymentSwitcherRow
41 : v-for="row in rows"
42 : :key="row.value"
43 : :value="row.value"
44 : :title="row.title"
45 : :deployment="row.name"
46 : :detail="row.detail"
47 : :tooltip="row.tooltip"
48 : :tone="row.tone"
49 : :data-testid="`default-row-${row.deploymentId ?? 'cloud'}`"
50 : @select="choose(row.deploymentId)"
51 : />
52 : </DropdownMenuRadioGroup>
53 : </MenuSubContent>
54 : </MenuSub>
55 : </template>
56 :
57 : <script setup lang="ts">
58 : import { cn } from '@comfyorg/tailwind-utils'
59 : import { storeToRefs } from 'pinia'
60 : import { DropdownMenuLabel, DropdownMenuRadioGroup } from 'reka-ui'
61 : import { computed } from 'vue'
62 : import { useI18n } from 'vue-i18n'
63 :
64 : import MenuSub from '@comfyorg/design-system/menu/MenuSub'
65 : import MenuSubContent from '@comfyorg/design-system/menu/MenuSubContent'
66 : import MenuSubTrigger from '@comfyorg/design-system/menu/MenuSubTrigger'
67 : import DeploymentSwitcherRow from '@/platform/workspace/components/DeploymentSwitcherRow.vue'
68 : import {
69 : switcherItemClass,
70 : switcherMenuMotionClass,
71 : switcherMenuWidthClass,
72 : switcherTrailingSlotClass
73 : } from '@/platform/workspace/components/deploymentSwitcherStyles'
74 : import {
75 : COMFY_CLOUD_ROW,
76 : useDeploymentLabels
77 : } from '@/platform/workspace/composables/useDeploymentLabels'
78 : import { useDeploymentPickStore } from '@/platform/workspace/stores/deploymentPickStore'
79 :
80 : const { disabled } = defineProps<{
81 : disabled: boolean
82 : }>()
83 :
84 0 : const emit = defineEmits<{
85 : setDefault: [deploymentId: string | null]
86 : }>()
87 :
88 0 : const { t } = useI18n()
89 0 : const { deployments, defaultDeploymentId, goneDefaultDeploymentId } =
90 : storeToRefs(useDeploymentPickStore())
91 0 : const { deploymentRowLabels, defaultTitle } = useDeploymentLabels()
92 :
93 0 : const rows = computed(() => [
94 : deploymentRowLabels(null),
95 : ...deployments.value.map((deployment) => deploymentRowLabels(deployment))
96 : ])
97 :
98 0 : const defaultGone = computed(() => goneDefaultDeploymentId.value !== null)
99 0 : const checkedValue = computed(() => {
100 0 : if (defaultDeploymentId.value !== null) return defaultDeploymentId.value
101 0 : return defaultGone.value ? '' : COMFY_CLOUD_ROW
102 : })
103 0 : function choose(deploymentId: string | null) {
104 0 : if ((deploymentId ?? COMFY_CLOUD_ROW) === checkedValue.value) return
105 0 : emit('setDefault', deploymentId)
106 : }
107 :
108 0 : const currentDefault = computed(() => {
109 0 : if (defaultGone.value) return t('deploymentSwitcher.defaultDeleted')
110 0 : return defaultTitle.value ?? t('deploymentSwitcher.comfyCloud')
111 : })
112 : </script>
|