LCOV - code coverage report
Current view: top level - src/platform/account/components - WorkspaceSwitcherFlyout.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 83.3 % 24 20
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2            6 :   <div class="flex w-60 flex-col gap-1" :class="{ 'pt-1': showSearch }">
       3              :     <div v-if="showSearch" class="flex flex-col gap-2">
       4              :       <input
       5              :         v-model="searchQuery"
       6              :         type="text"
       7              :         :placeholder="$t('workspaceSwitcher.searchPlaceholder')"
       8              :         :aria-label="$t('workspaceSwitcher.searchPlaceholder')"
       9              :         class="h-6 w-full border-none bg-transparent px-1 text-sm text-foreground outline-none placeholder:text-muted-foreground"
      10              :         data-testid="workspace-switcher-search"
      11              :       />
      12              :       <div class="mx-1 mb-1 border-t" />
      13              :     </div>
      14              : 
      15              :     <div
      16              :       class="flex scrollbar-custom max-h-[294px] min-h-0 flex-col gap-2 overflow-y-auto py-1"
      17              :       data-testid="workspace-switcher-list"
      18              :     >
      19              :       <template v-if="isFetchingWorkspaces">
      20            0 :         <div
      21              :           v-for="i in 2"
      22              :           :key="i"
      23              :           class="flex animate-pulse items-center gap-3 p-1"
      24              :         >
      25              :           <div class="size-8 rounded-md bg-secondary" />
      26              :           <div class="flex flex-col">
      27              :             <div class="h-3 w-24 rounded-sm bg-secondary" />
      28              :             <div class="h-2 w-14 rounded-sm bg-secondary" />
      29              :           </div>
      30              :         </div>
      31              :       </template>
      32              : 
      33              :       <div
      34              :         v-else-if="hasLoadError"
      35              :         class="flex flex-col gap-1 px-2 py-3 text-sm"
      36              :         data-testid="workspace-switcher-error"
      37              :       >
      38              :         <span class="text-muted-foreground">{{
      39              :           $t('workspaceSwitcher.loadFailed')
      40              :         }}</span>
      41              :         <Button
      42              :           variant="textonly"
      43              :           size="unset"
      44              :           class="self-start p-0 hover:bg-transparent"
      45              :           @click="retryLoad"
      46              :         >
      47              :           {{ $t('workspaceSwitcher.tryAgain') }}
      48              :         </Button>
      49              :       </div>
      50              : 
      51              :       <p
      52              :         v-else-if="noMatchQuery"
      53              :         class="m-0 px-2 py-3 text-sm text-muted-foreground"
      54              :       >
      55              :         {{ $t('workspaceSwitcher.noResults', { query: noMatchQuery }) }}
      56              :       </p>
      57              : 
      58              :       <template v-else>
      59           18 :         <Button
      60              :           v-for="workspace in filteredWorkspaces"
      61              :           :key="workspace.id"
      62              :           variant="textonly"
      63              :           size="unset"
      64              :           class="w-full justify-start gap-3 p-1 text-left font-normal"
      65              :           :disabled="isSelectionDisabled"
      66              :           :aria-current="workspace.ariaCurrent"
      67              :           @click="handleSelectWorkspace(workspace.id)"
      68              :         >
      69              :           <WorkspaceProfilePic
      70              :             class="size-8 shrink-0 text-sm"
      71              :             :workspace-name="workspace.name"
      72              :             :subscription-tier="workspace.subscriptionTier"
      73              :           />
      74              :           <span class="flex min-w-0 flex-1 flex-col">
      75              :             <span
      76              :               :title="workspace.name"
      77              :               class="truncate text-sm font-medium text-foreground"
      78              :             >
      79              :               {{ workspace.name }}
      80              :             </span>
      81              :             <span
      82              :               v-if="workspace.planLine"
      83              :               class="text-2xs leading-none font-medium text-muted-foreground uppercase"
      84              :               data-testid="workspace-row-plan-line"
      85              :             >
      86              :               {{ workspace.planLine }}
      87              :             </span>
      88              :           </span>
      89              :           <i
      90              :             v-if="workspace.ariaCurrent"
      91              :             class="icon-[lucide--check] text-foreground"
      92              :           />
      93              :         </Button>
      94              :       </template>
      95              :     </div>
      96              : 
      97              :     <WorkspaceSwitcherFlyoutFooter @create="emit('create')" />
      98              :   </div>
      99              : </template>
     100              : 
     101              : <script setup lang="ts">
     102              : import { storeToRefs } from 'pinia'
     103              : import { computed, ref } from 'vue'
     104              : import { useI18n } from 'vue-i18n'
     105              : 
     106              : import Button from '@comfyorg/design-system/button/Button'
     107              : import { reportError } from '@comfyorg/telemetry/reportError'
     108              : import WorkspaceSwitcherFlyoutFooter from '@/platform/account/components/WorkspaceSwitcherFlyoutFooter.vue'
     109              : import { profileMenuPlanLabel } from '@/platform/account/components/profileMenuPlanLine'
     110              : import { useWorkspaceBillingStateStore } from '@/platform/billing/stores/workspaceBillingStateStore'
     111              : import { isCloud } from '@/platform/distribution/types'
     112              : import WorkspaceProfilePic from '@/platform/workspace/components/WorkspaceProfilePic.vue'
     113              : import { useWorkspaceSwitch } from '@/platform/workspace/composables/useWorkspaceSwitch'
     114              : import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
     115              : 
     116         2355 : const SEARCH_THRESHOLD = 6
     117              : 
     118            2 : const emit = defineEmits<{
     119              :   select: []
     120              :   create: []
     121              : }>()
     122              : 
     123            2 : const { t } = useI18n()
     124            2 : const { switchWorkspace } = useWorkspaceSwitch()
     125            2 : const workspaceStore = useTeamWorkspaceStore()
     126            2 : const billingState = useWorkspaceBillingStateStore()
     127            2 : const {
     128              :   workspaceId,
     129              :   workspaces,
     130              :   isFetchingWorkspaces,
     131              :   isSwitching,
     132              :   initState
     133              : } = storeToRefs(workspaceStore)
     134              : 
     135            2 : const isSelectionDisabled = computed(() => !isCloud && isSwitching.value)
     136              : 
     137            2 : const visibleWorkspaces = computed(() =>
     138              :   isFetchingWorkspaces.value
     139              :     ? []
     140              :     : workspaces.value.map((w) => ({
     141              :         id: w.id,
     142              :         name: w.name,
     143              :         subscriptionTier: billingState.getSummary(w).subscriptionTier,
     144              :         planLine: profileMenuPlanLabel(w.plan_summary, t),
     145              :         ariaCurrent: w.id === workspaceId.value ? ('true' as const) : undefined
     146              :       }))
     147              : )
     148              : 
     149            2 : const searchQuery = ref('')
     150            2 : const showSearch = computed(
     151              :   () => visibleWorkspaces.value.length >= SEARCH_THRESHOLD
     152              : )
     153            2 : const filteredWorkspaces = computed(() => {
     154            4 :   const query = showSearch.value ? searchQuery.value.trim().toLowerCase() : ''
     155            4 :   if (!query) return visibleWorkspaces.value
     156            0 :   return visibleWorkspaces.value.filter((w) =>
     157              :     w.name.toLowerCase().includes(query)
     158              :   )
     159              : })
     160              : 
     161            2 : const noMatchQuery = computed(() =>
     162              :   filteredWorkspaces.value.length === 0 ? searchQuery.value.trim() : ''
     163              : )
     164              : 
     165            2 : const hasLoadError = computed(() => initState.value === 'error')
     166              : 
     167            0 : function retryLoad() {
     168            0 :   workspaceStore.initialize().catch((error: unknown) =>
     169              :     reportError(error, {
     170              :       errorType: 'error_retrying_workspace_list',
     171              :       surface: 'workspace'
     172              :     })
     173              :   )
     174              : }
     175              : 
     176            2 : async function handleSelectWorkspace(id: string) {
     177            2 :   if (await switchWorkspace(id)) emit('select')
     178              : }
     179              : </script>
        

Generated by: LCOV version 2.0-1