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
@@ -42,12 +42,6 @@
<ToastNotification @ref="_toast" />
<MoveDataConnectionDialog @bind-IsVisible="_showMoveDialog"
ConnectionId="_moveConnectionId"
ConnectionName="@_moveConnectionName"
SiteOptions="MoveTargetSiteOptions()"
OnMoved="OnConnectionMoved" />
@if (_loading)
{
<LoadingSpinner IsLoading="true" />
@@ -425,37 +419,37 @@
}
}
// ── M9-T24b: Move connection to another site ──
// The dialog dispatches MoveDataConnectionCommand through the guard-running
// ManagementActor path (IDataConnectionMoveService) — NOT a direct repository
// write — so the server enforces the Designer gate and every move guard. The
// page only opens the dialog, supplies the candidate target sites (the current
// site excluded), and reloads the tree once the move succeeds.
private bool _showMoveDialog;
private int _moveConnectionId;
private int _moveConnectionSiteId;
private string _moveConnectionName = string.Empty;
private void OpenMoveDialog(DataConnection conn)
// ── M9-T24b / T33b: Move connection to another site ──
// Opened via IDialogService.ShowAsync. The body dispatches MoveDataConnectionCommand
// through the guard-running ManagementActor path (IDataConnectionMoveService) — NOT
// a direct repository write — so the server enforces the Designer gate and every
// move guard, showing any guard error inline and staying open. On success the body
// closes with true; the page then toasts and reloads the tree.
private async Task OpenMoveDialog(DataConnection conn)
{
_moveConnectionId = conn.Id;
_moveConnectionSiteId = conn.SiteId;
_moveConnectionName = conn.Name;
_showMoveDialog = true;
var connId = conn.Id;
var connName = conn.Name;
var options = MoveTargetSiteOptions(conn.SiteId);
var moved = await Dialog.ShowAsync<bool>(
$"Move '{connName}' to site…",
ctx => @<MoveDataConnectionDialog Context="ctx"
ConnectionId="connId"
ConnectionName="@connName"
SiteOptions="options" />);
if (moved)
{
_toast.ShowSuccess($"Connection '{connName}' moved.");
await LoadDataAsync();
}
}
// Candidate target sites for the move: every site EXCEPT the connection's
// current one. Sourced from the already-loaded tree roots (each root is a site).
private IEnumerable<(int Id, string Label)> MoveTargetSiteOptions() =>
private IEnumerable<(int Id, string Label)> MoveTargetSiteOptions(int currentSiteId) =>
_treeRoots
.Where(r => r.SiteId is int sid && sid != _moveConnectionSiteId)
.Select(r => (r.SiteId!.Value, r.Label));
private async Task OnConnectionMoved()
{
_toast.ShowSuccess($"Connection '{_moveConnectionName}' moved.");
await LoadDataAsync();
}
.Where(r => r.SiteId is int sid && sid != currentSiteId)
.Select(r => (r.SiteId!.Value, r.Label))
.ToList();
// M9-T25: enum → Bootstrap badge class. Mirrors the Health dashboard's
// GetConnectionHealthBadge (Components/Pages/Monitoring/Health.razor) so the
@@ -17,33 +17,6 @@
<div class="container-fluid mt-3">
<ToastNotification @ref="_toast" />
<RenameFolderDialog @bind-IsVisible="_showRenameFolderDialog"
FolderId="_renameFolderId"
InitialName="@_renameFolderInitialName"
ErrorMessage="@_renameFolderError"
OnSubmit="SubmitRenameFolder" />
<MoveTemplateDialog @bind-IsVisible="_showMoveTemplateDialog"
TemplateId="_moveTemplateId"
TemplateName="@_moveTemplateName"
FolderOptions="EnumerateFolderOptions()"
ErrorMessage="@_moveTemplateError"
OnSubmit="SubmitMoveTemplate" />
<MoveFolderDialog @bind-IsVisible="_showMoveFolderDialog"
FolderId="_moveFolderId"
FolderName="@_moveFolderName"
FolderOptions="EnumerateFolderOptionsExcluding(_moveFolderId)"
ErrorMessage="@_moveFolderError"
OnSubmit="SubmitMoveFolder" />
<ComposeIntoDialog @bind-IsVisible="_showComposeDialog"
SourceTemplateId="_composeSourceId"
SourceName="@_composeSourceName"
ParentOptions="EnumerateComposableParents(_composeSourceId)"
ErrorMessage="@_composeError"
OnSubmit="SubmitCompose" />
@if (_loading)
{
<LoadingSpinner IsLoading="true" />
@@ -314,34 +287,26 @@
}
}
// Move-template dialog state
private bool _showMoveTemplateDialog;
private int _moveTemplateId;
private string _moveTemplateName = string.Empty;
private string? _moveTemplateError;
private void OpenMoveTemplateDialog(int templateId, string label)
// Move-template dialog: opened via IDialogService.ShowAsync. The body returns
// the picked folder id (null = Root) on Move, or null on Cancel; validation runs
// here after the dialog closes and surfaces server guard failures via a toast.
private async Task OpenMoveTemplateDialog(int templateId, string label)
{
_moveTemplateId = templateId;
_moveTemplateName = label;
_moveTemplateError = null;
_showMoveTemplateDialog = true;
}
var result = await Dialog.ShowAsync<MoveTemplateDialog.MoveTemplateResult>(
$"Move '{label}' to…",
ctx => @<MoveTemplateDialog Context="ctx" FolderOptions="EnumerateFolderOptions()" />);
if (result is null) return;
private async Task SubmitMoveTemplate((int TemplateId, int? NewFolderId) req)
{
_moveTemplateError = null;
var user = await GetCurrentUserAsync();
var result = await TemplateService.MoveTemplateAsync(req.TemplateId, req.NewFolderId, user);
if (result.IsSuccess)
var moved = await TemplateService.MoveTemplateAsync(templateId, result.NewFolderId, user);
if (moved.IsSuccess)
{
_showMoveTemplateDialog = false;
_toast.ShowSuccess($"Template '{_moveTemplateName}' moved.");
_toast.ShowSuccess($"Template '{label}' moved.");
await LoadTemplatesAsync();
}
else
{
_moveTemplateError = result.Error;
_toast.ShowError(moved.Error);
}
}
@@ -373,34 +338,27 @@
}
}
// Move-folder dialog state
private bool _showMoveFolderDialog;
private int _moveFolderId;
private string _moveFolderName = string.Empty;
private string? _moveFolderError;
private void OpenMoveFolderDialog(int folderId, string label)
// Move-folder dialog: opened via IDialogService.ShowAsync. The picker prunes the
// folder + its descendants (server still validates cycles). The body returns the
// picked parent id (null = Root) on Move, or null on Cancel; server guard failures
// surface via a toast.
private async Task OpenMoveFolderDialog(int folderId, string label)
{
_moveFolderId = folderId;
_moveFolderName = label;
_moveFolderError = null;
_showMoveFolderDialog = true;
}
var result = await Dialog.ShowAsync<MoveFolderDialog.MoveFolderResult>(
$"Move '{label}' to…",
ctx => @<MoveFolderDialog Context="ctx" FolderOptions="EnumerateFolderOptionsExcluding(folderId)" />);
if (result is null) return;
private async Task SubmitMoveFolder((int FolderId, int? NewParentId) req)
{
_moveFolderError = null;
var user = await GetCurrentUserAsync();
var result = await TemplateFolderService.MoveFolderAsync(req.FolderId, req.NewParentId, user);
if (result.IsSuccess)
var moved = await TemplateFolderService.MoveFolderAsync(folderId, result.NewParentId, user);
if (moved.IsSuccess)
{
_showMoveFolderDialog = false;
_toast.ShowSuccess($"Folder '{_moveFolderName}' moved.");
_toast.ShowSuccess($"Folder '{label}' moved.");
await LoadTemplatesAsync();
}
else
{
_moveFolderError = result.Error;
_toast.ShowError(moved.Error);
}
}
@@ -467,34 +425,27 @@
private void DismissRootContextMenu() => _showRootMenu = false;
// Rename folder dialog state
private bool _showRenameFolderDialog;
private int _renameFolderId;
private string _renameFolderInitialName = string.Empty;
private string? _renameFolderError;
private void OpenRenameFolderDialog(int folderId, string currentName)
// Rename folder dialog: opened via IDialogService.ShowAsync. The body seeds the
// input from the current name and returns the trimmed new name on Save, or null on
// Cancel; server guard failures surface via a toast.
private async Task OpenRenameFolderDialog(int folderId, string currentName)
{
_renameFolderId = folderId;
_renameFolderInitialName = currentName;
_renameFolderError = null;
_showRenameFolderDialog = true;
}
var newName = await Dialog.ShowAsync<string>(
"Rename Folder",
ctx => @<RenameFolderDialog Context="ctx" InitialName="@currentName" />,
size: "modal-sm");
if (string.IsNullOrWhiteSpace(newName)) return;
private async Task SubmitRenameFolder((int FolderId, string NewName) req)
{
_renameFolderError = null;
var user = await GetCurrentUserAsync();
var result = await TemplateFolderService.RenameFolderAsync(req.FolderId, req.NewName, user);
var result = await TemplateFolderService.RenameFolderAsync(folderId, newName, user);
if (result.IsSuccess)
{
_showRenameFolderDialog = false;
_toast.ShowSuccess("Folder renamed.");
await LoadTemplatesAsync();
}
else
{
_renameFolderError = result.Error;
_toast.ShowError(result.Error);
}
}
@@ -545,17 +496,31 @@
}
// ---- Compose-into dialog ----
private bool _showComposeDialog;
private int _composeSourceId;
private string _composeSourceName = string.Empty;
private string? _composeError;
private void OpenComposeDialog(Template source)
// Opened via IDialogService.ShowAsync. The body returns the chosen parent template
// + slot name on Compose (its own client-side guard keeps the button disabled until
// both are set), or null on Cancel; server guard failures surface via a toast.
private async Task OpenComposeDialog(Template source)
{
_composeSourceId = source.Id;
_composeSourceName = source.Name;
_composeError = null;
_showComposeDialog = true;
var sourceId = source.Id;
var sourceName = source.Name;
var result = await Dialog.ShowAsync<ComposeIntoDialog.ComposeResult>(
$"Compose '{sourceName}' into…",
ctx => @<ComposeIntoDialog Context="ctx"
SourceName="@sourceName"
ParentOptions="EnumerateComposableParents(sourceId)" />);
if (result is null) return;
var user = await GetCurrentUserAsync();
var composed = await TemplateService.AddCompositionAsync(result.ParentTemplateId, sourceId, result.SlotName, user);
if (composed.IsSuccess)
{
_toast.ShowSuccess($"Composed '{sourceName}' as '{result.SlotName}'.");
await LoadTemplatesAsync();
}
else
{
_toast.ShowError(composed.Error);
}
}
// Possible parents for a compose: every non-derived template except the source itself.
@@ -568,23 +533,6 @@
.Select(t => (t.Id, t.Name));
}
private async Task SubmitCompose((int SourceTemplateId, int ParentTemplateId, string SlotName) req)
{
_composeError = null;
var user = await GetCurrentUserAsync();
var result = await TemplateService.AddCompositionAsync(req.ParentTemplateId, req.SourceTemplateId, req.SlotName, user);
if (result.IsSuccess)
{
_showComposeDialog = false;
_toast.ShowSuccess($"Composed '{_composeSourceName}' as '{req.SlotName}'.");
await LoadTemplatesAsync();
}
else
{
_composeError = result.Error;
}
}
// ---- Composition leaf: rename + delete ----
private async Task RenameComposition(TemplateComposition composition)
{
@@ -1,68 +1,57 @@
@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">Compose '@SourceName' into…</h6>
<button type="button" class="btn-close" @onclick="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label small text-muted mb-1">Parent template</label>
<select class="form-select form-select-sm" @bind="_parentTemplateId">
<option value="0" disabled selected>Select a parent template…</option>
@foreach (var opt in ParentOptions)
{
<option value="@opt.Id">@opt.Label</option>
}
</select>
</div>
<div class="mb-1">
<label class="form-label small text-muted mb-1">Slot name</label>
<input type="text" class="form-control form-control-sm"
placeholder="Slot name"
@bind="_slotName" />
</div>
@if (!string.IsNullOrEmpty(ErrorMessage)) { <div class="text-danger small mt-2">@ErrorMessage</div> }
</div>
<div class="modal-footer">
<button class="btn btn-outline-secondary btn-sm" @onclick="Close">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit" disabled="@(_parentTemplateId == 0 || string.IsNullOrWhiteSpace(_slotName))">Compose</button>
</div>
</div>
</div>
</div>
}
@*
T33b: body component for the "Compose into" dialog hosted by
IDialogService.ShowAsync. Renders ONLY the parent/slot fields + action buttons
inside the host's .modal-body; the host owns the backdrop, header, and focus
trap. Closes with a ComposeResult (parent template id + slot name); Cancel
resolves to null. The Compose button stays disabled until both a parent and a
non-blank slot are chosen (client-side guard, preserved from the original).
Server-side compose failures are surfaced by the parent via a toast.
*@
<div class="mb-3">
<label class="form-label small text-muted mb-1">Parent template</label>
<select class="form-select form-select-sm" @bind="_parentTemplateId">
<option value="0" disabled selected>Select a parent template…</option>
@foreach (var opt in ParentOptions)
{
<option value="@opt.Id">@opt.Label</option>
}
</select>
</div>
<div class="mb-1">
<label class="form-label small text-muted mb-1">Slot name</label>
<input type="text" class="form-control form-control-sm"
placeholder="Slot name"
@bind="_slotName" @bind:event="oninput" />
</div>
<div class="modal-footer px-0 pb-0 mt-3">
<button class="btn btn-outline-secondary btn-sm" @onclick="() => Context.Cancel()">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit"
disabled="@(_parentTemplateId == 0 || string.IsNullOrWhiteSpace(_slotName))">Compose</button>
</div>
@code {
[Parameter] public bool IsVisible { get; set; }
[Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }
[Parameter] public int SourceTemplateId { get; set; }
/// <summary>Host-supplied context used to close (with the chosen parent + slot) or cancel.</summary>
[Parameter] public DialogContext<ComposeResult> Context { get; set; } = default!;
[Parameter] public string SourceName { get; set; } = string.Empty;
[Parameter] public IEnumerable<(int Id, string Label)> ParentOptions { get; set; } = Array.Empty<(int, string)>();
[Parameter] public string? ErrorMessage { get; set; }
[Parameter] public EventCallback<(int SourceTemplateId, int ParentTemplateId, string SlotName)> OnSubmit { get; set; }
private bool _wasVisible;
private int _parentTemplateId;
private string _slotName = string.Empty;
protected override void OnParametersSet()
{
if (IsVisible && !_wasVisible)
{
_parentTemplateId = 0;
_slotName = SourceName;
}
_wasVisible = IsVisible;
}
protected override void OnInitialized() => _slotName = SourceName;
private async Task Close() => await IsVisibleChanged.InvokeAsync(false);
private async Task Submit()
private void Submit()
{
if (_parentTemplateId == 0 || string.IsNullOrWhiteSpace(_slotName)) return;
await OnSubmit.InvokeAsync((SourceTemplateId, _parentTemplateId, _slotName.Trim()));
Context.Close(new ComposeResult(_parentTemplateId, _slotName.Trim()));
}
/// <summary>
/// Result of the compose picker: the parent template to compose into and the
/// slot name. ShowAsync resolves to this record on Compose, or <c>null</c> on Cancel.
/// </summary>
/// <param name="ParentTemplateId">The template the source is composed into.</param>
/// <param name="SlotName">The trimmed slot (composition instance) name.</param>
public sealed record ComposeResult(int ParentTemplateId, string SlotName);
}
@@ -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
{
@@ -1,58 +1,38 @@
@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 '@FolderName' to…</h6>
<button type="button" class="btn-close" @onclick="Close"></button>
</div>
<div class="modal-body">
<select class="form-select form-select-sm" @bind="_targetParentId">
@foreach (var opt in FolderOptions)
{
<option value="@opt.Id">@opt.Label</option>
}
</select>
@if (!string.IsNullOrEmpty(ErrorMessage)) { <div class="text-danger small mt-1">@ErrorMessage</div> }
</div>
<div class="modal-footer">
<button class="btn btn-outline-secondary btn-sm" @onclick="Close">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit">Move</button>
</div>
</div>
</div>
</div>
}
@*
T33b: body component for the "Move folder" dialog hosted by
IDialogService.ShowAsync. Renders ONLY the picker + action buttons inside the
host's .modal-body; the host owns the backdrop, header, and focus trap. The
body closes with a MoveFolderResult carrying the picked parent id (null = Root,
which is why a result record is used: Close(null) would otherwise be
indistinguishable from a Cancel). The parent validates after the dialog closes
and toasts any server guard failure.
*@
<select class="form-select form-select-sm" @bind="_targetParentId">
@foreach (var opt in FolderOptions)
{
<option value="@opt.Id">@opt.Label</option>
}
</select>
<div class="modal-footer px-0 pb-0 mt-3">
<button class="btn btn-outline-secondary btn-sm" @onclick="() => Context.Cancel()">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit">Move</button>
</div>
@code {
[Parameter] public bool IsVisible { get; set; }
[Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }
[Parameter] public int FolderId { get; set; }
[Parameter] public string FolderName { get; set; } = string.Empty;
/// <summary>Host-supplied context used to close (with the picked parent id) or cancel.</summary>
[Parameter] public DialogContext<MoveFolderResult> Context { get; set; } = default!;
[Parameter] public IEnumerable<(int? Id, string Label)> FolderOptions { get; set; } = Array.Empty<(int?, string)>();
[Parameter] public string? ErrorMessage { get; set; }
[Parameter] public EventCallback<(int FolderId, int? NewParentId)> OnSubmit { get; set; }
private bool _wasVisible;
private int? _targetParentId;
protected override void OnParametersSet()
{
if (IsVisible && !_wasVisible)
{
_targetParentId = null;
}
_wasVisible = IsVisible;
}
private void Submit() => Context.Close(new MoveFolderResult(_targetParentId));
private async Task Close()
{
await IsVisibleChanged.InvokeAsync(false);
}
private async Task Submit()
{
await OnSubmit.InvokeAsync((FolderId, _targetParentId));
}
/// <summary>
/// Result of the move-folder picker. A reference type so a non-null close is
/// distinguishable from a cancel even when the picked parent is null (Root):
/// ShowAsync resolves to this record on Move and to <c>null</c> on Cancel.
/// </summary>
/// <param name="NewParentId">The chosen parent folder id, or <c>null</c> for Root.</param>
public sealed record MoveFolderResult(int? NewParentId);
}
@@ -1,59 +1,36 @@
@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 '@TemplateName' to…</h6>
<button type="button" class="btn-close" @onclick="Close"></button>
</div>
<div class="modal-body">
<select class="form-select form-select-sm" @bind="_targetFolderId">
@foreach (var opt in FolderOptions)
{
<option value="@opt.Id">@opt.Label</option>
}
</select>
@if (!string.IsNullOrEmpty(ErrorMessage)) { <div class="text-danger small mt-1">@ErrorMessage</div> }
</div>
<div class="modal-footer">
<button class="btn btn-outline-secondary btn-sm" @onclick="Close">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit">Move</button>
</div>
</div>
</div>
</div>
}
@*
T33b: body component for the "Move template" dialog hosted by
IDialogService.ShowAsync. Renders ONLY the picker + action buttons inside the
host's .modal-body; the host owns the backdrop, header, and focus trap. Closes
with a MoveTemplateResult carrying the picked folder id (null = Root) — a result
record so Close(null) for the Root choice stays distinguishable from a Cancel.
*@
<select class="form-select form-select-sm" @bind="_targetFolderId">
@foreach (var opt in FolderOptions)
{
<option value="@opt.Id">@opt.Label</option>
}
</select>
<div class="modal-footer px-0 pb-0 mt-3">
<button class="btn btn-outline-secondary btn-sm" @onclick="() => Context.Cancel()">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit">Move</button>
</div>
@code {
[Parameter] public bool IsVisible { get; set; }
[Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }
[Parameter] public int TemplateId { get; set; }
[Parameter] public string TemplateName { get; set; } = string.Empty;
/// <summary>Host-supplied context used to close (with the picked folder id) or cancel.</summary>
[Parameter] public DialogContext<MoveTemplateResult> Context { get; set; } = default!;
[Parameter] public IEnumerable<(int? Id, string Label)> FolderOptions { get; set; } = Array.Empty<(int?, string)>();
[Parameter] public string? ErrorMessage { get; set; }
[Parameter] public EventCallback<(int TemplateId, int? NewFolderId)> OnSubmit { get; set; }
private bool _wasVisible;
private int? _targetFolderId;
protected override void OnParametersSet()
{
// Reset internal state on transition from hidden -> visible.
if (IsVisible && !_wasVisible)
{
_targetFolderId = null;
}
_wasVisible = IsVisible;
}
private void Submit() => Context.Close(new MoveTemplateResult(_targetFolderId));
private async Task Close()
{
await IsVisibleChanged.InvokeAsync(false);
}
private async Task Submit()
{
await OnSubmit.InvokeAsync((TemplateId, _targetFolderId));
}
/// <summary>
/// Result of the move-template picker. A reference type so a non-null close is
/// distinguishable from a cancel even when the picked folder is null (Root):
/// ShowAsync resolves to this record on Move and to <c>null</c> on Cancel.
/// </summary>
/// <param name="NewFolderId">The chosen destination folder id, or <c>null</c> for Root.</param>
public sealed record MoveTemplateResult(int? NewFolderId);
}
@@ -1,53 +1,31 @@
@if (IsVisible)
{
<div class="modal show d-block" tabindex="-1" style="background: rgba(0,0,0,0.4);">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title">Rename Folder</h6>
<button type="button" class="btn-close" @onclick="Close"></button>
</div>
<div class="modal-body">
<input class="form-control form-control-sm" @bind="_name" />
@if (!string.IsNullOrEmpty(ErrorMessage)) { <div class="text-danger small mt-1">@ErrorMessage</div> }
</div>
<div class="modal-footer">
<button class="btn btn-outline-secondary btn-sm" @onclick="Close">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit">Save</button>
</div>
</div>
</div>
</div>
}
@*
T33b: body component for the "Rename folder" dialog hosted by
IDialogService.ShowAsync. Renders ONLY the input + action buttons inside the
host's .modal-body; the host owns the backdrop, header, and focus trap. Closes
with the trimmed new name (string); Cancel resolves to null. Save is disabled
while the field is blank (client-side guard); server-side rename failures are
surfaced by the parent via a toast.
*@
<input class="form-control form-control-sm" @bind="_name" @bind:event="oninput" />
<div class="modal-footer px-0 pb-0 mt-3">
<button class="btn btn-outline-secondary btn-sm" @onclick="() => Context.Cancel()">Cancel</button>
<button class="btn btn-primary btn-sm" @onclick="Submit"
disabled="@string.IsNullOrWhiteSpace(_name)">Save</button>
</div>
@code {
[Parameter] public bool IsVisible { get; set; }
[Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }
[Parameter] public int FolderId { get; set; }
/// <summary>Host-supplied context used to close (with the trimmed name) or cancel.</summary>
[Parameter] public DialogContext<string> Context { get; set; } = default!;
[Parameter] public string InitialName { get; set; } = string.Empty;
[Parameter] public string? ErrorMessage { get; set; }
[Parameter] public EventCallback<(int FolderId, string NewName)> OnSubmit { get; set; }
private bool _wasVisible;
private string _name = string.Empty;
protected override void OnParametersSet()
{
// Reset internal state on transition from hidden -> visible.
if (IsVisible && !_wasVisible)
{
_name = InitialName;
}
_wasVisible = IsVisible;
}
protected override void OnInitialized() => _name = InitialName;
private async Task Close()
private void Submit()
{
await IsVisibleChanged.InvokeAsync(false);
}
private async Task Submit()
{
await OnSubmit.InvokeAsync((FolderId, _name.Trim()));
if (string.IsNullOrWhiteSpace(_name)) return;
Context.Close(_name.Trim());
}
}