fix: address PR review feedback from Gemini Code Assist

Address three issues identified in code review:

1. Fix missing thinkingLevel parameter (Critical)
   - Added thinkingLevel parameter to enhance API call
   - Updated electron.ts type definition to match http-api-client
   - Fixes functional regression in Claude model enhancement

2. Refactor dropdown menu to use constants dynamically
   - Changed hardcoded DropdownMenuItem components to dynamic generation
   - Now iterates over ENHANCEMENT_MODE_LABELS object
   - Ensures automatic sync when new modes are added
   - Eliminates manual UI updates for new enhancement modes

3. Optimize array reversal performance
   - Added useMemo hook to memoize reversed history array
   - Prevents creating new array on every render
   - Improves performance with lengthy histories

All TypeScript errors resolved. Build verified.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Shirone
2026-01-11 15:17:46 +01:00
parent 8321c06e16
commit 7e5d915b60
3 changed files with 16 additions and 19 deletions

View File

@@ -64,7 +64,8 @@ export function EnhanceWithAI({
const result = await api.enhancePrompt?.enhance(
value,
enhancementMode,
enhancementOverride.effectiveModel
enhancementOverride.effectiveModel,
enhancementOverride.effectiveModelEntry.thinkingLevel
);
if (result?.success && result.enhancedText) {
@@ -108,21 +109,13 @@ export function EnhanceWithAI({
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem onClick={() => setEnhancementMode('improve')}>
{ENHANCEMENT_MODE_LABELS.improve}
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setEnhancementMode('technical')}>
{ENHANCEMENT_MODE_LABELS.technical}
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setEnhancementMode('simplify')}>
{ENHANCEMENT_MODE_LABELS.simplify}
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setEnhancementMode('acceptance')}>
{ENHANCEMENT_MODE_LABELS.acceptance}
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setEnhancementMode('ux-reviewer')}>
{ENHANCEMENT_MODE_LABELS['ux-reviewer']}
</DropdownMenuItem>
{(Object.entries(ENHANCEMENT_MODE_LABELS) as [EnhancementMode, string][]).map(
([mode, label]) => (
<DropdownMenuItem key={mode} onClick={() => setEnhancementMode(mode)}>
{label}
</DropdownMenuItem>
)
)}
</DropdownMenuContent>
</DropdownMenu>

View File

@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useMemo } from 'react';
import { Button } from '@/components/ui/button';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { History } from 'lucide-react';
@@ -69,6 +69,9 @@ export function EnhancementHistoryButton<T extends BaseHistoryEntry>({
});
};
// Memoize reversed history to avoid creating new array on every render
const reversedHistory = useMemo(() => [...history].reverse(), [history]);
return (
<Popover open={showHistory} onOpenChange={setShowHistory}>
<PopoverTrigger asChild>
@@ -88,7 +91,7 @@ export function EnhancementHistoryButton<T extends BaseHistoryEntry>({
<p className="text-xs text-muted-foreground mt-1">Click a version to restore it</p>
</div>
<div className="max-h-64 overflow-y-auto p-2 space-y-1">
{[...history].reverse().map((entry, index) => {
{reversedHistory.map((entry, index) => {
const value = valueAccessor(entry);
const isCurrentVersion = value === currentValue;
const sourceLabel = getSourceLabel(entry);

View File

@@ -612,7 +612,8 @@ export interface ElectronAPI {
enhance: (
originalText: string,
enhancementMode: string,
model?: string
model?: string,
thinkingLevel?: string
) => Promise<{
success: boolean;
enhancedText?: string;