fix(ui): clearing an agent profile field no longer leaves an unsaved change (#1874)
This commit is contained in:
1 file changed
+10
-1
@@ -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(() => {
|
||||
|
||||
Reference in new issue
Block a user