LCOV - code coverage report
Current view: top level - src/components/topbar - CurrentUserButton.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 29 29
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2           27 :   <div>
       3              :     <PopoverRoot v-model:open="open">
       4              :       <PopoverTrigger as-child>
       5              :         <Button
       6              :           v-if="isLoggedIn"
       7              :           ref="buttonRef"
       8              :           class="p-1 hover:bg-transparent"
       9              :           variant="muted-textonly"
      10              :           :aria-label="$t('g.currentUser')"
      11              :           data-testid="current-user-button"
      12              :         >
      13              :           <div
      14              :             :class="
      15              :               cn(
      16              :                 'flex items-center justify-center gap-1 rounded-full hover:bg-accent',
      17              :                 compact && 'size-full'
      18              :               )
      19              :             "
      20              :           >
      21              :             <Skeleton
      22              :               v-if="showWorkspaceSkeleton"
      23              :               class="size-8 rounded-full"
      24              :             />
      25              :             <WorkspaceProfilePic
      26              :               v-else-if="showWorkspaceIcon"
      27              :               :workspace-name="workspaceName"
      28              :               :subscription-tier="activeSummary?.subscriptionTier"
      29              :               :class="compact && 'size-full'"
      30              :             />
      31              :             <UserAvatar
      32              :               v-else
      33              :               :label="$t('auth.login.userAvatar')"
      34              :               :photo-url="photoURL"
      35              :               :class="compact && 'h-full w-auto'"
      36              :             />
      37              : 
      38              :             <i v-if="showArrow" class="icon-[lucide--chevron-down] px-1" />
      39              :           </div>
      40              :         </Button>
      41              :       </PopoverTrigger>
      42              : 
      43              :       <PopoverContent
      44              :         :side
      45              :         align="end"
      46              :         :side-offset="side === 'bottom' ? undefined : 8"
      47              :         :reference="sidebarReference"
      48              :         :class="
      49              :           cn(
      50              :             'overflow-visible border-border p-0 data-[state=closed]:animate-none data-[state=open]:animate-none',
      51              :             popoverSizeClass
      52              :           )
      53              :         "
      54              :       >
      55              :         <component
      56              :           :is="workspaceMenu"
      57              :           v-if="showWorkspacePopover"
      58              :           :account-actions-only="initState !== 'ready'"
      59              :           v-bind="flags.billingNewUxEnabled ? { flyoutSide } : {}"
      60              :           @close="closePopover"
      61              :         />
      62              :         <CurrentUserPopoverLegacy v-else @close="closePopover" />
      63              :       </PopoverContent>
      64              :     </PopoverRoot>
      65              :   </div>
      66              : </template>
      67              : 
      68              : <script setup lang="ts">
      69              : import { storeToRefs } from 'pinia'
      70              : import { PopoverRoot, PopoverTrigger } from 'reka-ui'
      71              : import PopoverContent from '@comfyorg/design-system/popover/PopoverContent'
      72              : import { unrefElement } from '@vueuse/core'
      73              : import { computed, ref } from 'vue'
      74              : 
      75              : import UserAvatar from '@comfyorg/design-system/common/UserAvatar'
      76              : import Skeleton from '@comfyorg/design-system/skeleton/Skeleton'
      77              : import WorkspaceProfilePic from '@/platform/workspace/components/WorkspaceProfilePic.vue'
      78              : import Button from '@comfyorg/design-system/button/Button'
      79              : import { usePopoverViewportDismiss } from '@comfyorg/design-system/lib/popover/usePopoverViewportDismiss'
      80              : import { useCurrentUser } from '@/composables/auth/useCurrentUser'
      81              : import { isCloud } from '@/platform/distribution/types'
      82              : import { useWorkspaceBillingStateStore } from '@/platform/billing/stores/workspaceBillingStateStore'
      83              : import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
      84              : import { cn } from '@comfyorg/tailwind-utils'
      85              : 
      86              : import CurrentUserPopoverWorkspace from '@/platform/account/components/CurrentUserPopoverWorkspace.vue'
      87              : import ProfileMenuWorkspace from '@/platform/account/components/ProfileMenuWorkspace.vue'
      88              : import { useFeatureFlags } from '@/composables/useFeatureFlags'
      89              : import CurrentUserPopoverLegacy from './CurrentUserPopoverLegacy.vue'
      90              : 
      91              : const {
      92              :   showArrow = true,
      93              :   compact = false,
      94              :   side = 'bottom'
      95              : } = defineProps<{
      96              :   showArrow?: boolean
      97              :   compact?: boolean
      98              :   side?: 'bottom' | 'left' | 'right'
      99              : }>()
     100              : 
     101           16 : const { isLoggedIn, userPhotoUrl } = useCurrentUser()
     102              : 
     103           16 : const photoURL = computed<string | undefined>(
     104              :   () => userPhotoUrl.value ?? undefined
     105              : )
     106              : 
     107           16 : const {
     108              :   workspaceName: teamWorkspaceName,
     109              :   initState,
     110              :   isInPersonalWorkspace
     111              : } = storeToRefs(useTeamWorkspaceStore())
     112           16 : const { activeSummary } = storeToRefs(useWorkspaceBillingStateStore())
     113              : 
     114           16 : const showWorkspaceSkeleton = computed(
     115              :   () => isCloud && initState.value === 'loading'
     116              : )
     117           16 : const showWorkspaceIcon = computed(
     118              :   () => initState.value === 'ready' && !isInPersonalWorkspace.value
     119              : )
     120           16 : const { flags } = useFeatureFlags()
     121           16 : const workspaceMenu = computed(() =>
     122              :   flags.billingNewUxEnabled ? ProfileMenuWorkspace : CurrentUserPopoverWorkspace
     123              : )
     124           16 : const flyoutSide = computed(() => (side === 'right' ? 'right' : 'left'))
     125           16 : const showWorkspacePopover = computed(
     126              :   () => isCloud || initState.value === 'ready'
     127              : )
     128           16 : const popoverSizeClass = computed(() => {
     129           38 :   if (!showWorkspacePopover.value) return 'w-80 rounded-lg'
     130           38 :   return flags.billingNewUxEnabled
     131              :     ? 'w-72 rounded-xl'
     132              :     : 'w-fit max-w-96 min-w-80 rounded-lg'
     133              : })
     134              : 
     135           16 : const workspaceName = computed(() => {
     136            2 :   if (!showWorkspaceIcon.value) return ''
     137            2 :   return teamWorkspaceName.value
     138              : })
     139              : 
     140           16 : const open = ref(false)
     141           16 : const buttonRef = ref<InstanceType<typeof Button> | null>(null)
     142           16 : usePopoverViewportDismiss(open, () => unrefElement(buttonRef))
     143              : 
     144           16 : const sidebarReference = computed(() => {
     145           16 :   if (side === 'bottom') return undefined
     146           15 :   return {
     147              :     getBoundingClientRect: () => {
     148           12 :       const trigger = unrefElement(buttonRef)
     149           12 :       const rect = trigger?.getBoundingClientRect() ?? new DOMRect()
     150           12 :       const sidebar = trigger?.closest('nav')?.getBoundingClientRect() ?? rect
     151           12 :       return new DOMRect(sidebar.x, rect.y, sidebar.width, rect.height)
     152              :     }
     153              :   }
     154              : })
     155              : 
     156            4 : function closePopover() {
     157            4 :   open.value = false
     158              : }
     159              : </script>
        

Generated by: LCOV version 2.0-1