fix(ui): clearing an agent profile field no longer leaves an unsaved change (#1874)

This commit is contained in:
sam committed 2026-11-14 03:48:04 +11:00
1 parent 5c02207d48
commit 0451545220
1 file changed
+10 -1
+10 -1
View File
@@ -43,8 +43,17 @@ function removeProfile(index: number) {
if (!key) return;
store.setDraftEntry(KIND, key, undefined);
}
// A field cleared back to empty is dropped unless the stored profile has it,
// so emptying a field the profile never had is not a change.
function patch(key: string, changes: Partial<Profile>) {
store.setDraftEntry(KIND, key, { ...profiles.value?.[key], ...changes });
const stored = (store.stateFor(KIND).resource?.value as Record<string, Profile> | null)?.[key];
const next: Record<string, unknown> = { ...profiles.value?.[key], ...changes };
for (const field of Object.keys(changes)) {
const value = next[field];
const empty = Array.isArray(value) ? value.length === 0 : value === "";
if (empty && !(stored && field in stored)) delete next[field];
}
store.setDraftEntry(KIND, key, next);
}
onMounted(() => {