mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-27 08:14:33 +08:00
b3b3c0732a
Add real-time merge preview functionality to all config editor components (Claude, Codex, Gemini) that shows the final merged configuration when common config is enabled. UI changes: - Add finalConfig/finalEnv prop to display merged result - Add toggle button to show/hide merge preview (Eye/EyeOff icons) - Auto-show preview when common config is enabled - Display custom config editor with label when preview is visible - Show read-only merged preview below custom config - Add visual indicators: "只读" badge, green hint text The preview helps users understand how their custom configuration combines with the shared common config template before saving.
101 lines
2.4 KiB
TypeScript
101 lines
2.4 KiB
TypeScript
import React, { useState, useEffect } from "react";
|
|
import { CodexAuthSection, CodexConfigSection } from "./CodexConfigSections";
|
|
import { CodexCommonConfigModal } from "./CodexCommonConfigModal";
|
|
|
|
interface CodexConfigEditorProps {
|
|
authValue: string;
|
|
|
|
configValue: string;
|
|
|
|
onAuthChange: (value: string) => void;
|
|
|
|
onConfigChange: (value: string) => void;
|
|
|
|
onAuthBlur?: () => void;
|
|
|
|
useCommonConfig: boolean;
|
|
|
|
onCommonConfigToggle: (checked: boolean) => void;
|
|
|
|
commonConfigSnippet: string;
|
|
|
|
onCommonConfigSnippetChange: (value: string) => void;
|
|
|
|
commonConfigError: string;
|
|
|
|
authError: string;
|
|
|
|
configError: string; // config.toml 错误提示
|
|
|
|
onExtract?: () => void;
|
|
|
|
isExtracting?: boolean;
|
|
|
|
/** 最终合并后的配置(只读预览) */
|
|
finalConfig?: string;
|
|
}
|
|
|
|
const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
|
authValue,
|
|
configValue,
|
|
onAuthChange,
|
|
onConfigChange,
|
|
onAuthBlur,
|
|
useCommonConfig,
|
|
onCommonConfigToggle,
|
|
commonConfigSnippet,
|
|
onCommonConfigSnippetChange,
|
|
commonConfigError,
|
|
authError,
|
|
configError,
|
|
onExtract,
|
|
isExtracting,
|
|
finalConfig,
|
|
}) => {
|
|
const [isCommonConfigModalOpen, setIsCommonConfigModalOpen] = useState(false);
|
|
|
|
// Auto-open common config modal if there's an error
|
|
useEffect(() => {
|
|
if (commonConfigError && !isCommonConfigModalOpen) {
|
|
setIsCommonConfigModalOpen(true);
|
|
}
|
|
}, [commonConfigError, isCommonConfigModalOpen]);
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
{/* Auth JSON Section */}
|
|
<CodexAuthSection
|
|
value={authValue}
|
|
onChange={onAuthChange}
|
|
onBlur={onAuthBlur}
|
|
error={authError}
|
|
/>
|
|
|
|
{/* Config TOML Section */}
|
|
<CodexConfigSection
|
|
value={configValue}
|
|
onChange={onConfigChange}
|
|
useCommonConfig={useCommonConfig}
|
|
onCommonConfigToggle={onCommonConfigToggle}
|
|
onEditCommonConfig={() => setIsCommonConfigModalOpen(true)}
|
|
commonConfigError={commonConfigError}
|
|
configError={configError}
|
|
finalConfig={finalConfig}
|
|
/>
|
|
|
|
{/* Common Config Modal */}
|
|
<CodexCommonConfigModal
|
|
isOpen={isCommonConfigModalOpen}
|
|
onClose={() => setIsCommonConfigModalOpen(false)}
|
|
value={commonConfigSnippet}
|
|
onChange={onCommonConfigSnippetChange}
|
|
error={commonConfigError}
|
|
onExtract={onExtract}
|
|
isExtracting={isExtracting}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default CodexConfigEditor;
|