Comprehensive UI polish across multiple components to enhance visual design, improve user experience, and maintain consistency. UsageScriptModal Component (1302 lines refactored): - Complete layout overhaul for better usability - Improved script editor with syntax highlighting - Better template selection interface - Enhanced test/preview panels with clearer separation - Improved error feedback and validation messages - Better modal sizing and responsiveness - Cleaner tab navigation between sections - Enhanced code formatting and readability - Improved loading states for async operations - Better integration with parent components MCP Components: - McpFormModal (42 lines): * Streamlined form layout * Better server type selection (stdio/http) * Improved field grouping and labels * Enhanced validation feedback - UnifiedMcpPanel (14 lines): * Minor layout adjustments * Better list item spacing * Improved server status indicators * Enhanced action button placement Provider Components: - ProviderCard (11 lines): * Refined card layout and spacing * Better visual hierarchy * Improved badge placement * Enhanced hover effects - ProviderList (5 lines): * Minor grid layout adjustments * Better drag-and-drop visual feedback - GeminiConfigSections (4 lines): * Field label alignment * Improved spacing consistency Editor & Footer Components: - JsonEditor (13 lines): * Better editor height management * Improved error display * Enhanced syntax highlighting - UsageFooter (10 lines): * Refined footer layout * Better quota display * Improved refresh button placement Settings & Environment: - ImportExportSection (24 lines): * Better button layout * Improved action grouping * Enhanced visual feedback - EnvWarningBanner (4 lines): * Refined alert styling * Better dismiss button placement Global Styles (index.css): - Added 11 lines of utility classes - Improved transition timing - Better focus indicators - Enhanced scrollbar styling - Refined spacing utilities Design Improvements: - Consistent spacing using design tokens - Unified color palette application - Better typography hierarchy - Improved shadow system for depth - Enhanced interactive states (hover, active, focus) - Better border radius consistency - Refined animation timings Accessibility: - Improved focus indicators - Better keyboard navigation - Enhanced screen reader support - Improved color contrast ratios Code Quality: - Net increase of 68 lines due to UsageScriptModal improvements - Better component organization - Cleaner style application - Reduced style duplication These visual refinements create a more polished and professional interface while maintaining excellent usability and accessibility standards across all components.
192 lines
5.1 KiB
TypeScript
192 lines
5.1 KiB
TypeScript
import React, { useEffect, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import JsonEditor from "@/components/JsonEditor";
|
|
|
|
interface GeminiEnvSectionProps {
|
|
value: string;
|
|
onChange: (value: string) => void;
|
|
onBlur?: () => void;
|
|
error?: string;
|
|
}
|
|
|
|
/**
|
|
* GeminiEnvSection - .env editor section for Gemini environment variables
|
|
*/
|
|
export const GeminiEnvSection: React.FC<GeminiEnvSectionProps> = ({
|
|
value,
|
|
onChange,
|
|
onBlur,
|
|
error,
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
|
|
const observer = new MutationObserver(() => {
|
|
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
});
|
|
|
|
observer.observe(document.documentElement, {
|
|
attributes: true,
|
|
attributeFilter: ["class"],
|
|
});
|
|
|
|
return () => observer.disconnect();
|
|
}, []);
|
|
|
|
const handleChange = (newValue: string) => {
|
|
onChange(newValue);
|
|
if (onBlur) {
|
|
onBlur();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-2">
|
|
<label
|
|
htmlFor="geminiEnv"
|
|
className="block text-sm font-medium text-gray-900 dark:text-gray-100"
|
|
>
|
|
{t("geminiConfig.envFile", { defaultValue: "环境变量 (.env)" })}
|
|
</label>
|
|
|
|
<JsonEditor
|
|
value={value}
|
|
onChange={handleChange}
|
|
placeholder={`GOOGLE_GEMINI_BASE_URL=https://your-api-endpoint.com/
|
|
GEMINI_API_KEY=sk-your-api-key-here
|
|
GEMINI_MODEL=gemini-3-pro-preview`}
|
|
darkMode={isDarkMode}
|
|
rows={6}
|
|
showValidation={false}
|
|
language="javascript"
|
|
/>
|
|
|
|
{error && (
|
|
<p className="text-xs text-red-500 dark:text-red-400">{error}</p>
|
|
)}
|
|
|
|
{!error && (
|
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
|
{t("geminiConfig.envFileHint", {
|
|
defaultValue: "使用 .env 格式配置 Gemini 环境变量",
|
|
})}
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
interface GeminiConfigSectionProps {
|
|
value: string;
|
|
onChange: (value: string) => void;
|
|
useCommonConfig: boolean;
|
|
onCommonConfigToggle: (checked: boolean) => void;
|
|
onEditCommonConfig: () => void;
|
|
commonConfigError?: string;
|
|
configError?: string;
|
|
}
|
|
|
|
/**
|
|
* GeminiConfigSection - Config JSON editor section with common config support
|
|
*/
|
|
export const GeminiConfigSection: React.FC<GeminiConfigSectionProps> = ({
|
|
value,
|
|
onChange,
|
|
useCommonConfig,
|
|
onCommonConfigToggle,
|
|
onEditCommonConfig,
|
|
commonConfigError,
|
|
configError,
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
|
|
const observer = new MutationObserver(() => {
|
|
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
});
|
|
|
|
observer.observe(document.documentElement, {
|
|
attributes: true,
|
|
attributeFilter: ["class"],
|
|
});
|
|
|
|
return () => observer.disconnect();
|
|
}, []);
|
|
|
|
return (
|
|
<div className="space-y-2">
|
|
<div className="flex items-center justify-between">
|
|
<label
|
|
htmlFor="geminiConfig"
|
|
className="block text-sm font-medium text-gray-900 dark:text-gray-100"
|
|
>
|
|
{t("geminiConfig.configJson", {
|
|
defaultValue: "配置文件 (config.json)",
|
|
})}
|
|
</label>
|
|
|
|
<label className="inline-flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400 cursor-pointer">
|
|
<input
|
|
type="checkbox"
|
|
checked={useCommonConfig}
|
|
onChange={(e) => onCommonConfigToggle(e.target.checked)}
|
|
className="w-4 h-4 text-blue-500 bg-white dark:bg-gray-800 border-border-default rounded focus:ring-blue-500 dark:focus:ring-blue-400 focus:ring-2"
|
|
/>
|
|
{t("geminiConfig.writeCommonConfig", {
|
|
defaultValue: "写入通用配置",
|
|
})}
|
|
</label>
|
|
</div>
|
|
|
|
<div className="flex items-center justify-end">
|
|
<button
|
|
type="button"
|
|
onClick={onEditCommonConfig}
|
|
className="text-xs text-blue-500 dark:text-blue-400 hover:underline"
|
|
>
|
|
{t("geminiConfig.editCommonConfig", {
|
|
defaultValue: "编辑通用配置",
|
|
})}
|
|
</button>
|
|
</div>
|
|
|
|
{commonConfigError && (
|
|
<p className="text-xs text-red-500 dark:text-red-400 text-right">
|
|
{commonConfigError}
|
|
</p>
|
|
)}
|
|
|
|
<JsonEditor
|
|
value={value}
|
|
onChange={onChange}
|
|
placeholder={`{
|
|
"timeout": 30000,
|
|
"maxRetries": 3
|
|
}`}
|
|
darkMode={isDarkMode}
|
|
rows={8}
|
|
showValidation={true}
|
|
language="json"
|
|
/>
|
|
|
|
{configError && (
|
|
<p className="text-xs text-red-500 dark:text-red-400">{configError}</p>
|
|
)}
|
|
|
|
{!configError && (
|
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
|
{t("geminiConfig.configJsonHint", {
|
|
defaultValue: "使用 JSON 格式配置 Gemini 扩展参数(可选)",
|
|
})}
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|