Skip to content

servcheck: keep legend chips equal width using the longest label - #129

Merged
TheWitness merged 4 commits into
mainfrom
feature/legend-equal-chips
Oct 7, 2026
Merged

TheWitness merged 4 commits into
mainfrom
feature/legend-equal-chips

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Description

Brings the servcheck status legend in line with the equal-width chip refinement already applied to the Monitor, Thold and Syslog legends.

servcheck's legend was already rendered as chips, but with min-width: 0, so the chips could shrink below their labels and overflow when the row got tight. CSS can't measure the widest sibling, so servcheck_legend() now computes the longest label and emits it as a --servcheck-chip-min CSS variable (calc(<longest>ch + 1.5rem)); css/common.css uses that as a shared min-width (falling back to max-content).

Because every chip shares the same minimum, the equal flex-grow keeps them equal width, and they wrap as a tidy grid. white-space: nowrap is retained, so labels never clip.

Related Issue

Consistency follow-up to the chip-legend treatment across the Monitor/Thold/Syslog plugins.

Motivation and Context

Keeps the legend reading as a clean, uniform key rather than a row of mismatched (or clipped) chip widths as it wraps.

How Has This Been Tested?

  • php -l clean on includes/functions.php, the new test, and the bootstrap.
  • css/common.css is brace-balanced.
  • Added includes/functions.php to the coverage <source> with no-op html_start_box()/html_end_box() bootstrap stubs and a new tests/Unit/ServcheckLegendTest.php that renders servcheck_legend() and asserts one chip per state plus the --servcheck-chip-min container, so the changed renderer lines are covered by the patch-coverage gate. No new translatable strings (the labels come from includes/arrays.php).

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the code style of this project.

The status legend already used the chip design but with min-width:0, so chips could shrink below their labels (overflow) when the row got tight. servcheck_legend() now computes the longest label and emits it as a --servcheck-chip-min CSS variable (calc(<longest>ch + 1.5rem)); css/common.css uses it as a shared min-width (falling back to max-content), matching the Monitor/Thold/Syslog legends so chips stay equal width as the legend wraps. Added includes/functions.php to the coverage <source> with no-op html_start_box/html_end_box bootstrap stubs and a new ServcheckLegendTest so the changed renderer lines are covered by the patch-coverage gate.
Copilot AI balanced review requested due to automatic review settings October 7, 2026 13:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Wrapped flex rows do not preserve equal chip widths, and the new test does not verify the calculated width.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

Updates the servcheck status legend to size chips from the longest label.

Changes:

  • Computes and applies a shared chip minimum width.
  • Adds renderer coverage and supporting test stubs.
  • Updates coverage configuration and changelog.
File Description
includes/​functions.php Computes the legend chip width.
css/​common.css Applies the shared minimum width.
tests/​Unit/​ServcheckLegendTest.php Tests legend rendering.
tests/​bootstrap-unit.php Adds HTML helper stubs.
phpunit.xml Adds renderer coverage.
CHANGELOG.md Documents the refinement.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread css/common.css Outdated
Comment thread tests/Unit/ServcheckLegendTest.php
Comment thread tests/Unit/ServcheckLegendTest.php Outdated
xmacan
xmacan previously approved these changes Oct 7, 2026
…act chip min

Follow-up on the longest-label chip work: the flex: 1 1 0 + flex-wrap layout distributes free space per wrapped line, so a partial last row stretched its chips wider than full rows. Switch .servcheck_legend to a grid (repeat(auto-fill, minmax(var(--servcheck-chip-min), 1fr))) so every chip shares an equal column across all rows. The test now asserts the exact calc(Nch + 1.5rem) value instead of just the calc( prefix.
…to the legend test

Review follow-up (#129): auto-fit collapses empty tracks so chips fill the legend width on a single row while staying equal across wrapped rows. The new ServcheckLegendTest.php now carries the repository's standard GPL v2 header (matching CspNonceTest.php).
Defence-in-depth: wrap the legend chip display text in html_escape() so markup or HTML entities in a translated label cannot alter the legend DOM. Applied consistently across the thold/monitor/servcheck/mactrack/syslog fleet legends. The chip-min sizing still measures the unescaped label length, so layout is unchanged.
@TheWitness
TheWitness merged commit db47364 into main Oct 7, 2026
3 checks passed
@TheWitness
TheWitness deleted the feature/legend-equal-chips branch October 7, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants