fix(adminui): refresh script dropdown label after inline create
After inline "New script" creates an SC-… id, the entry is now added to _scripts BEFORE _form.ScriptId is set so the <InputSelect> has a matching <option> on first render and the displayed label is correct. Extracts VirtualTagModalHelpers.ResolveScriptLabel as a testable pure helper (5 new unit tests in VirtualTagScriptDropdownTests).
This commit is contained in:
@@ -329,14 +329,16 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind the new script and load its (blank) source so the inline editor renders + expands.
|
||||
_form.ScriptId = result.CreatedId;
|
||||
await LoadScriptSourceAsync();
|
||||
// Make the freshly-created script a real option in the dropdown so the select stays coherent.
|
||||
// Add the new script to the options list BEFORE setting the selected value so the
|
||||
// <InputSelect> can resolve the label on first render — if we set ScriptId first the
|
||||
// dropdown has no matching <option> yet and shows a blank/stale label.
|
||||
if (!_scripts.Any(s => s.Id == result.CreatedId))
|
||||
{
|
||||
_scripts.Add((result.CreatedId, $"{seedName} (CSharp)"));
|
||||
}
|
||||
// Bind the new script and load its (blank) source so the inline editor renders + expands.
|
||||
_form.ScriptId = result.CreatedId;
|
||||
await LoadScriptSourceAsync();
|
||||
_scriptExpanded = true;
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Uns;
|
||||
|
||||
/// <summary>
|
||||
/// Pure helpers extracted from <see cref="VirtualTagModal"/> to support unit testing of state
|
||||
/// logic that is otherwise embedded in Razor component lifecycle methods.
|
||||
/// </summary>
|
||||
internal static class VirtualTagModalHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves the display label for the given <paramref name="selectedId"/> from the supplied
|
||||
/// dropdown <paramref name="options"/> list.
|
||||
/// </summary>
|
||||
/// <param name="options">
|
||||
/// The current in-memory options, each as an <c>(Id, Display)</c> pair. This list MUST include
|
||||
/// the newly-created script entry BEFORE <c>selectedId</c> is set on the form; otherwise the
|
||||
/// rendered <c><select></c> will have no matching <c><option></c> and show a blank
|
||||
/// label.
|
||||
/// </param>
|
||||
/// <param name="selectedId">The id of the currently selected script (may be null or empty).</param>
|
||||
/// <returns>
|
||||
/// The display label for the selected id, or <c>null</c> when <paramref name="selectedId"/> is
|
||||
/// empty or is not present in <paramref name="options"/>.
|
||||
/// </returns>
|
||||
internal static string? ResolveScriptLabel(
|
||||
IEnumerable<(string Id, string Display)> options,
|
||||
string? selectedId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(selectedId))
|
||||
return null;
|
||||
|
||||
foreach (var (id, display) in options)
|
||||
{
|
||||
if (id == selectedId)
|
||||
return display;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user