Skip to content

feat(app): double-click a column's resize handle to fit it to its content - #3819

Open
alex-fedotyev wants to merge 4 commits into
mainfrom
alex/HDX-6190-column-fit
Open

alex-fedotyev wants to merge 4 commits into
mainfrom
alex/HDX-6190-column-fit

Conversation

@alex-fedotyev

@alex-fedotyev alex-fedotyev commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Double-clicking a column's resize handle in the search results table now fits the column to its content, the same gesture spreadsheets and most data grids use. Until now the only way to size a column was to drag it.

  • Fits both ways. The column takes the width of its widest rendered cell, header label included, so a column wider than its values gets narrower and one that cuts its values off gets wider.
  • Capped. A fitted column stops at 600px or half the visible table width, whichever is smaller, so one long value can't push the other columns out of view. The existing 50px minimum still applies.
  • The last column fills the table again. It already takes the space the other columns leave, so double-clicking it clears a width it was dragged to. Fitting it to its content would leave a gap on the right when narrower, or scroll the table sideways when wider.
  • Saved like a drag. The width is stored with the table's other column widths, and Reset Column Widths clears it.

It works in the tables that save their column widths: search results, and the Logs tab of a trace's side panel. Tables that only keep widths in memory (surrounding context, event patterns, the Kubernetes and dashboard panels) don't feed a resized column back into the last column's fill width, so a fit there would leave the rows out of line with the header. They keep drag resizing only, which already drifts the same way. Dashboard table tiles share the header component but size their columns from the tile width, so they keep today's behavior too.

How it measures. TanStack Table 8.7.9 has no auto-size, so measureColumnContentWidth (new, in DBTable/columnFit.ts) clones the column's header cell and each rendered body cell out of view at width: max-content and takes the widest. Measuring the DOM rather than the row data picks up how cells actually render (dates in the chosen time zone, log levels, search highlights, the content font size setting) without duplicating the cell renderers, and it works with wrap lines on. All the clones go in before the first read, so the table lays out once. Only mounted rows count (the visible ones plus the virtualizer's overscan), which is also how AG Grid's auto-size works. Cells of tables nested in an expanded row are skipped.

Column sizing handler. onColumnSizingChange called TanStack's updater with no previous state and merged the result into the stored sizes, so a stored width could be set but never removed: column.resetSize() would have thrown Cannot destructure '_ref2' as it is undefined. It now applies the updater to the stored sizes, which is what lets the last column drop its width. Drags go through the same updater and behave as before, and the handler no longer needs any.

Screenshots or video

Search on the demo server (Demo Logs, 1440 x 900). ServiceName dragged down to 70px so the service names are cut off, then its resize handle double-clicked. On main the column stays at 70px. On this branch it fits its widest value at 117px.

Before (main) After
before light after light
before dark after dark

How to reproduce

Starting point: the Vercel preview on this PR, or yarn app:dev:local → onboarding → "Connect to Demo Server".

On main:

  1. Open Search on Demo Logs.
  2. Drag the resize handle at the right edge of the ServiceName header to the left until the service names are cut off.
  3. Double-click the same handle. Nothing changes.

On this branch:

  1. Repeat the steps above. The double-click widens ServiceName until every service name shows in full.
  2. Drag ServiceName wider than its values and double-click the handle again. It narrows to its widest value.
  3. Put Body in the middle of the SELECT (for example Timestamp, Body, ServiceName) and double-click its handle. It stops at half the table width.
  4. With the default SELECT, drag the last column (Body) narrower and double-click its handle. It fills the table again.
  5. Reload. The fitted widths stay, and Reset Column Widths (the rotate icon at the end of the header) clears them.

How to test on Vercel preview

Preview routes: /search

Steps:

  1. Open /search and click "Connect to Demo Server" if prompted.
  2. Wait for the results table to show rows.
  3. Drag the resize handle (data-testid="column-resize-handle") at the right edge of the "ServiceName" column header about 90px to the left, so the service names are cut off with "…".
  4. Double-click the same resize handle.
  5. Verify the "ServiceName" column is wider than before the double-click and no service name in it is cut off with "…".

Test plan

  • yarn lint, yarn tsc --noEmit and yarn lint:styles in packages/app, and yarn knip
  • unit: columnFit.test.ts covers the widest cell with the header included, cell padding, skipping nested tables, cleanup when a read throws, and the cap. A new Fit column to content block in DBRowTable.test.tsx narrows and saves a column, caps one at half the table (read when the handle is double-clicked), returns the last column to filling, and leaves tables that don't save their widths to drag resizing. saves the width a column is dragged to covers drags under the retyped column sizing handler. Reverting any one part of the change (the double-click wiring, the measurement, the cap and minimum, the last-column rule, the tableId check, or the sizing handler fix) fails at least one of them.
  • e2e: tests/e2e/features/search/column-fit.spec.ts widens a squeezed column, narrows a widened one, shows the whole header label of a column whose header is wider than its values, returns the last column to filling, and keeps a fitted width after a reload. It passes locally in local mode, and every test fails with the double-click handler removed.
  • manual on the Vercel preview with the demo server: the steps above in light and dark theme, and with wrap lines on, where wrapped values fit their longest line and long ones stop at the cap.
  • viewport: in a 1440 x 900 window the table is 956px wide, and Body in the middle of the SELECT fits to 478px. In a 1024 x 768 window the table is 540px wide, and it fits to 270px.

References

  • Linear Issue: HDX-6190
  • Related PRs: none

[ui-states: allow] Fitting only changes a column's width. The table's empty, loading and error states are unchanged, and a column with no rendered cells is left as it is.

…tent

Double-clicking the resize handle on a search results column sets the
column to the width of its widest rendered cell, header included, so it
gets narrower or wider to match what it shows. A fitted column stops at
600px or half the visible table width, whichever is smaller. The last
column already fills the space the others leave, so double-clicking it
clears a dragged width and it fills the table again.

The fitted width is saved and reset like a dragged one. Clearing the
last column's width needs the column sizing handler to apply TanStack's
updater to the stored sizes. It called the updater with no previous
state and merged the result in, so a stored size could never be removed.
The handler is now typed without `any`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 25, 2026 1:17am UTC
hyperdx-storybook Ready Ready Preview Nov 25, 2026 1:17am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fbf843d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.12%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 479 passed • 1 skipped • 1082s

Status Count
✅ Passed 479
❌ Failed 0
⚠️ Flaky 14
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@alex-fedotyev
alex-fedotyev marked this pull request as ready for review November 25, 2026 00:41
@alex-fedotyev
alex-fedotyev requested a review from a team as a code owner November 25, 2026 00:41
@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 3
  • Production lines changed: 142 (+ 541 in test files, excluded from tier calculation)
  • Branch: alex/HDX-6190-column-fit
  • Author: alex-fedotyev

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

✅ No issues found.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This is a well-scoped, well-tested UI feature. The onColumnSizingChange rewrite to functionalUpdate(updater, sizes) correctly fixes the prior resetSize() crash and preserves drag behavior (verified: TanStack's updater is applied to current stored sizes, so key removal propagates and the last column falls back to its fill width). The DOM measurement inserts all clones before the first getBoundingClientRect read, so layout runs once rather than per-cell, and the clone candidate set is bounded by the virtualizer's mounted window, not the dataset — no performance regression on this double-click gesture. The four P3 items raised in prior review (the finally-block cleanup, reading clientWidth at double-click time, dropping the contentWidth === 0 guard, and measuring the full header row) are all present in the current diff.

🟡 P2 — recommended

  • packages/app/src/components/DBTable/columnFit.ts:22 — measureColumnContentWidth measures each matched cell's firstElementChild, an implicit contract that is also relied on by two render sites (TableHeader.tsx <th data-column-id> and DBRowTable.tsx:1337 <div data-column-id>); a future change to either cell's inner DOM nesting would silently mis-measure or skip the column with no test failure, since the unit test builds its own fixture markup rather than rendering the real cells.
    • Fix: Add a component-level assertion that the real rendered header and body cells expose their measurable content as firstElementChild, or centralize the content-node lookup so the contract lives in one place.
🔵 P3 nitpicks (1)
  • packages/app/src/components/DBTable/columnFit.ts:66 — when visibleTableWidth is 0 (table hidden or not yet laid out at double-click time), getFittedColumnWidth resolves its cap to max(MIN_COLUMN_WIDTH, min(600, 0)) = 50, so the column snaps to the 50px minimum rather than being left unchanged; harmless in practice because the gesture requires a visible handle, but the clamp silently masks a degenerate input.
    • Fix: Early-return the column's current width (no-op) when visibleTableWidth <= 0.

Reviewers (3 of 11 completed at synthesis): performance, agent-native, learnings-researcher. Correctness, testing, maintainability, project-standards, adversarial, kieran-typescript, julik-frontend-races, and previous-comments were dispatched but had not returned when structured output was required; the findings above reflect the completed reviewers plus orchestrator-level analysis of the full diff.

Testing gaps: No regression test asserts that the mousedown-initiated resize drag and the double-click fit do not interfere on the shared handle; the e2e suite exercises drag and double-click as separate gestures only. The component tests rely on a hand-built DOM fixture and mocked getBoundingClientRect/clientWidth, so they would not catch a drift between the fixture markup and the real cell DOM structure the measurement depends on.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

- Read the visible table width when the handle is double-clicked,
  instead of the last width the resize observer reported.
- Drop the empty-measurement guard. The header always has width, so the
  measurement is never 0 for the column being fitted.
- Remove the measuring copies in a finally block, so a failed read
  cannot leave them in the table.
- Note at both render sites what the measurement relies on, and why it
  measures the whole header row: the remove button and resize handle take
  room the label needs to show in full.
- Test that a column whose header is wider than its values shows the
  whole label after a fit, the read-time width cap, and cleanup when a
  read throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alex-fedotyev

Copy link
Copy Markdown
Contributor Author

Review findings, addressed in 110a997:

  • Guards that can't be true (DBRowTable.tsx, claude-review P3): dropped the contentWidth === 0 guard. The ref check stays, because it narrows tableRef.current and tableContainerRef from | null; the alternative is a non-null assertion.
  • Header measured with its remove button and resize handle (columnFit.ts, deep-review P3): not changed. Both sit in the header row next to the label and take space even while the remove button is invisible, so a column fitted to the label alone cuts the label off. The new e2e test shows the whole header label of a column whose header is wider than its values squeezes SeverityText, fits it and checks the label shows in full. It fails when only the label is measured. Both render sites now note what the measurement relies on.
  • Stale containerWidth (DBRowTable.tsx, deep-review P3): fixed. The fit reads the container's clientWidth when the handle is double-clicked. tableRef.current.clientWidth would be the full table width, which is wider than the visible area once the table scrolls sideways. Covered by caps a fitted column by the table width at the time of the double-click.
  • Cleanup outside finally (columnFit.ts, deep-review P3): fixed. The measuring copies are removed in a finally block, covered by removes its copies even when reading a width throws.

Tables without a tableId keep column widths in TanStack's own state,
which the last column's fill width and the table's min width don't
read. A fit there narrowed a column without the last column growing to
match, so the rows fell out of line with the header. Dragging in those
tables already drifts the same way; this keeps the new gesture out of
it.

Also tests that a dragged width is still saved under the retyped column
sizing handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alex-fedotyev

Copy link
Copy Markdown
Contributor Author

Second review round, in fbf843d:

  • Tables without a tableId (claude-review P2 on DBRowTable.tsx, deep-review P3 on tableMinWidth): fixed by offering the fit only when the table saves its widths. Replied inline.
  • Only mounted rows are measured (deep-review P2): keeping as is. The fit narrows columns as well as widening them, and there are nearly always rows outside the virtualizer window, so "never shrink while rows are unmounted" would make it widen-only. Fitting to the rendered rows matches AG Grid's auto-size, and a double-click after scrolling refits.
  • Positional firstElementChild (deep-review P2): keeping as is. Both render sites say what the measurement relies on, and the e2e tests check that no value or header label is cut off after a fit, which catches the fit measuring the wrong node.
  • Jitter between the two clicks (P3): the fit writes last, so the saved width is the fitted one.
  • Cloning chart cells, duplicate ids (P3): chart columns only appear in the patterns table, which has no tableId and so no fit. The copies only exist inside one synchronous call and are removed in finally.
  • Fonts loading late (P3): fonts have loaded by the time someone double-clicks a header. The e2e helper waits because it fits right after page load.
  • Untested guards (P3): both are type guards that no reachable path hits.
  • Dragged widths under the retyped handler (testing gap): added saves the width a column is dragged to.

That's two rounds of automated review, so I'll leave anything further for a maintainer.

@pulpdrew pulpdrew 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.

LGTM! Very convenient. It would be great if this also worked on dashboard search tiles in the future

This branch was successfully deployed

2 active deployments
Preview – hyperdx-storybook — fbf843d6 Deployed Nov 25, 2026 by vercel[bot]
Preview – hyperdx-oss — fbf843d6 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants