fix(dashboard): pilot native dialog focus and safe dismissal

This commit is contained in:
Joseph Doherty
2026-11-13 17:51:02 -05:00
parent 3e004708d4
commit 260d58afa1
32 changed files with 1750 additions and 40 deletions
@@ -0,0 +1,2 @@
@namespace MxUiCanary.Components
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><base href="/"/><link rel="stylesheet" href="/lib/bootstrap/css/bootstrap.min.css"/><ThemeHead/><link rel="stylesheet" href="/css/site.css"/></head><body class="dashboard-body"><FixtureBody @rendermode="InteractiveServer"/><script>window.mxCanaryReady=()=>document.documentElement.dataset.mxReady='true';</script><script src="/_framework/blazor.web.js"></script></body></html>
@@ -0,0 +1,18 @@
@namespace MxUiCanary.Components
@page "/"
@inject IJSRuntime JS
<ThemeShell Product="Synthetic MX UI canary">
<ChildContent>
<p>Synthetic local fixture: no gateway worker, key store, LDAP, COM or real write provider.</p>
<button id="slow-trigger" class="btn btn-secondary" @onclick="()=>_open=true">Open synthetic delayed confirmation</button>
<button id="outside" class="btn btn-secondary">Outside inertness probe</button>
<p id="counts">Synthetic confirms: @_count</p>
<ConfirmDialog IsOpen="@_open" IsBusy="@_busy" Title="Synthetic delayed operation" Message="Fixture only; no session or key is changed." OnCancel="()=>_open=false" OnConfirm="Confirm"/>
<ApiKeysPage/>
</ChildContent>
</ThemeShell>
@code {
bool _open;bool _busy;int _count;
protected override async Task OnAfterRenderAsync(bool firstRender) {if(firstRender)await JS.InvokeVoidAsync("mxCanaryReady");}
async Task Confirm(){if(_busy)return;_busy=true;_count++;await Task.Delay(1500);_busy=false;_open=false;}
}
@@ -0,0 +1,7 @@
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using ZB.MOM.WW.Theme
@using ZB.MOM.WW.MxGateway.Server.Dashboard.Components.Shared
@using ZB.MOM.WW.MxGateway.Server.Dashboard.Components.Pages
+105
View File
@@ -0,0 +1,105 @@
using System.Runtime.CompilerServices;
using System.Security.Claims;
using Microsoft.AspNetCore.Components.Authorization;
using ZB.MOM.WW.MxGateway.Server.Dashboard;
using ZB.MOM.WW.MxGateway.Server.Security.Authentication;
using ZB.MOM.WW.MxGateway.Server.Security.Authorization;
internal sealed class StubSnapshotService : IDashboardSnapshotService
{
/// <inheritdoc />
public DashboardSnapshot GetSnapshot() => new(
GeneratedAt: DateTimeOffset.UnixEpoch,
GatewayStartedAt: DateTimeOffset.UnixEpoch,
GatewayUptime: TimeSpan.Zero,
GatewayStatus: "Healthy",
GatewayVersion: "test",
Sessions: [],
Workers: [],
Metrics: [],
Faults: [],
ApiKeys:
[
new DashboardApiKeySummary(
KeyId: "synthetic-tagged",
DisplayName: "Tags only",
Scopes: new HashSet<string>(StringComparer.Ordinal),
Constraints: ApiKeyConstraints.Empty with { DashboardTags = ["team-a", "team-b"] },
CreatedUtc: DateTimeOffset.UnixEpoch,
LastUsedUtc: null,
RevokedUtc: null),
new DashboardApiKeySummary(
KeyId: "synthetic-plain",
DisplayName: "Unconstrained",
Scopes: new HashSet<string>(StringComparer.Ordinal),
Constraints: ApiKeyConstraints.Empty,
CreatedUtc: DateTimeOffset.UnixEpoch,
LastUsedUtc: null,
RevokedUtc: null),
],
Configuration: null!,
Galaxy: null!);
/// <inheritdoc />
public IAsyncEnumerable<DashboardSnapshot> WatchSnapshotsAsync(CancellationToken cancellationToken) =>
new IdleSnapshotFeed().WatchAsync(cancellationToken);
}
// Parks until the page is disposed, so the base page's watch loop neither spins nor pushes a
// second snapshot mid-render.
internal sealed class IdleSnapshotFeed : IDashboardSnapshotFeed
{
/// <inheritdoc />
public async IAsyncEnumerable<DashboardSnapshot> WatchAsync(
[EnumeratorCancellation] CancellationToken cancellationToken)
{
await Task.Delay(Timeout.Infinite, cancellationToken).ConfigureAwait(false);
yield break;
}
}
// Grants management so the create dialog is reachable; no test here exercises a mutation.
internal sealed class ManagingApiKeyService : IDashboardApiKeyManagementService
{
/// <inheritdoc />
public bool CanManage(ClaimsPrincipal user) => true;
/// <inheritdoc />
public Task<DashboardApiKeyManagementResult> CreateAsync(
ClaimsPrincipal user,
DashboardApiKeyManagementRequest request,
CancellationToken cancellationToken) =>
Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised"));
/// <inheritdoc />
public Task<DashboardApiKeyManagementResult> RevokeAsync(
ClaimsPrincipal user,
string keyId,
CancellationToken cancellationToken) =>
Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised"));
/// <inheritdoc />
public Task<DashboardApiKeyManagementResult> RotateAsync(
ClaimsPrincipal user,
string keyId,
CancellationToken cancellationToken) =>
Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised"));
/// <inheritdoc />
public Task<DashboardApiKeyManagementResult> DeleteAsync(
ClaimsPrincipal user,
string keyId,
CancellationToken cancellationToken) =>
Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised"));
}
internal sealed class StubAuthenticationStateProvider : AuthenticationStateProvider
{
/// <inheritdoc />
public override Task<AuthenticationState> GetAuthenticationStateAsync() =>
Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity(
[new Claim(ClaimTypes.Name, "admin-user"), new Claim(ClaimTypes.Role, DashboardRoles.Admin)],
authenticationType: "test",
nameType: ClaimTypes.Name,
roleType: ClaimTypes.Role))));
}
@@ -0,0 +1,2 @@
<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><TargetFramework>net10.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup><ItemGroup><ProjectReference Include="../../../src/ZB.MOM.WW.MxGateway.Server/ZB.MOM.WW.MxGateway.Server.csproj" /></ItemGroup>
<Target Name="DeduplicateFixtureFrameworkAssets" BeforeTargets="ResolveBuildCompressedStaticWebAssetsConfiguration"><RemoveDuplicates Inputs="@(StaticWebAsset)"><Output TaskParameter="Filtered" ItemName="_UniqueFixtureStaticWebAsset" /></RemoveDuplicates><ItemGroup><StaticWebAsset Remove="@(StaticWebAsset)" /><StaticWebAsset Include="@(_UniqueFixtureStaticWebAsset)" /></ItemGroup></Target></Project>
+18
View File
@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.FileProviders;
using MxUiCanary.Components;
using ZB.MOM.WW.MxGateway.Server.Dashboard;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseUrls("http://127.0.0.1:0");
builder.WebHost.UseStaticWebAssets();
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddSingleton<IDashboardSnapshotService, StubSnapshotService>();
builder.Services.AddSingleton<IDashboardSnapshotFeed, IdleSnapshotFeed>();
builder.Services.AddSingleton<IDashboardApiKeyManagementService, ManagingApiKeyService>();
builder.Services.AddSingleton<AuthenticationStateProvider, StubAuthenticationStateProvider>();
var app = builder.Build();
app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.GetFullPath("../../../src/ZB.MOM.WW.MxGateway.Server/wwwroot")) });
app.UseStaticFiles();app.UseAntiforgery();
app.MapRazorComponents<FixtureApp>().AddInteractiveServerRenderMode();
app.MapGet("/provenance",()=>new { theme=typeof(ZB.MOM.WW.Theme.ThemeShell).Assembly.GetName().Version?.ToString(), syntheticOnly=true });
app.Run();