feat(FN-1375): add null-as-delete pattern for settings with Reset button
- Send null instead of undefined when clearing token cap to explicitly delete setting - Handle null values as delete operations in updateSettings (for clearing keys) - Add Reset button in Settings modal to clear token cap with one click - Update placeholder and help text for token cap input - Fix TypeScript cast error for config.settings
This commit is contained in:
@@ -595,6 +595,17 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
|
||||
|
||||
return this.withConfigLock(async () => {
|
||||
const config = await this.readConfig();
|
||||
|
||||
// Handle null values as "delete this key from settings"
|
||||
// This allows the frontend to explicitly clear a setting by sending null
|
||||
// (since JSON.stringify drops undefined keys, we use null as a sentinel)
|
||||
for (const key of Object.keys(projectPatch)) {
|
||||
if ((projectPatch as Record<string, unknown>)[key] === null) {
|
||||
delete (config.settings as unknown as Record<string, unknown>)[key];
|
||||
delete (projectPatch as Record<string, unknown>)[key];
|
||||
}
|
||||
}
|
||||
|
||||
const globalSettings = await this.globalSettingsStore.getSettings();
|
||||
const previousMerged: Settings = { ...DEFAULT_SETTINGS, ...globalSettings, ...config.settings } as Settings;
|
||||
const updatedProjectSettings = { ...config.settings, ...projectPatch };
|
||||
|
||||
Reference in New Issue
Block a user