Skip to content

fix: 修复密钥表单供应商分组选择时 default 不自动移除的问题#568

Merged
ding113 merged 2 commits intoding113:devfrom
NieiR:fix/key-form-provider-group
Jan 8, 2026
Merged

fix: 修复密钥表单供应商分组选择时 default 不自动移除的问题#568
ding113 merged 2 commits intoding113:devfrom
NieiR:fix/key-form-provider-group

Conversation

@NieiR
Copy link
Contributor

@NieiR NieiR commented Jan 8, 2026

Greptile Overview

Greptile Summary

Restored missing auto-removal logic for 'default' provider group when selecting multiple groups in key forms, and fixed input focus ring clipping issue.

  • Added handleProviderGroupChange callback in both add-key-form.tsx and edit-key-form.tsx to automatically remove the 'default' group when users select multiple provider groups
  • Logic matches the original implementation in key-edit-section.tsx (lines 313-329)
  • Fixed focus ring visual issue in form-layout.tsx by adjusting horizontal padding to prevent overflow-y-auto from clipping the left border
  • All changes restore behavior that was inadvertently removed during PR refactor: 拆分 unified-edit-dialog 为专用对话框组件 #539 refactoring

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • The changes correctly restore missing functionality by implementing identical logic from the original codebase, use appropriate React patterns (useCallback with proper dependencies), and include a minor CSS fix that improves UI quality without affecting functionality
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx 5/5 Added handleProviderGroupChange callback to automatically remove 'default' when multiple groups are selected
src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx 5/5 Added handleProviderGroupChange callback to automatically remove 'default' when multiple groups are selected
src/components/form/form-layout.tsx 5/5 Changed padding from pr-2 -mr-2 to px-1 -mx-1 to fix focus ring clipping issue

Sequence Diagram

sequenceDiagram
    participant User
    participant TagInputField
    participant Form as Add/EditKeyForm
    participant Handler as handleProviderGroupChange
    
    User->>TagInputField: Select provider groups
    TagInputField->>Handler: onChange(newValue)
    Handler->>Handler: Split & trim groups
    alt Multiple groups & includes "default"
        Handler->>Handler: Filter out "default"
        Handler->>Form: setValue("providerGroup", withoutDefault)
    else Single group or no "default"
        Handler->>Form: setValue("providerGroup", newValue)
    end
    Form->>TagInputField: Update displayed value
Loading

- 在 add-key-form.tsx 和 edit-key-form.tsx 中添加 handleProviderGroupChange
- 当选择多个分组时自动移除 default 分组
- 修复 DialogFormLayout 中输入框 focus ring 左边被裁剪的样式问题

此问题由 PR ding113#539 重构引入,原有逻辑在 key-edit-section.tsx 中存在但未迁移到新表单组件
@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

在 add-key 与 edit-key 表单中新增 handleProviderGroupChange 以在选择多个提供者组时自动移除 DEFAULT 条目;调整 DialogFormLayout 的水平间距类;移除未使用的 Tooltip 导入;更新 biome.json 的 schema 版本。

Changes

内聚体 / 文件 变更摘要
表单提供者组逻辑
src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx, src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx
添加 useCallback 导入并新增 handleProviderGroupChange:解析逗号分隔值、修剪非空项;当选择多于1个组且包含 DEFAULT 时移除 DEFAULT,并用该函数替换原有 providerGrouponChange 处理器。
表单布局间距
src/components/form/form-layout.tsx
更新 DialogFormLayout 容器的类名,从 "flex-1 overflow-y-auto min-h-0 py-4 pr-2 -mr-2" 改为 "flex-1 overflow-y-auto min-h-0 py-4 px-1 -mx-1"(调整水平内/外边距)。
导入清理
src/app/[locale]/dashboard/sessions/[sessionId]/messages/_components/session-stats.tsx
移除未使用的 Tooltip 相关导入条目(纯导入清理)。
工具配置
biome.json
$schema 从 Biome 2.3.10 更新为 2.3.11。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PR 标题使用中文描述,直接指向主要改动内容(修复密钥表单供应商分组选择时 default 不自动移除的问题),与 changeset 内容高度相关且准确反映了核心问题。
Description check ✅ Passed PR 描述详细且与 changeset 完全相关,包含了对所有主要改动的说明、实现原理、修复的具体问题以及影响范围的说明。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

📥 Commits

Reviewing files that changed from the base of the PR and between e7a326a and 302b158.

📒 Files selected for processing (2)
  • biome.json
  • src/app/[locale]/dashboard/sessions/[sessionId]/messages/_components/session-stats.tsx
💤 Files with no reviewable changes (1)
  • src/app/[locale]/dashboard/sessions/[sessionId]/messages/_components/session-stats.tsx
✅ Files skipped from review due to trivial changes (1)
  • biome.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: 🌐 API Tests
  • GitHub Check: Docker Build Test

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @NieiR, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求主要修复了两个用户界面问题。首先,它恢复了密钥新增和编辑表单中供应商分组选择的预期行为,确保在选择多个分组时 "default" 分组能够被正确移除,纠正了先前重构引入的回归。其次,它调整了表单布局的样式,以解决输入框聚焦时焦点环被裁剪的视觉缺陷。这些修复旨在提升用户体验和界面一致性,且不涉及 API 变更或破坏性影响。

Highlights

  • 修复密钥表单供应商分组选择逻辑: 恢复了在新增/编辑密钥时,当选择多个供应商分组(包含 "default")时,自动移除 "default" 分组的逻辑。此问题是 PR refactor: 拆分 unified-edit-dialog 为专用对话框组件 #539 重构后引入的回归。
  • 修复输入框焦点环样式: 解决了输入框聚焦时,左侧焦点环因 "overflow-y-auto" 样式裁剪导致显示不完整的问题。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added size/XS Extra Small PR (< 50 lines) bug Something isn't working area:UI labels Jan 8, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 修复了在密钥表单中选择供应商分组时 default 分组不会被自动移除的 bug,同时修正了一个输入框 focus 时的样式问题。整体来看,代码变更清晰地解决了所述问题。

我注意到在 add-key-form.tsxedit-key-form.tsx 中引入了重复的逻辑。我已在相关代码处提出建议,通过提取一个共享的工具函数来优化代码结构,以提高可维护性和复用性。

除此之外,其他修改看起来没有问题。

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx (1)

141-156: 逻辑正确,但存在代码重复

handleProviderGroupChange 函数的实现与 add-key-form.tsx(lines 122-137)完全相同,正确实现了自动移除 default 的逻辑。

建议:提取为共享工具函数

考虑将该函数提取到共享工具文件中(例如 @/lib/utils/provider-group.ts),以减少代码重复并便于后续维护。

♻️ 可选的重构方案

创建新文件 src/lib/utils/provider-group.ts:

import { PROVIDER_GROUP } from "@/lib/constants/provider.constants";

/**
 * 规范化供应商分组值,当有多个分组时自动移除 default
 */
export function normalizeProviderGroup(value: string): string {
  const groups = value
    .split(",")
    .map((g) => g.trim())
    .filter(Boolean);
    
  if (groups.length > 1 && groups.includes(PROVIDER_GROUP.DEFAULT)) {
    const withoutDefault = groups.filter((g) => g !== PROVIDER_GROUP.DEFAULT);
    return withoutDefault.join(",");
  }
  
  return value;
}

然后在两个表单文件中使用:

-  const handleProviderGroupChange = useCallback(
-    (newValue: string) => {
-      const groups = newValue
-        .split(",")
-        .map((g) => g.trim())
-        .filter(Boolean);
-      if (groups.length > 1 && groups.includes(PROVIDER_GROUP.DEFAULT)) {
-        const withoutDefault = groups.filter((g) => g !== PROVIDER_GROUP.DEFAULT);
-        form.setValue("providerGroup", withoutDefault.join(","));
-      } else {
-        form.setValue("providerGroup", newValue);
-      }
-    },
-    [form]
-  );
+  const handleProviderGroupChange = useCallback(
+    (newValue: string) => {
+      form.setValue("providerGroup", normalizeProviderGroup(newValue));
+    },
+    [form]
+  );
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

📥 Commits

Reviewing files that changed from the base of the PR and between cf6caa1 and e7a326a.

📒 Files selected for processing (3)
  • src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx
  • src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx
  • src/components/form/form-layout.tsx
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

No emoji characters in any code, comments, or string literals

Files:

  • src/components/form/form-layout.tsx
  • src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx
  • src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx
**/*.{ts,tsx,jsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,jsx,js}: All user-facing strings must use i18n (5 languages supported: zh-CN, en, ja, ko, de). Never hardcode display text
Use path alias @/ to map to ./src/
Use Biome for code formatting with configuration: double quotes, trailing commas, 2-space indent, 100 character line width
Prefer named exports over default exports
Use next-intl for internationalization
Use Next.js 16 App Router with Hono for API routes

Files:

  • src/components/form/form-layout.tsx
  • src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx
  • src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use React 19, shadcn/ui, Tailwind CSS, and Recharts for the UI layer

Files:

  • src/components/form/form-layout.tsx
  • src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx
  • src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx
🧠 Learnings (1)
📚 Learning: 2026-01-05T03:02:06.594Z
Learnt from: NieiR
Repo: ding113/claude-code-hub PR: 539
File: src/app/[locale]/dashboard/_components/user/user-key-table-row.tsx:66-66
Timestamp: 2026-01-05T03:02:06.594Z
Learning: In the claude-code-hub project, the translations.actions.addKey field in UserKeyTableRowProps is defined as optional for backward compatibility, but all actual callers in the codebase provide the complete translations object. The field has been added to all 5 locale files (messages/{locale}/dashboard.json).

Applied to files:

  • src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx
🧬 Code graph analysis (2)
src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx (1)
src/lib/constants/provider.constants.ts (1)
  • PROVIDER_GROUP (25-30)
src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx (1)
src/lib/constants/provider.constants.ts (1)
  • PROVIDER_GROUP (25-30)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: pr-review
  • GitHub Check: pr-description
  • GitHub Check: 🌐 API Tests
  • GitHub Check: pr-label
  • GitHub Check: Docker Build Test
🔇 Additional comments (4)
src/components/form/form-layout.tsx (1)

59-59: 修复正确,改善了输入框焦点环的显示效果

将右侧单向的内边距/外边距(pr-2 -mr-2)改为对称的水平内边距/外边距(px-1 -mx-1),有效解决了在 overflow-y-auto 容器中输入框获得焦点时左侧边框被裁剪的问题。

src/app/[locale]/dashboard/_components/user/forms/add-key-form.tsx (2)

122-137: 逻辑正确,恢复了供应商分组的自动规范化功能

handleProviderGroupChange 函数正确实现了以下逻辑:

  • 当用户选择多个分组且包含 default 时,自动移除 default
  • 单独的 default 分组保持不变
  • 使用 useCallback 进行优化,依赖项正确

该实现与 PR #539 之前的行为一致,符合预期。


213-213: 正确应用了新的处理函数

providerGroup 字段的 onChange 处理器更换为 handleProviderGroupChange,确保用户选择分组时自动触发规范化逻辑。

src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx (1)

236-236: 正确应用了新的处理函数

add-key-form.tsx 保持一致,正确将 onChange 处理器更换为 handleProviderGroupChange

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

This PR successfully restores the missing provider group auto-removal logic that was inadvertently omitted during the refactoring in PR #539. The implementation is clean and consistent with the existing pattern in key-edit-section.tsx.

PR Size: XS

  • Lines changed: 44 (39 additions, 5 deletions)
  • Files changed: 3

Issues Found

No significant issues identified in this PR.

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate (manual testing performed)
  • Code clarity - Good

Analysis Summary

Positive aspects:

  1. Consistent Implementation: The handleProviderGroupChange logic in both files matches the reference implementation in key-edit-section.tsx:313-329, ensuring behavioral consistency across the codebase.

  2. Proper Hook Usage: Correctly uses useCallback with [form] dependency, preventing unnecessary re-renders.

  3. Clear Business Logic: The auto-removal logic is straightforward:

    • When multiple groups are selected AND "default" is included → remove "default"
    • Otherwise → keep the value as-is
  4. UI Fix: The form-layout.tsx change (pr-2 -mr-2px-1 -mx-1) addresses a legitimate focus ring clipping issue without affecting functionality.

Validation performed:

  • Verified the logic matches the existing pattern in key-edit-section.tsx
  • Confirmed PROVIDER_GROUP.DEFAULT constant usage is consistent with codebase conventions
  • Checked that the change only affects NEW code (lines added in the diff)
  • Validated that no error handling is needed (form state management handles validation)

No issues to report because:

  • The implementation is a direct restoration of previously working code
  • No security vulnerabilities introduced
  • No silent failures or error swallowing
  • Type safety is maintained (TypeScript will catch issues)
  • No test coverage gaps for this UI interaction logic
  • Code is clear and maintainable

Automated review by Claude AI

- Update biome.json schema version from 2.3.10 to 2.3.11
- Remove unused Tooltip import from session-stats.tsx
@ding113 ding113 merged commit 5b8ba79 into ding113:dev Jan 8, 2026
7 of 8 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Claude Code Hub Roadmap Jan 8, 2026
@github-actions github-actions bot mentioned this pull request Jan 10, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI bug Something isn't working size/XS Extra Small PR (< 50 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants