refactor(centralui): migrate Move/Rename/Compose dialogs to DialogService.ShowAsync host (T33b)

This commit is contained in:
Joseph Doherty
2026-06-18 19:53:19 -04:00
parent c8915e8638
commit e0d085481f
9 changed files with 327 additions and 464 deletions
@@ -2,84 +2,55 @@
@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.
M9-T24b / T33b: body component for the "Move data connection" dialog hosted by
IDialogService.ShowAsync. Renders ONLY the site picker + action buttons inside
the host's .modal-body; the host owns the backdrop, header, and focus trap.
The body still injects IDataConnectionMoveService and dispatches the
MoveDataConnectionCommand through the guard-running ManagementActor path (NOT a
direct repository write) so the server's Designer gate and every move guard run.
A guard error is shown inline and the dialog STAYS OPEN; success closes the
dialog with Close(true) so the parent reloads the tree. Cancel resolves to false.
*@
@if (IsVisible)
@if (SiteOptions.Any())
{
<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>
<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 class="modal-footer px-0 pb-0 mt-3">
<button class="btn btn-outline-secondary btn-sm" @onclick="() => Context.Cancel()" disabled="@_busy">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit"
disabled="@(_busy || !SiteOptions.Any())">Move</button>
</div>
@code {
[Parameter] public bool IsVisible { get; set; }
[Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }
/// <summary>Host-supplied context: Close(true) on a successful move, Cancel on dismiss.</summary>
[Parameter] public DialogContext<bool> Context { get; set; } = default!;
[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()
protected override void OnInitialized()
{
// 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);
// Default the picker to the first candidate site.
_targetSiteId = SiteOptions.Select(o => (int?)o.Id).FirstOrDefault();
}
private async Task Submit()
@@ -94,8 +65,9 @@
if (result.Success)
{
await IsVisibleChanged.InvokeAsync(false);
await OnMoved.InvokeAsync();
// Success closes the dialog; the parent's post-ShowAsync block toasts
// and reloads the tree.
Context.Close(true);
}
else
{