feat(m9/T24b): move-data-connection UI dialog + action

This commit is contained in:
Joseph Doherty
2026-06-18 11:45:53 -04:00
parent dbe51e5f25
commit 16cb078cd2
7 changed files with 530 additions and 0 deletions
@@ -0,0 +1,105 @@
@using ZB.MOM.WW.ScadaBridge.CentralUI.Services
@inject IDataConnectionMoveService MoveService
@*
M9-T24b: Move a data connection to another site. The picker lists the candidate
target sites (the page excludes the connection's current site). On confirm the
dialog dispatches MoveDataConnectionCommand through IDataConnectionMoveService —
the guard-running ManagementActor path, NOT a direct repository write — so the
server's Designer gate and every move guard (target exists, no name collision, no
instance binding, no native-alarm-source name reference) run. A guard error is
shown inline and the dialog stays open; success closes the dialog and raises
OnMoved so the page reloads the tree. Mirrors the MoveFolderDialog idiom.
*@
@if (IsVisible)
{
<div class="modal show d-block" tabindex="-1" style="background: rgba(0,0,0,0.4);">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title">Move '@ConnectionName' to site…</h6>
<button type="button" class="btn-close" @onclick="Close" disabled="@_busy"></button>
</div>
<div class="modal-body">
@if (SiteOptions.Any())
{
<select class="form-select form-select-sm" @bind="_targetSiteId">
@foreach (var opt in SiteOptions)
{
<option value="@opt.Id">@opt.Label</option>
}
</select>
}
else
{
<div class="text-muted small">No other site is available to move this connection to.</div>
}
@if (!string.IsNullOrEmpty(_error))
{
<div class="text-danger small mt-2" data-test="move-connection-error">@_error</div>
}
</div>
<div class="modal-footer">
<button class="btn btn-outline-secondary btn-sm" @onclick="Close" disabled="@_busy">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit"
disabled="@(_busy || !SiteOptions.Any())">Move</button>
</div>
</div>
</div>
</div>
}
@code {
[Parameter] public bool IsVisible { get; set; }
[Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }
[Parameter] public int ConnectionId { get; set; }
[Parameter] public string ConnectionName { get; set; } = string.Empty;
[Parameter] public IEnumerable<(int Id, string Label)> SiteOptions { get; set; } = Array.Empty<(int, string)>();
/// <summary>Raised after a successful move so the page can reload the tree.</summary>
[Parameter] public EventCallback OnMoved { get; set; }
private bool _wasVisible;
private int? _targetSiteId;
private string? _error;
private bool _busy;
protected override void OnParametersSet()
{
// Reset internal state on transition from hidden -> visible: default the
// picker to the first candidate site and clear any prior error.
if (IsVisible && !_wasVisible)
{
_targetSiteId = SiteOptions.Select(o => (int?)o.Id).FirstOrDefault();
_error = null;
_busy = false;
}
_wasVisible = IsVisible;
}
private async Task Close()
{
await IsVisibleChanged.InvokeAsync(false);
}
private async Task Submit()
{
if (_targetSiteId is not int target || _busy) return;
_busy = true;
_error = null;
var result = await MoveService.MoveAsync(ConnectionId, target);
_busy = false;
if (result.Success)
{
await IsVisibleChanged.InvokeAsync(false);
await OnMoved.InvokeAsync();
}
else
{
// Surface the server guard error inline; keep the dialog open.
_error = result.Error ?? "Move failed.";
}
}
}