Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/views/system/chat-management/users/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const chatUserQuery = computed<Dict<unknown>>(() => ({
}))

function formatQuotaUsage(tokenQuota?: ChatUser['token_quota']) {
if (!tokenQuota) return '-'
if (!tokenQuota) return '0 / 不限'
const used = formatTokenNumber(tokenQuota.used_tokens)
if (tokenQuota.quota_type === QUOTA_TYPE.UNLIMITED) return `${used} / 不限`
return `${used} / ${formatTokenNumber(tokenQuota.token_limit)}`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue is semantic, not syntactic:

  • Missing quota data is being treated as “0 / 不限” (0 / Unlimited). !tokenQuota can mean the data is still loading, failed to load, or is genuinely absent. Rendering “0 / 不限” can falsely tell users they have unlimited quota and hide an error/loading state. Safer to keep '-', use a loading/error placeholder, or only return '0 / 不限' if the business rule explicitly defines “no quota object” as “zero usage, unlimited.”

  • Hardcoded localized text: '不限' is repeated. If the app supports i18n, use a translation key/constant instead. At minimum, extract a constant to avoid duplication.

  • Add tests for:

    • tokenQuota undefined
    • unlimited quota with used_tokens > 0
    • limited quota
    • possibly null at runtime if the API can return it

Suggested safer version:

const UNLIMITED_LABEL = '不限'

function formatQuotaUsage(tokenQuota?: ChatUser['token_quota']) {
  if (!tokenQuota) return '-' // or a loading/error placeholder

  const used = formatTokenNumber(tokenQuota.used_tokens)

  if (tokenQuota.quota_type === QUOTA_TYPE.UNLIMITED) {
    return `${used} / ${UNLIMITED_LABEL}`
  }

  return `${used} / ${formatTokenNumber(tokenQuota.token_limit)}`
}

If the new behavior is intentional, add a comment explaining that missing quota data means “0 used / unlimited,” and ensure callers only pass undefined in that specific case rather than during loading or errors.

Expand Down
Loading