From d5aea8355bc1837ff39b61e0038ba6adde7a88d2 Mon Sep 17 00:00:00 2001 From: Stephan Rieche Date: Tue, 30 Dec 2025 01:09:25 +0100 Subject: [PATCH] refactor: improve code quality based on Gemini Code Assist suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applied three code quality improvements suggested by Gemini Code Assist: 1. **Replace nested ternary with map object (enhance.ts)** - Changed nested ternary operator to Record map - Improves readability and maintainability - More declarative approach for system prompt selection 2. **Simplify handleToggle logic (prompt-customization-section.tsx)** - Removed redundant if/else branches - Both branches were calculating the same value - Cleaner, more concise implementation 3. **Add type safety to updatePrompt with generics (prompt-customization-section.tsx)** - Changed field parameter from string to keyof NonNullable - Prevents runtime errors from misspelled field names - Improved developer experience with autocomplete All tests passing (774/774). Builds successful. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../routes/enhance-prompt/routes/enhance.ts | 15 +++++++-------- .../prompts/prompt-customization-section.tsx | 19 +++++++------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/apps/server/src/routes/enhance-prompt/routes/enhance.ts b/apps/server/src/routes/enhance-prompt/routes/enhance.ts index 0b06891d..ad6e9602 100644 --- a/apps/server/src/routes/enhance-prompt/routes/enhance.ts +++ b/apps/server/src/routes/enhance-prompt/routes/enhance.ts @@ -136,14 +136,13 @@ export function createEnhanceHandler( const prompts = await getPromptCustomization(settingsService, '[EnhancePrompt]'); // Get the system prompt for this mode from merged prompts - const systemPrompt = - validMode === 'improve' - ? prompts.enhancement.improveSystemPrompt - : validMode === 'technical' - ? prompts.enhancement.technicalSystemPrompt - : validMode === 'simplify' - ? prompts.enhancement.simplifySystemPrompt - : prompts.enhancement.acceptanceSystemPrompt; + const systemPromptMap: Record = { + improve: prompts.enhancement.improveSystemPrompt, + technical: prompts.enhancement.technicalSystemPrompt, + simplify: prompts.enhancement.simplifySystemPrompt, + acceptance: prompts.enhancement.acceptanceSystemPrompt, + }; + const systemPrompt = systemPromptMap[validMode]; logger.debug(`Using ${validMode} system prompt (length: ${systemPrompt.length} chars)`); diff --git a/apps/ui/src/components/views/settings-view/prompts/prompt-customization-section.tsx b/apps/ui/src/components/views/settings-view/prompts/prompt-customization-section.tsx index c1b1888a..06ffb924 100644 --- a/apps/ui/src/components/views/settings-view/prompts/prompt-customization-section.tsx +++ b/apps/ui/src/components/views/settings-view/prompts/prompt-customization-section.tsx @@ -72,15 +72,10 @@ function PromptField({ const minHeight = calculateMinHeight(displayValue); const handleToggle = (enabled: boolean) => { - if (enabled) { - // Enable custom mode - preserve existing custom value or initialize with default - const value = customValue?.value ?? defaultValue; - onCustomValueChange({ value, enabled: true }); - } else { - // Disable custom mode - preserve custom value but mark as disabled - const value = customValue?.value ?? defaultValue; - onCustomValueChange({ value, enabled: false }); - } + // When toggling, preserve the existing custom value if it exists, + // otherwise initialize with the default value. + const value = customValue?.value ?? defaultValue; + onCustomValueChange({ value, enabled }); }; const handleTextChange = (newValue: string) => { @@ -148,9 +143,9 @@ export function PromptCustomizationSection({ }: PromptCustomizationSectionProps) { const [activeTab, setActiveTab] = useState('auto-mode'); - const updatePrompt = ( - category: keyof PromptCustomization, - field: string, + const updatePrompt = ( + category: T, + field: keyof NonNullable, value: CustomPrompt | undefined ) => { const updated = {