fix(web): show used quota for unlimited API keys (#6224)

This commit is contained in:
RedwindA
2026-07-20 18:08:53 +08:00
committed by GitHub
parent 270accc322
commit 08677566f8
3 changed files with 40 additions and 11 deletions
@@ -34,6 +34,7 @@ import {
TooltipTrigger,
} from '@/components/ui/tooltip'
import { copyToClipboard } from '@/lib/copy-to-clipboard'
import { formatQuota } from '@/lib/format'
import type { ApiKey } from '../types'
import { useApiKeys } from './api-keys-provider'
@@ -141,6 +142,40 @@ export function ApiKeyCell({ apiKey }: { apiKey: ApiKey }) {
)
}
type UnlimitedQuotaBadgeProps = {
used: number
}
export function UnlimitedQuotaBadge(props: UnlimitedQuotaBadgeProps) {
const { t } = useTranslation()
const formattedUsed = formatQuota(props.used)
return (
<Popover>
<PopoverTrigger
render={
<button
type='button'
className='focus-visible:ring-ring/50 -ml-1.5 cursor-help rounded-4xl focus-visible:ring-[3px] focus-visible:outline-none'
aria-label={`${t('Unlimited')}; ${t('Used:')} ${formattedUsed}`}
/>
}
>
<StatusBadge
label={t('Unlimited')}
variant='neutral'
copyable={false}
/>
</PopoverTrigger>
<PopoverContent className='w-auto p-2' side='top'>
<span className='text-xs'>
{t('Used:')} {formattedUsed}
</span>
</PopoverContent>
</Popover>
)
}
export function ModelLimitsCell({ apiKey }: { apiKey: ApiKey }) {
const { t } = useTranslation()
@@ -41,8 +41,9 @@ import type { ApiKey } from '../types'
import { ApiKeyTimestampCell } from './api-key-timestamp-cell'
import {
ApiKeyCell,
ModelLimitsCell,
IpRestrictionsCell,
ModelLimitsCell,
UnlimitedQuotaBadge,
} from './api-keys-cells'
import { DataTableRowActions } from './data-table-row-actions'
@@ -145,14 +146,7 @@ export function useApiKeysColumns(now: number): ColumnDef<ApiKey>[] {
cell: ({ row }) => {
const apiKey = row.original
if (apiKey.unlimited_quota) {
return (
<StatusBadge
label={t('Unlimited')}
variant='neutral'
copyable={false}
className='-ml-1.5'
/>
)
return <UnlimitedQuotaBadge used={apiKey.used_quota} />
}
const used = apiKey.used_quota
@@ -53,7 +53,7 @@ import {
ERROR_MESSAGES,
} from '../constants'
import type { ApiKey } from '../types'
import { ApiKeyCell } from './api-keys-cells'
import { ApiKeyCell, UnlimitedQuotaBadge } from './api-keys-cells'
import { useApiKeysColumns } from './api-keys-columns'
import { useApiKeys } from './api-keys-provider'
import { DataTableBulkActions } from './data-table-bulk-actions'
@@ -168,7 +168,7 @@ function ApiKeysMobileList({
<div className='flex items-center justify-between gap-2 text-xs'>
<span className='text-muted-foreground'>{t('Quota')}</span>
{apiKey.unlimited_quota ? (
<span className='font-medium'>{t('Unlimited')}</span>
<UnlimitedQuotaBadge used={apiKey.used_quota} />
) : (
<span className='font-medium tabular-nums'>
{formatQuota(apiKey.remain_quota)}