From 316153dc9873674b0753b642732fa8b186e38d6c Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Sat, 1 Aug 2026 11:26:55 -0400 Subject: [PATCH] =?UTF-8?q?feat(centralui):=20hide=20OffsetPager=20on=20a?= =?UTF-8?q?=20single=20page,=20opt-in=20=E2=80=94=20NotificationReport=20e?= =?UTF-8?q?nabled=20(M10=20residual)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DECISION: a pager whose only two controls are permanently disabled is noise, so the conventional behaviour ships — the bar is hidden when the result set is a single page. NotificationReport, which raised the finding, opts in. RATIONALE for opt-in rather than default-on. OffsetPager is shared, and its summary span ("Page N of Y · T total") doubles as the ONLY total-count readout on ConfigurationAuditLog — auto-hiding there would silently delete the result count for every query returning under a page, and the existing Playwright fixture asserts "3 total" on exactly such a query. So the behaviour lives in the shared component (reusable for the next consumer) behind HideWhenSinglePage, default false, which keeps every current consumer byte-identical. The guard fires only when single-page-ness is POSITIVELY established: PageCount <= 1 AND Page <= 1 AND !HasNextPage. A null TotalCount means the host cannot count, so the bar renders — the controls never vanish while a further page still exists. NotificationReport's own Playwright pagination test seeds 51 rows (2 pages) and is unaffected. 5 new bUnit tests cover hide-on-single-page, hide-on-empty, show-on-multi-page, show-when-TotalCount-unknown, and the default-off path. --- .../Notifications/NotificationReport.razor | 5 +- .../Components/Shared/OffsetPager.razor | 23 +++++- .../Shared/OffsetPagerTests.cs | 79 +++++++++++++++++++ 3 files changed, 104 insertions(+), 3 deletions(-) diff --git a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Notifications/NotificationReport.razor b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Notifications/NotificationReport.razor index b93435a6..56d415cd 100644 --- a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Notifications/NotificationReport.razor +++ b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Notifications/NotificationReport.razor @@ -204,7 +204,8 @@ HasNextPage="@(_notifications.Count >= _pageSize)" TotalCount="_totalCount" PageSize="_pageSize" - Disabled="_loading" /> + Disabled="_loading" + HideWhenSinglePage="true" /> } @@ -326,7 +327,7 @@ @* Email bodies are plain text (design: BCC delivery, plain text). Rendered as preformatted text — never as a MarkupString, which would be an XSS vector. *@ -
@_detail.Body
} diff --git a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Shared/OffsetPager.razor b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Shared/OffsetPager.razor index 6cbdf4b8..118b43bc 100644 --- a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Shared/OffsetPager.razor +++ b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Shared/OffsetPager.razor @@ -2,8 +2,11 @@ @* Reusable offset-pagination bar. Purely presentational: the host page owns page-number state, query execution, and the HasNextPage decision. - Parameters: Page, PageChanged, HasNextPage, TotalCount, PageSize, Disabled. *@ + Parameters: Page, PageChanged, HasNextPage, TotalCount, PageSize, Disabled, + HideWhenSinglePage. *@ +@if (!IsSinglePageAndHidden) +{
+} @code { [Parameter] public int Page { get; set; } = 1; @@ -30,8 +34,25 @@ [Parameter] public int PageSize { get; set; } [Parameter] public bool Disabled { get; set; } + /// + /// When true, the whole bar is suppressed once the result set is + /// provably a single page — the conventional behaviour for a pager whose only + /// controls would be permanently disabled. Opt-in (default false) + /// because the summary span doubles as the "N total" result-count readout on + /// pages that have no other place to show it; a host that relies on that + /// readout leaves this off. + /// + [Parameter] public bool HideWhenSinglePage { get; set; } + private bool HasPrev => Page > 1; + // Hide only when single-page-ness is POSITIVELY established: a known page + // count of 0/1, sitting on page 1, with no next page. A null TotalCount + // (host cannot count) or any disagreement between the signals renders the + // bar, so the controls never vanish while a further page still exists. + private bool IsSinglePageAndHidden => + HideWhenSinglePage && PageCount is <= 1 && Page <= 1 && !HasNextPage; + private int? PageCount => TotalCount is { } t && PageSize > 0 ? (int)Math.Ceiling(t / (double)PageSize) diff --git a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Shared/OffsetPagerTests.cs b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Shared/OffsetPagerTests.cs index 4fe7d9cc..237681b2 100644 --- a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Shared/OffsetPagerTests.cs +++ b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Shared/OffsetPagerTests.cs @@ -90,6 +90,85 @@ public class OffsetPagerTests : BunitContext Assert.Contains("230 total", summary.TextContent); } + // ── HideWhenSinglePage_HidesBar_OnSinglePage ────────────────────────────── + + [Fact] + public void HideWhenSinglePage_HidesBar_OnSinglePage() + { + var cut = Render(ps => ps + .Add(p => p.Page, 1) + .Add(p => p.PageSize, 50) + .Add(p => p.TotalCount, 12) + .Add(p => p.HasNextPage, false) + .Add(p => p.HideWhenSinglePage, true)); + + Assert.Empty(cut.FindAll("[data-test='pager-prev']")); + Assert.Empty(cut.FindAll("[data-test='pager-next']")); + Assert.Empty(cut.FindAll("[data-test='pager-summary']")); + } + + // ── HideWhenSinglePage_HidesBar_OnEmptyResult ───────────────────────────── + + [Fact] + public void HideWhenSinglePage_HidesBar_OnEmptyResult() + { + var cut = Render(ps => ps + .Add(p => p.Page, 1) + .Add(p => p.PageSize, 50) + .Add(p => p.TotalCount, 0) + .Add(p => p.HasNextPage, false) + .Add(p => p.HideWhenSinglePage, true)); + + Assert.Empty(cut.FindAll("[data-test='pager-summary']")); + } + + // ── HideWhenSinglePage_ShowsBar_WhenMultiplePages ───────────────────────── + + [Fact] + public void HideWhenSinglePage_ShowsBar_WhenMultiplePages() + { + var cut = Render(ps => ps + .Add(p => p.Page, 1) + .Add(p => p.PageSize, 50) + .Add(p => p.TotalCount, 120) + .Add(p => p.HasNextPage, true) + .Add(p => p.HideWhenSinglePage, true)); + + Assert.Contains("Page 1 of 3", cut.Find("[data-test='pager-summary']").TextContent); + } + + // ── HideWhenSinglePage_ShowsBar_WhenTotalCountUnknown ───────────────────── + // TotalCount is null (the host cannot count), so single-page-ness is not + // provable — the bar must stay so the user can still reach a further page. + + [Fact] + public void HideWhenSinglePage_ShowsBar_WhenTotalCountUnknown() + { + var cut = Render(ps => ps + .Add(p => p.Page, 1) + .Add(p => p.PageSize, 50) + .Add(p => p.HasNextPage, false) + .Add(p => p.HideWhenSinglePage, true)); + + Assert.NotNull(cut.Find("[data-test='pager-summary']")); + } + + // ── HideWhenSinglePage_Off_KeepsBarVisible_OnSinglePage ─────────────────── + // Default (opt-out) behaviour: consumers that use the summary as their only + // "N total" readout keep the bar on a single page. + + [Fact] + public void HideWhenSinglePage_Off_KeepsBarVisible_OnSinglePage() + { + var cut = Render(ps => ps + .Add(p => p.Page, 1) + .Add(p => p.PageSize, 50) + .Add(p => p.TotalCount, 3) + .Add(p => p.HasNextPage, false)); + + Assert.Contains("3 total", cut.Find("[data-test='pager-summary']").TextContent); + } + // ── BothDisabled_WhenDisabled ───────────────────────────────────────────── [Fact]