fix(accounts): group account details and period controls in quota forecasts

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Zyy
2026-11-29 11:29:28 +08:00
co-authored by Codex
parent 4b8825a28f
commit c89152ce08
4 changed files with 43 additions and 67 deletions
@@ -18,15 +18,11 @@ const props = withDefaults(
size?: 'md' | 'lg'
showPlan?: boolean
showNotes?: boolean
metaPosition?: 'title' | 'secondary'
metaSize?: 'xs' | 'sm'
}>(),
{
size: 'md',
showPlan: false,
showNotes: false,
metaPosition: 'title',
metaSize: 'sm',
},
)
@@ -68,10 +64,6 @@ const avatarSizeClass = computed(() =>
: 'size-9 text-z',
)
const metaGapClass = computed(() => props.metaSize === 'xs'
? 'gap-1'
: 'gap-1.5')
const avatarToneClass = computed(() => {
const identity = props.account.id || props.account.email || displayTitle.value
return stablePresetVisualToneClass(identity)
@@ -91,25 +83,10 @@ const avatarToneClass = computed(() => {
<span class="min-w-0 truncate text-z font-heavy text-z-text" :title="identityTitle">
{{ displayTitle }}
</span>
<span
v-if="metaPosition === 'title' && (showPlan || $slots.meta)"
class="inline-flex shrink-0 items-center justify-end"
:class="metaGapClass"
>
<slot name="meta" />
<AccountPlanBadge v-if="showPlan" :upstream="account.upstream" :authentication-kind="account.authenticationKind" :plan-type="account.planType" :plan-type-display="account.planTypeDisplay" :size="metaSize" />
</span>
</div>
<div
v-if="metaPosition === 'secondary' && (showPlan || $slots.meta)"
class="mt-0.5 inline-flex min-w-0 items-center"
:class="metaGapClass"
>
<slot name="meta" />
<AccountPlanBadge v-if="showPlan" :upstream="account.upstream" :authentication-kind="account.authenticationKind" :plan-type="account.planType" :plan-type-display="account.planTypeDisplay" :size="metaSize" />
<AccountPlanBadge v-if="showPlan" class="shrink-0" :upstream="account.upstream" :authentication-kind="account.authenticationKind" :plan-type="account.planType" :plan-type-display="account.planTypeDisplay" size="sm" />
</div>
<AccountSecondaryText
v-else-if="secondaryText"
v-if="secondaryText"
:text="secondaryText"
:label="visibleNotes ? t('accounts.identity.notes') : t('accounts.identity.email')"
:class="secondaryClass"
@@ -27,7 +27,7 @@ const metrics = computed(() => [
</script>
<template>
<section v-if="source" :aria-label="t('accounts.quotaForecast.capacityForecast')" class="flex flex-col gap-5 rounded-z-card bg-z-fill-tertiary/70 p-4 [html[data-theme=light]_&]:bg-z-fill-quaternary/70">
<section v-if="source" :aria-label="t('accounts.quotaForecast.capacityForecast')" class="flex flex-col gap-5">
<div>
<div class="flex flex-wrap items-center justify-between gap-2">
<span class="text-z-xs text-z-text-secondary">{{ t('accounts.quotaForecast.usedThisCycle') }}</span>
@@ -9,32 +9,30 @@ const { t } = useI18n({ useScope: 'global' })
<template>
<div role="status" aria-busy="true">
<span class="sr-only">{{ t('accounts.quotaForecast.loadingQuotaForecast') }}</span>
<div aria-hidden="true">
<div class="flex flex-col gap-5 rounded-z-card bg-z-fill-tertiary/70 p-4 [html[data-theme=light]_&]:bg-z-fill-quaternary/70">
<div>
<div class="flex items-center justify-between gap-3">
<ZSkeleton shape="text" class="w-16" />
<ZSkeleton class="h-6 w-28" />
</div>
<ZSkeleton class="mt-2 h-8 w-28" />
<ZSkeleton class="mt-3 h-3 w-full rounded-full" />
<div class="mt-2 flex justify-between">
<ZSkeleton v-for="tick in 5" :key="tick" shape="text" class="h-2.5 w-5" />
</div>
<div aria-hidden="true" class="flex flex-col gap-5">
<div>
<div class="flex items-center justify-between gap-3">
<ZSkeleton shape="text" class="w-16" />
<ZSkeleton class="h-6 w-28" />
</div>
<ZSkeleton class="mt-2 h-8 w-28" />
<ZSkeleton class="mt-3 h-3 w-full rounded-full" />
<div class="mt-2 flex justify-between">
<ZSkeleton v-for="tick in 5" :key="tick" shape="text" class="h-2.5 w-5" />
</div>
</div>
<div class="grid gap-2">
<div class="mb-1 flex justify-between gap-3">
<ZSkeleton shape="text" class="w-20" />
<ZSkeleton shape="text" class="w-20" />
</div>
<div v-for="metric in 2" :key="metric" class="rounded-z bg-z-bg-container px-3 py-3">
<ZSkeleton shape="text" class="w-20" />
<div class="mt-3 grid grid-cols-[1fr_20px_1.2fr] items-center gap-2">
<ZSkeleton shape="text" class="w-14" />
<ZSkeleton class="size-3" />
<ZSkeleton class="h-6 w-24 justify-self-end" />
</div>
<div class="grid gap-2">
<div class="mb-1 flex justify-between gap-3">
<ZSkeleton shape="text" class="w-20" />
<ZSkeleton shape="text" class="w-20" />
</div>
<div v-for="metric in 2" :key="metric" class="rounded-z bg-z-bg-container px-3 py-3">
<ZSkeleton shape="text" class="w-20" />
<div class="mt-3 grid grid-cols-[1fr_20px_1.2fr] items-center gap-2">
<ZSkeleton shape="text" class="w-14" />
<ZSkeleton class="size-3" />
<ZSkeleton class="h-6 w-24 justify-self-end" />
</div>
</div>
</div>
@@ -7,8 +7,9 @@ import { ChartNoAxesCombined, CircleAlert, RefreshCw } from '@lucide/vue'
import { useIntervalFn, useNow } from '@vueuse/core'
import { computed, ref, toRef, useId, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import AccountPlanBadge from '@/components/account-plan-badge/index.vue'
import ProviderIconGroup from '@/components/ProviderIconGroup.vue'
import AccountIdentityCell from '../AccountIdentityCell.vue'
import { accountIdentityLabel } from '../../utils/accountIdentity'
import ForecastCapacity from './ForecastCapacity.vue'
import ForecastSkeleton from './Skeleton.vue'
import { useAccountQuotaForecast } from './useAccountQuotaForecast'
@@ -18,6 +19,13 @@ const props = defineProps<{ account: Account }>()
const emit = defineEmits<{ accountUpdated: [account: Account] }>()
const { t } = useI18n({ useScope: 'global' })
const accountLabel = computed(() => accountIdentityLabel(props.account))
const accountTitle = computed(() => {
const email = props.account.email?.trim()
return email && email !== accountLabel.value
? `${accountLabel.value}\n${email}`
: accountLabel.value
})
const open = defineModel<boolean>({ default: false })
const period = ref('weekly')
@@ -82,28 +90,21 @@ function handleExplanationKeydown(event: KeyboardEvent) {
:title="t('accounts.quotaForecast.quotaForecast')"
:description="t('accounts.quotaForecast.periodHelp')"
width="36rem"
type="info"
>
<template #icon>
<ChartNoAxesCombined class="size-5 text-z-primary-text" :stroke-width="1.75" />
</template>
<div class="grid grid-cols-1 gap-4">
<div class="flex flex-wrap items-center justify-between gap-4">
<AccountIdentityCell :account="account" show-plan meta-position="secondary" meta-size="xs" class="max-w-full">
<template #meta>
<ProviderIconGroup :provider="account.provider" size="xs" />
</template>
</AccountIdentityCell>
<ZSegmented v-model="period" :aria-label="t('accounts.quotaForecast.forecastPeriod')" :options="options" class="w-48" />
<div class="grid grid-cols-1 gap-4 rounded-z-card bg-z-fill-tertiary/70 p-4 [html[data-theme=light]_&]:bg-z-fill-quaternary/70">
<div class="flex flex-wrap items-center gap-x-4 gap-y-2.5">
<div class="flex min-w-0 flex-[1_1_12rem] items-center gap-2">
<ProviderIconGroup :provider="account.provider" class="shrink-0" />
<strong class="min-w-0 truncate text-z font-emphasis text-z-text" :title="accountTitle">{{ accountLabel }}</strong>
<AccountPlanBadge :upstream="account.upstream" :authentication-kind="account.authenticationKind" :plan-type="account.planType" :plan-type-display="account.planTypeDisplay" size="sm" class="max-w-1/2 shrink-0" />
</div>
<ZSegmented v-model="period" :aria-label="t('accounts.quotaForecast.forecastPeriod')" :options="options" size="small" class="basis-36 grow sm:grow-0" />
</div>
<div aria-live="polite" :aria-busy="loading || refreshing">
<ForecastSkeleton v-if="loading || refreshing" />
<template v-else-if="forecast">
<div v-if="unavailableReason" class="grid rounded-z-card bg-z-fill-tertiary/70 [html[data-theme=light]_&]:bg-z-fill-quaternary/70">
<ZEmpty :title="t('accounts.quotaForecast.unpredictableAtMoment')" :description="unavailableReason" :icon="ChartNoAxesCombined" surface="none" class="min-h-72 content-center" />
</div>
<ZEmpty v-if="unavailableReason" :title="t('accounts.quotaForecast.unpredictableAtMoment')" :description="unavailableReason" :icon="ChartNoAxesCombined" surface="none" class="min-h-72 content-center" />
<ForecastCapacity v-else :forecast="forecast" />
</template>
</div>