316153dc98
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.
75 lines
2.7 KiB
Plaintext
75 lines
2.7 KiB
Plaintext
@namespace ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared
|
|
|
|
@* 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,
|
|
HideWhenSinglePage. *@
|
|
|
|
@if (!IsSinglePageAndHidden)
|
|
{
|
|
<div class="d-flex align-items-center gap-2">
|
|
<button class="btn btn-outline-secondary btn-sm"
|
|
data-test="pager-prev"
|
|
disabled="@(!HasPrev || Disabled)"
|
|
@onclick="OnPrevAsync">
|
|
Previous
|
|
</button>
|
|
|
|
<span data-test="pager-summary">@SummaryText</span>
|
|
|
|
<button class="btn btn-outline-secondary btn-sm"
|
|
data-test="pager-next"
|
|
disabled="@(!HasNextPage || Disabled)"
|
|
@onclick="OnNextAsync">
|
|
Next
|
|
</button>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public int Page { get; set; } = 1;
|
|
[Parameter] public EventCallback<int> PageChanged { get; set; }
|
|
[Parameter] public bool HasNextPage { get; set; }
|
|
[Parameter] public int? TotalCount { get; set; }
|
|
[Parameter] public int PageSize { get; set; }
|
|
[Parameter] public bool Disabled { get; set; }
|
|
|
|
/// <summary>
|
|
/// When <c>true</c>, 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 <c>false</c>)
|
|
/// 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.
|
|
/// </summary>
|
|
[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)
|
|
: (int?)null;
|
|
|
|
private string SummaryText
|
|
{
|
|
get
|
|
{
|
|
var text = $"Page {Page}";
|
|
if (PageCount is { } pc) text += $" of {pc}";
|
|
if (TotalCount is { } total) text += $" · {total} total";
|
|
return text;
|
|
}
|
|
}
|
|
|
|
private Task OnPrevAsync() => PageChanged.InvokeAsync(Page - 1);
|
|
private Task OnNextAsync() => PageChanged.InvokeAsync(Page + 1);
|
|
}
|