mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
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:
@@ -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<EnhancementMode, string> = {
|
||||
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)`);
|
||||
|
||||
|
||||
@@ -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 = <T extends keyof PromptCustomization>(
|
||||
category: T,
|
||||
field: keyof NonNullable<PromptCustomization[T]>,
|
||||
value: CustomPrompt | undefined
|
||||
) => {
|
||||
const updated = {
|
||||
|
||||
Reference in New Issue
Block a user