-
-
Notifications
You must be signed in to change notification settings - Fork 180
fix(ui): admin panel UI improvements #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ import { | |
| import { Badge } from "@/components/ui/badge"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; | ||
| import { DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; | ||
| import { DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { Label } from "@/components/ui/label"; | ||
| import { | ||
|
|
@@ -41,6 +41,8 @@ import { ApiTestButton } from "./api-test-button"; | |
| import { ProxyTestButton } from "./proxy-test-button"; | ||
| import { UrlPreview } from "./url-preview"; | ||
|
|
||
| const GROUP_TAG_MAX_TOTAL_LENGTH = 50; | ||
|
|
||
| type Mode = "create" | "edit"; | ||
|
|
||
| interface ProviderFormProps { | ||
|
|
@@ -295,6 +297,14 @@ export function ProviderForm({ | |
| return; | ||
| } | ||
|
|
||
| // group_tag 在 DB/schema 中限制为 varchar(50),并且后端按整串校验 max(50) | ||
| // 这里限制逗号拼接后的总长度,避免“UI 看似可选多标签,但保存必失败”的体验 | ||
| const serializedGroupTag = groupTag.join(","); | ||
| if (serializedGroupTag.length > GROUP_TAG_MAX_TOTAL_LENGTH) { | ||
| toast.error(t("errors.groupTagTooLong", { max: GROUP_TAG_MAX_TOTAL_LENGTH })); | ||
| return; | ||
| } | ||
|
|
||
| // 检查 failureThreshold 是否为特殊值(0 或大于 100) | ||
| const threshold = failureThreshold ?? 5; | ||
| if (threshold === 0 || threshold > 100) { | ||
|
|
@@ -306,6 +316,15 @@ export function ProviderForm({ | |
| performSubmit(); | ||
| }; | ||
|
|
||
| const handleGroupTagChange = (nextTags: string[]) => { | ||
| const serialized = nextTags.join(","); | ||
| if (serialized.length > GROUP_TAG_MAX_TOTAL_LENGTH) { | ||
| toast.error(t("errors.groupTagTooLong", { max: GROUP_TAG_MAX_TOTAL_LENGTH })); | ||
| return; | ||
| } | ||
| setGroupTag(nextTags); | ||
| }; | ||
|
|
||
| // 实际提交逻辑 | ||
| const performSubmit = () => { | ||
| // 处理模型重定向(空对象转为 null) | ||
|
|
@@ -519,6 +538,7 @@ export function ProviderForm({ | |
| <> | ||
| <DialogHeader className="flex-shrink-0"> | ||
| <DialogTitle>{isEdit ? t("title.edit") : t("title.create")}</DialogTitle> | ||
| <DialogDescription className="sr-only">{t("dialogDescription")}</DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <form onSubmit={handleSubmit} className="flex flex-col flex-1 min-h-0"> | ||
|
|
@@ -692,16 +712,16 @@ export function ProviderForm({ | |
| <TagInput | ||
| id={isEdit ? "edit-group" : "group"} | ||
| value={groupTag} | ||
| onChange={setGroupTag} | ||
| onChange={handleGroupTagChange} | ||
| placeholder={t("sections.routing.scheduleParams.group.placeholder")} | ||
| disabled={isPending} | ||
| maxTagLength={50} | ||
| maxTagLength={GROUP_TAG_MAX_TOTAL_LENGTH} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Find the provider-form.tsx file and relevant constants/components
find . -name "provider-form.tsx" -type f | head -5Repository: ding113/claude-code-hub Length of output: 140 🏁 Script executed: # Search for GROUP_TAG_MAX_TOTAL_LENGTH constant definition
rg -n "GROUP_TAG_MAX_TOTAL_LENGTH" --type=ts --type=tsx -B 2 -A 2Repository: ding113/claude-code-hub Length of output: 94 🏁 Script executed: # Find TagInput component
fd -name "*tag-input*" -type fRepository: ding113/claude-code-hub Length of output: 297 🏁 Script executed: # Search for GROUP_TAG_MAX_TOTAL_LENGTH constant definition
rg "GROUP_TAG_MAX_TOTAL_LENGTH" -B 2 -A 2Repository: ding113/claude-code-hub Length of output: 3269 🏁 Script executed: # Find TagInput component
fd "tag-input" -type fRepository: ding113/claude-code-hub Length of output: 237 🏁 Script executed: # Check the provider-form.tsx file for imports and relevant code around line 718
head -750 ./src/app/[locale]/settings/providers/_components/forms/provider-form.tsx | tail -100Repository: ding113/claude-code-hub Length of output: 5234 🏁 Script executed: # Find TagInput component
find . -name "*" -type f | xargs grep -l "export.*TagInput" | head -10Repository: ding113/claude-code-hub Length of output: 137 🏁 Script executed: # Search for TagInput prop definition or component
rg "maxTagLength" -B 5 -A 5 --max-count=20Repository: ding113/claude-code-hub Length of output: 17009 🏁 Script executed: # Look for TagInput component more broadly
rg "component.*TagInput|export.*function.*TagInput|const.*TagInput.*=" -A 20Repository: ding113/claude-code-hub Length of output: 5866 🏁 Script executed: # Get the complete TagInput component implementation
cat ./src/components/ui/tag-input.tsx | head -200Repository: ding113/claude-code-hub Length of output: 6074 🏁 Script executed: # Check how handleGroupTagChange is implemented in context
rg -B 10 "const handleGroupTagChange" src/app/[locale]/settings/providers/_components/forms/provider-form.tsxRepository: ding113/claude-code-hub Length of output: 318 纠正
这会导致语义混乱: 虽然 🤖 Prompt for AI Agents |
||
| suggestions={groupSuggestions} | ||
| onInvalidTag={(_tag, reason) => { | ||
| const messages: Record<string, string> = { | ||
| empty: tUI("emptyTag"), | ||
| duplicate: tUI("duplicateTag"), | ||
| too_long: tUI("tooLong", { max: 50 }), | ||
| too_long: tUI("tooLong", { max: GROUP_TAG_MAX_TOTAL_LENGTH }), | ||
| invalid_format: tUI("invalidFormat"), | ||
| max_tags: tUI("maxTags"), | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation for the total length of
groupTagis redundant. ThehandleGroupTagChangefunction, which is called on every change to the tags, already performs this validation and prevents the state from being updated if the length is invalid. Removing this duplicated check fromhandleSubmitwill make the code cleaner and rely on a single source of truth for this validation.