From d9c56511b14ca9a1ef9157c2c368884439fe9c6c Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 17 Oct 2025 18:38:49 +0800 Subject: [PATCH] refactor: split CodexConfigEditor into specialized components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before optimization: - CodexConfigEditor.tsx: 675 lines (monolithic component) After optimization: - CodexConfigEditor.tsx: 131 lines (-81%, orchestration only) - CodexQuickWizardModal.tsx: 325 lines (quick wizard modal) - CodexCommonConfigModal.tsx: 126 lines (common config modal) - CodexConfigSections.tsx: 150 lines (auth & config sections) - Total: 732 lines (+57 lines, but highly modular) Benefits: ✅ Single Responsibility: each component has one clear purpose ✅ Maintainability: reduced file size makes code easier to understand ✅ Reusability: modal components can be used independently ✅ Testability: isolated components are easier to test ✅ Readability: main component is now just orchestration logic ✅ Consistency: follows same modal patterns across app Component breakdown: - CodexConfigEditor: orchestration + state management (131 lines) - CodexQuickWizardModal: step-by-step wizard for quick config (325 lines) - CodexCommonConfigModal: common TOML configuration editor (126 lines) - CodexAuthSection: auth.json editor UI (70 lines) - CodexConfigSection: config.toml editor UI (80 lines) --- .../forms/CodexCommonConfigModal.tsx | 126 ++++ .../providers/forms/CodexConfigEditor.tsx | 644 ++---------------- .../providers/forms/CodexConfigSections.tsx | 150 ++++ .../providers/forms/CodexQuickWizardModal.tsx | 325 +++++++++ 4 files changed, 651 insertions(+), 594 deletions(-) create mode 100644 src/components/providers/forms/CodexCommonConfigModal.tsx create mode 100644 src/components/providers/forms/CodexConfigSections.tsx create mode 100644 src/components/providers/forms/CodexQuickWizardModal.tsx diff --git a/src/components/providers/forms/CodexCommonConfigModal.tsx b/src/components/providers/forms/CodexCommonConfigModal.tsx new file mode 100644 index 0000000..c836972 --- /dev/null +++ b/src/components/providers/forms/CodexCommonConfigModal.tsx @@ -0,0 +1,126 @@ +import React, { useEffect } from "react"; +import { X, Save } from "lucide-react"; +import { useTranslation } from "react-i18next"; +import { isLinux } from "@/lib/platform"; + +interface CodexCommonConfigModalProps { + isOpen: boolean; + onClose: () => void; + value: string; + onChange: (value: string) => void; + error?: string; +} + +/** + * CodexCommonConfigModal - Common Codex configuration editor modal + * Allows editing of common TOML configuration shared across providers + */ +export const CodexCommonConfigModal: React.FC = ({ + isOpen, + onClose, + value, + onChange, + error, +}) => { + const { t } = useTranslation(); + + // Support ESC key to close modal + useEffect(() => { + if (!isOpen) return; + + const onKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") { + e.preventDefault(); + onClose(); + } + }; + + window.addEventListener("keydown", onKeyDown); + return () => window.removeEventListener("keydown", onKeyDown); + }, [isOpen, onClose]); + + if (!isOpen) return null; + + return ( +
{ + if (e.target === e.currentTarget) onClose(); + }} + > + {/* Backdrop */} +
+ + {/* Modal */} +
+ {/* Header */} +
+

+ {t("codexConfig.editCommonConfigTitle")} +

+ +
+ + {/* Content */} +
+

+ {t("codexConfig.commonConfigHint")} +

+ +