fix(ui): prevent system_prompt_template overwrite when value is empty string

## Problem
When editing trader configuration, if `system_prompt_template` was set to an empty string (""), the UI would incorrectly treat it as falsy and overwrite it with 'default', losing the user's selection.

**Root cause:**
```tsx
if (traderData && !traderData.system_prompt_template) {
  //  This triggers for both undefined AND empty string ""
  setFormData({ system_prompt_template: 'default' });
}
```

JavaScript falsy values that trigger `!` operator:
- `undefined`  Should trigger default
- `null`  Should trigger default
- `""`  Should NOT trigger (user explicitly chose empty)
- `false`, `0`, `NaN` (less relevant here)

## Solution

Change condition to explicitly check for `undefined`:

```tsx
if (traderData && traderData.system_prompt_template === undefined) {
  //  Only triggers for truly missing field
  setFormData({ system_prompt_template: 'default' });
}
```

## Impact
-  Empty string selections are preserved
-  Legacy data (undefined) still gets default value
-  User's explicit choices are respected
-  No breaking changes to existing functionality

## Testing
-  Code compiles
- ⚠️ Requires manual UI testing:
  - [ ] Edit trader with empty system_prompt_template
  - [ ] Verify it doesn't reset to 'default'
  - [ ] Create new trader → should default to 'default'
  - [ ] Edit old trader (undefined field) → should default to 'default'

## Code Changes
```
web/src/components/TraderConfigModal.tsx:
- Line 99: Changed !traderData.system_prompt_template → === undefined
```
This commit is contained in:
ZhouYongyou
2025-11-04 19:00:23 +08:00
parent 5649cb7496
commit 7bd02b7939

View File

@@ -96,7 +96,7 @@ export function TraderConfigModal({
});
}
// 确保旧数据也有默认的 system_prompt_template
if (traderData && !traderData.system_prompt_template) {
if (traderData && traderData.system_prompt_template === undefined) {
setFormData(prev => ({
...prev,
system_prompt_template: 'default'