fix(adminui): preserve edited alarm fields on Galaxy address re-pick

This commit is contained in:
Joseph Doherty
2026-06-19 02:02:06 -04:00
parent f81fa76809
commit 2dd723e195
3 changed files with 105 additions and 8 deletions
@@ -336,14 +336,12 @@
private void OnGalaxyAddressPicked(string address)
{
_galaxyAddress = address;
// A fresh {FullName} blob would drop any tag-level historize the operator already set on this
// edit; re-merge it so re-picking a Galaxy address never silently clears "Historize this tag".
var config = TagHistorizeConfig.Set(
JsonSerializer.Serialize(new { FullName = address }),
_historizeState.IsHistorized,
_historizeState.HistorianTagname);
// Re-merge any array intent for the same reason — a fresh {FullName} blob would otherwise drop it.
config = TagArrayConfig.Set(config, _arrayState.IsArray, _arrayState.ArrayLength);
// Re-picking a Galaxy address owns ONLY the address-derived FullName key — apply it over the EXISTING
// TagConfig so every other user-edited field survives verbatim. This preserves a hand-authored `alarm`
// object (FB-4: a re-pick must never clobber edited alarm fields) as well as the root history/array
// intent and any driver/unknown keys. TagConfigJson.SetFullName uses the same preserve-unknown idiom
// as the historize/array merge seams.
var config = TagConfigJson.SetFullName(_form.TagConfig, address);
_form.TagConfig = _galaxyPickedIsAlarm
? NativeAlarmModel.SeedDefaultAlarm(config)
: config;
@@ -43,4 +43,19 @@ public static class TagConfigJson
if (value is null) { o.Remove(name); return; }
o[name] = JsonValue.Create(value is Enum e ? e.ToString() : value);
}
/// <summary>
/// Merges a freshly-picked Galaxy reference (<c>tag_name.AttributeName</c>) into <paramref name="json"/>
/// by setting ONLY the canonical PascalCase <c>FullName</c> key — every other key is preserved verbatim.
/// This is the Galaxy address re-pick seam: re-picking an address must update the bound attribute WITHOUT
/// discarding fields the operator already edited independently of the address — ESPECIALLY a hand-authored
/// <c>alarm</c> object (and root history/array intent, scaling, etc.). Null/blank/malformed input starts
/// from a bare <c>{"FullName":...}</c> object.
/// </summary>
public static string SetFullName(string? json, string fullName)
{
var o = ParseOrNew(json);
o["FullName"] = JsonValue.Create(fullName);
return Serialize(o);
}
}