From 92528e6a9fd4d96ba866959ffea651adb4cf7ad8 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 16 Oct 2025 16:20:45 +0800 Subject: [PATCH] refactor: migrate all MCP dialogs to shadcn/ui Dialog component Convert all MCP-related modal windows to use the unified shadcn/ui Dialog component for consistency with the rest of the application. Changes: - McpPanel: Replace custom modal with Dialog component - Update props from onClose to open/onOpenChange pattern - Use DialogContent, DialogHeader, DialogTitle components - Remove custom backdrop and close button (handled by Dialog) - McpFormModal: Migrate form modal to Dialog - Wrap entire form in Dialog component structure - Use DialogFooter for action buttons - Apply variant="mcp" to maintain green button styling - Remove unused X icon import - McpWizardModal: Convert wizard to Dialog - Replace custom modal structure with Dialog components - Use Button component with variant="mcp" for consistency - Remove unused isLinux and X icon imports - App.tsx: Update McpPanel usage - Remove conditional rendering wrapper - Pass open and onOpenChange props directly - dialog.tsx: Fix dialog overlay and content styling - Change overlay from bg-background/80 to bg-black/50 for consistency - Change content from bg-background to explicit bg-white dark:bg-gray-900 - Ensures opaque backgrounds matching MCP panel style Benefits: - Unified dialog behavior across the application - Consistent styling and animations - Better accessibility with Radix UI primitives - Reduced code duplication - Maintains MCP-specific green color scheme All dialogs now share the same base styling while preserving their unique content and functionality. --- src/App.tsx | 13 +- src/components/mcp/McpFormModal.tsx | 498 +++++++++++++------------- src/components/mcp/McpPanel.tsx | 185 +++++----- src/components/mcp/McpWizardModal.tsx | 75 ++-- src/components/ui/dialog.tsx | 4 +- 5 files changed, 372 insertions(+), 403 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index cec3f12..90e4e5b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -333,13 +333,12 @@ function App() { onImportSuccess={handleImportSuccess} /> - {isMcpOpen && ( - setIsMcpOpen(false)} - onNotify={handleNotify} - /> - )} + ); } diff --git a/src/components/mcp/McpFormModal.tsx b/src/components/mcp/McpFormModal.tsx index 36d6c76..a5bcd30 100644 --- a/src/components/mcp/McpFormModal.tsx +++ b/src/components/mcp/McpFormModal.tsx @@ -1,7 +1,6 @@ import React, { useMemo, useState, useEffect } from "react"; import { useTranslation } from "react-i18next"; import { - X, Save, AlertCircle, ChevronDown, @@ -9,6 +8,13 @@ import { AlertTriangle, } from "lucide-react"; import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogFooter, +} from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { mcpApi, type AppType } from "@/lib/api"; @@ -495,267 +501,255 @@ const McpFormModal: React.FC = ({ }; return ( -
- {/* Backdrop */} -
+ <> + !open && onClose()}> + + + {getFormTitle()} + - {/* Modal */} -
- {/* Header */} -
-

- {getFormTitle()} -

- -
- - {/* Content - Scrollable */} -
- {/* 预设选择(仅新增时展示) */} - {!isEditing && ( -
- -
- - {mcpPresets.map((preset, idx) => { - const descriptionKey = `mcp.presets.${preset.id}.description`; - return ( - - ); - })} -
-
- )} - {/* ID (标题) */} -
-
- - {!isEditing && idError && ( - - {idError} - - )} -
- handleIdChange(e.target.value)} - disabled={isEditing} - /> -
- - {/* Name */} -
- - setFormName(e.target.value)} - /> -
- - {/* 可折叠的附加信息按钮 */} -
- -
- - {/* 附加信息区域(可折叠) */} - {showMetadata && ( - <> - {/* Description (描述) */} + {/* Content - Scrollable */} +
+ {/* 预设选择(仅新增时展示) */} + {!isEditing && (
-
- - {/* Tags */} -
- - setFormTags(e.target.value)} - /> -
- - {/* Homepage */} -
- - setFormHomepage(e.target.value)} - /> -
- - {/* Docs */} -
- - setFormDocs(e.target.value)} - /> -
- - )} - - {/* 配置输入框(根据格式显示 JSON 或 TOML) */} -
-
- - {(isEditing || selectedPreset === -1) && ( - - )} -
-