From 7493f3f9dd21eacbd481b7b8bfa345fb114749c5 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 10 Oct 2025 11:17:40 +0800 Subject: [PATCH] feat(mcp): show inline duplicate ID error and block submit in add mode - Display red hint next to title when ID exists - Disable Add/Save button and prevent submit on duplicate - Accept existing IDs via prop for real-time validation - Remove overwrite confirmation dialog on add - i18n: add duplicate-ID error strings and remove unused overwrite prompt - files: - src/components/mcp/McpFormModal.tsx - src/components/mcp/McpPanel.tsx - src/i18n/locales/en.json - src/i18n/locales/zh.json --- src/components/mcp/McpFormModal.tsx | 34 ++++++++++++++++++++++++----- src/components/mcp/McpPanel.tsx | 1 + src/i18n/locales/en.json | 1 + src/i18n/locales/zh.json | 1 + 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/components/mcp/McpFormModal.tsx b/src/components/mcp/McpFormModal.tsx index b99b16e..6b09858 100644 --- a/src/components/mcp/McpFormModal.tsx +++ b/src/components/mcp/McpFormModal.tsx @@ -11,6 +11,7 @@ interface McpFormModalProps { initialData?: McpServer; onSave: (id: string, server: McpServer) => Promise; onClose: () => void; + existingIds?: string[]; } /** @@ -38,6 +39,7 @@ const McpFormModal: React.FC = ({ initialData, onSave, onClose, + existingIds = [], }) => { const { t } = useTranslation(); const [formId, setFormId] = useState(editingId || ""); @@ -50,10 +52,19 @@ const McpFormModal: React.FC = ({ const [jsonError, setJsonError] = useState(""); const [saving, setSaving] = useState(false); const [isWizardOpen, setIsWizardOpen] = useState(false); + const [idError, setIdError] = useState(""); // 编辑模式下禁止修改 ID const isEditing = !!editingId; + const handleIdChange = (value: string) => { + setFormId(value); + if (!isEditing) { + const exists = existingIds.includes(value.trim()); + setIdError(exists ? t("mcp.error.idExists") : ""); + } + }; + const handleJsonChange = (value: string) => { setFormJson(value); @@ -104,6 +115,12 @@ const McpFormModal: React.FC = ({ return; } + // 新增模式:阻止提交重名 ID + if (!isEditing && existingIds.includes(formId.trim())) { + setIdError(t("mcp.error.idExists")); + return; + } + // 验证 JSON const currentJsonError = validateJson(formJson); setJsonError(currentJsonError); @@ -186,14 +203,21 @@ const McpFormModal: React.FC = ({
{/* ID (标题) */}
- +
+ + {!isEditing && idError && ( + + {idError} + + )} +
setFormId(e.target.value)} + onChange={(e) => handleIdChange(e.target.value)} disabled={isEditing} />
@@ -247,7 +271,7 @@ const McpFormModal: React.FC = ({