refactor: improve code quality based on Gemini Code Assist suggestions

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<EnhancementMode, string> 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<PromptCustomization[T]>
   - 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 <noreply@anthropic.com>
This commit is contained in:
Stephan Rieche
2025-12-30 01:09:25 +01:00
parent e448d6d4e5
commit d5aea8355b
2 changed files with 14 additions and 20 deletions

View File

@@ -136,14 +136,13 @@ export function createEnhanceHandler(
const prompts = await getPromptCustomization(settingsService, '[EnhancePrompt]'); const prompts = await getPromptCustomization(settingsService, '[EnhancePrompt]');
// Get the system prompt for this mode from merged prompts // Get the system prompt for this mode from merged prompts
const systemPrompt = const systemPromptMap: Record<EnhancementMode, string> = {
validMode === 'improve' improve: prompts.enhancement.improveSystemPrompt,
? prompts.enhancement.improveSystemPrompt technical: prompts.enhancement.technicalSystemPrompt,
: validMode === 'technical' simplify: prompts.enhancement.simplifySystemPrompt,
? prompts.enhancement.technicalSystemPrompt acceptance: prompts.enhancement.acceptanceSystemPrompt,
: validMode === 'simplify' };
? prompts.enhancement.simplifySystemPrompt const systemPrompt = systemPromptMap[validMode];
: prompts.enhancement.acceptanceSystemPrompt;
logger.debug(`Using ${validMode} system prompt (length: ${systemPrompt.length} chars)`); logger.debug(`Using ${validMode} system prompt (length: ${systemPrompt.length} chars)`);

View File

@@ -72,15 +72,10 @@ function PromptField({
const minHeight = calculateMinHeight(displayValue); const minHeight = calculateMinHeight(displayValue);
const handleToggle = (enabled: boolean) => { const handleToggle = (enabled: boolean) => {
if (enabled) { // When toggling, preserve the existing custom value if it exists,
// Enable custom mode - preserve existing custom value or initialize with default // otherwise initialize with the default value.
const value = customValue?.value ?? defaultValue; const value = customValue?.value ?? defaultValue;
onCustomValueChange({ value, enabled: true }); onCustomValueChange({ value, enabled });
} else {
// Disable custom mode - preserve custom value but mark as disabled
const value = customValue?.value ?? defaultValue;
onCustomValueChange({ value, enabled: false });
}
}; };
const handleTextChange = (newValue: string) => { const handleTextChange = (newValue: string) => {
@@ -148,9 +143,9 @@ export function PromptCustomizationSection({
}: PromptCustomizationSectionProps) { }: PromptCustomizationSectionProps) {
const [activeTab, setActiveTab] = useState('auto-mode'); const [activeTab, setActiveTab] = useState('auto-mode');
const updatePrompt = ( const updatePrompt = <T extends keyof PromptCustomization>(
category: keyof PromptCustomization, category: T,
field: string, field: keyof NonNullable<PromptCustomization[T]>,
value: CustomPrompt | undefined value: CustomPrompt | undefined
) => { ) => {
const updated = { const updated = {