LCOV - code coverage report
Current view: top level - src/platform/account/components - WorkspaceSwitcherPopover.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 0.0 % 38 0
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2            0 :   <div class="flex max-h-96 w-80 flex-col overflow-hidden rounded-lg">
       3              :     <div
       4              :       class="flex scrollbar-custom min-h-0 flex-1 flex-col"
       5              :       data-testid="workspace-switcher-list"
       6              :     >
       7              :       <div v-if="isFetchingWorkspaces" class="flex flex-col gap-2 p-2">
       8            0 :         <div
       9              :           v-for="i in 2"
      10              :           :key="i"
      11              :           class="flex h-[54px] animate-pulse items-center gap-2 rounded-sm px-2 py-4"
      12              :         >
      13              :           <div class="size-8 rounded-full bg-secondary" />
      14              :           <div class="flex flex-1 flex-col gap-1">
      15              :             <div class="h-4 w-24 rounded-sm bg-secondary" />
      16              :             <div class="h-3 w-16 rounded-sm bg-secondary" />
      17              :           </div>
      18              :         </div>
      19              :       </div>
      20              : 
      21            0 :       <div
      22              :         v-for="workspace in visibleWorkspaces"
      23              :         :key="workspace.id"
      24              :         class="border-b p-2"
      25              :       >
      26              :         <div
      27              :           :data-current="isCurrentWorkspace(workspace)"
      28              :           class="group flex h-[54px] w-full items-center gap-2 rounded-sm px-2 py-4 hover:bg-accent data-[current=true]:bg-secondary data-[current=true]:hover:bg-accent"
      29              :         >
      30              :           <button
      31              :             class="flex min-w-0 flex-1 cursor-pointer items-center gap-2 border-none bg-transparent p-0"
      32              :             :disabled="isSelectionDisabled"
      33              :             :aria-current="isCurrentWorkspace(workspace) || undefined"
      34              :             @click="handleSelectWorkspace(workspace)"
      35              :           >
      36              :             <WorkspaceProfilePic
      37              :               class="size-8 shrink-0 text-sm"
      38              :               :workspace-name="workspace.name"
      39              :               :subscription-tier="workspace.subscriptionTier"
      40              :             />
      41              :             <div class="flex min-w-0 flex-1 flex-col items-start gap-1">
      42              :               <div class="flex max-w-full min-w-0 items-center gap-1.5">
      43              :                 <span
      44              :                   :title="workspace.name"
      45              :                   class="min-w-0 truncate text-sm text-foreground"
      46              :                 >
      47              :                   {{ workspace.name }}
      48              :                 </span>
      49              :                 <span
      50              :                   v-if="resolveTierLabel(workspace)"
      51              :                   class="shrink-0 rounded-full bg-foreground px-1 py-0.5 text-2xs font-bold text-background uppercase"
      52              :                 >
      53              :                   {{ resolveTierLabel(workspace) }}
      54              :                 </span>
      55              :               </div>
      56              :               <span class="text-xs text-muted-foreground">
      57              :                 {{ getRoleLabel(workspace.role) }}
      58              :               </span>
      59              :             </div>
      60              :             <i
      61              :               v-if="isCurrentWorkspace(workspace)"
      62              :               class="icon-[lucide--check] size-3.5 text-foreground"
      63              :             />
      64              :           </button>
      65              :         </div>
      66              :       </div>
      67              :     </div>
      68              : 
      69              :     <div
      70              :       v-if="!isCloud"
      71              :       class="flex shrink-0 items-center gap-2 px-4 py-2 text-xs text-muted-foreground"
      72              :     >
      73              :       <Tooltip>
      74              :         <TooltipTrigger
      75              :           :aria-label="$t('workspaceSwitcher.scopeCaption')"
      76              :           class="flex"
      77              :         >
      78              :           <i class="icon-[lucide--info] size-3" />
      79              :         </TooltipTrigger>
      80              :         <TooltipContent side="left">{{
      81              :           $t('workspaceSwitcher.scopeTooltip')
      82              :         }}</TooltipContent>
      83              :       </Tooltip>
      84              :       <span>{{ $t('workspaceSwitcher.scopeCaption') }}</span>
      85              :     </div>
      86              : 
      87              :     <div v-if="isCloud" class="shrink-0 border-t p-2">
      88              :       <div
      89              :         :class="
      90              :           cn(
      91              :             'flex h-12 w-full items-center gap-2 rounded-sm p-2',
      92              :             canCreateWorkspace
      93              :               ? 'cursor-pointer hover:bg-accent'
      94              :               : 'cursor-default'
      95              :           )
      96              :         "
      97              :         @click="handleCreateWorkspace"
      98              :       >
      99              :         <div
     100              :           :class="
     101              :             cn(
     102              :               'flex size-8 items-center justify-center rounded-full bg-secondary',
     103              :               !canCreateWorkspace && 'opacity-50'
     104              :             )
     105              :           "
     106              :         >
     107              :           <i class="icon-[lucide--plus] size-3.5 text-muted-foreground" />
     108              :         </div>
     109              :         <div class="flex min-w-0 flex-1 flex-col text-sm text-muted-foreground">
     110              :           <span>{{ createWorkspaceLabel }}</span>
     111              :         </div>
     112              :       </div>
     113              :     </div>
     114              :   </div>
     115              : </template>
     116              : 
     117              : <script setup lang="ts">
     118              : import { storeToRefs } from 'pinia'
     119              : import { computed } from 'vue'
     120              : import { useI18n } from 'vue-i18n'
     121              : 
     122              : import Tooltip from '@comfyorg/design-system/tooltip/Tooltip'
     123              : import TooltipContent from '@comfyorg/design-system/tooltip/TooltipContent'
     124              : import TooltipTrigger from '@comfyorg/design-system/tooltip/TooltipTrigger'
     125              : import WorkspaceProfilePic from '@/platform/workspace/components/WorkspaceProfilePic.vue'
     126              : import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
     127              : import { isCloud } from '@/platform/distribution/types'
     128              : import { useCreateWorkspaceRefusal } from '@/platform/workspace/composables/useCreateWorkspaceRefusal'
     129              : import { useWorkspaceSwitch } from '@/platform/workspace/composables/useWorkspaceSwitch'
     130              : import { useWorkspaceTierLabel } from '@/platform/billing/composables/useWorkspaceTierLabel'
     131              : import { useWorkspaceBillingStateStore } from '@/platform/billing/stores/workspaceBillingStateStore'
     132              : import type { SubscriptionTier } from '@comfyorg/ingest-types'
     133              : import type {
     134              :   WorkspaceRole,
     135              :   WorkspaceType
     136              : } from '@/platform/workspace/api/workspaceApi'
     137              : import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
     138              : import { cn } from '@comfyorg/tailwind-utils'
     139              : 
     140              : interface AvailableWorkspace {
     141              :   id: string
     142              :   name: string
     143              :   type: WorkspaceType
     144              :   role: WorkspaceRole
     145              :   isSubscribed: boolean
     146              :   subscriptionPlan: string | null
     147              :   subscriptionTier: SubscriptionTier | null
     148              : }
     149              : 
     150            0 : const emit = defineEmits<{
     151              :   select: [workspace: AvailableWorkspace]
     152              :   create: []
     153              : }>()
     154              : 
     155            0 : const { t } = useI18n()
     156            0 : const { switchWorkspace } = useWorkspaceSwitch()
     157            0 : const { subscription } = useBillingContext()
     158            0 : const { formatTierName, getTierLabel } = useWorkspaceTierLabel()
     159              : 
     160            0 : const currentSubscriptionTierName = computed(() => {
     161            0 :   const tier = subscription.value?.tier
     162            0 :   if (!tier) return ''
     163            0 :   const isYearly = subscription.value?.duration === 'ANNUAL'
     164            0 :   return formatTierName(tier, isYearly)
     165              : })
     166              : 
     167            0 : const workspaceStore = useTeamWorkspaceStore()
     168            0 : const billingState = useWorkspaceBillingStateStore()
     169            0 : const {
     170              :   workspaceId,
     171              :   workspaces,
     172              :   canCreateWorkspace,
     173              :   isFetchingWorkspaces,
     174              :   isSwitching
     175              : } = storeToRefs(workspaceStore)
     176            0 : const createRefusal = useCreateWorkspaceRefusal()
     177              : 
     178            0 : const isSelectionDisabled = computed(() => !isCloud && isSwitching.value)
     179            0 : const createWorkspaceLabel = computed(() => {
     180            0 :   if (canCreateWorkspace.value) return t('workspaceSwitcher.createWorkspace')
     181            0 :   return createRefusal.value
     182              : })
     183              : 
     184            0 : const visibleWorkspaces = computed<AvailableWorkspace[]>(() =>
     185              :   isFetchingWorkspaces.value
     186              :     ? []
     187              :     : workspaces.value.map((w) => ({
     188              :         id: w.id,
     189              :         name: w.name,
     190              :         type: w.type,
     191              :         role: w.role,
     192              :         ...billingState.getSummary(w)
     193              :       }))
     194              : )
     195              : 
     196            0 : function isCurrentWorkspace(workspace: AvailableWorkspace): boolean {
     197            0 :   return workspace.id === workspaceId.value
     198              : }
     199              : 
     200            0 : function getRoleLabel(role: AvailableWorkspace['role']): string {
     201            0 :   if (role === 'owner') return t('workspaceSwitcher.roleOwner')
     202            0 :   if (role === 'member') return t('workspaceSwitcher.roleMember')
     203            0 :   return ''
     204              : }
     205              : 
     206            0 : function resolveTierLabel(workspace: AvailableWorkspace): string | null {
     207            0 :   if (workspace.type !== 'personal') return null
     208              : 
     209            0 :   if (isCurrentWorkspace(workspace)) {
     210            0 :     return currentSubscriptionTierName.value || null
     211              :   }
     212              : 
     213            0 :   return getTierLabel(workspace)
     214              : }
     215              : 
     216            0 : async function handleSelectWorkspace(workspace: AvailableWorkspace) {
     217              :   const success = await switchWorkspace(workspace.id)
     218            0 :   if (success) {
     219            0 :     emit('select', workspace)
     220              :   }
     221              : }
     222              : 
     223            0 : function handleCreateWorkspace() {
     224            0 :   if (canCreateWorkspace.value) emit('create')
     225              : }
     226              : </script>
        

Generated by: LCOV version 2.0-1