From 7461ce8b6189b2e5da05a4958448b738bb9fde01 Mon Sep 17 00:00:00 2001 From: Alex Fedotyev <61838744+alex-fedotyev@users.noreply.github.com> Date: Tue, 1 Dec 2026 20:49:43 +0000 Subject: [PATCH 1/2] feat(app): fit columns in tables that don't save their widths Double-clicking a column's resize handle now fits the column in tables without a tableId too: dashboard search tiles, the side panel's surrounding context, event patterns, the Kubernetes panels and the chart preview. Those tables kept resized widths inside TanStack, where the last column's fill width and the table's minimum width never saw them, so a fitted or dragged column left an empty strip on the right of the table. Their widths now live in the component's state while it's mounted, and the last column takes up the difference. Nothing new is saved: tables with a tableId keep saving to local storage, and the rest still forget their widths when they unmount. Co-Authored-By: Claude Opus 5.5 --- .changeset/column-fit-unsaved-tables.md | 8 ++++ packages/app/src/components/DBRowTable.tsx | 27 ++++++------ .../components/__tests__/DBRowTable.test.tsx | 41 +++++++++++++++---- .../tests/e2e/components/TableComponent.ts | 16 ++++++++ .../e2e/features/search/column-fit.spec.ts | 37 +++++++++++++++++ 5 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 .changeset/column-fit-unsaved-tables.md diff --git a/.changeset/column-fit-unsaved-tables.md b/.changeset/column-fit-unsaved-tables.md new file mode 100644 index 000000000..cdb0d4d90 --- /dev/null +++ b/.changeset/column-fit-unsaved-tables.md @@ -0,0 +1,8 @@ +--- +'@hyperdx/app': patch +--- + +feat: double-click a column's resize handle to fit it to its content in tables +that don't save their column widths, such as dashboard search tiles and the side +panel's surrounding context. Their last column now fills the table after a fit +or a drag, instead of leaving an empty strip on the right. diff --git a/packages/app/src/components/DBRowTable.tsx b/packages/app/src/components/DBRowTable.tsx index b59e56770..81ea3b51d 100644 --- a/packages/app/src/components/DBRowTable.tsx +++ b/packages/app/src/components/DBRowTable.tsx @@ -503,9 +503,19 @@ export const RawLogTable = memo( const expandInlineOnRowClick = prefersInlineExpand && (!canOpenSidePanel || highlightedLineId == null); - const [columnSizeStorage, setColumnSizeStorage] = useLocalStorage< + const [storedColumnSizes, setStoredColumnSizes] = useLocalStorage< Record >(`${tableId}-column-sizes`, {}); + // Without a tableId, widths aren't saved and only last while the table is + // mounted. Keeping them here rather than inside TanStack lets the last + // column's fill width follow a resized column. + const [unsavedColumnSizes, setUnsavedColumnSizes] = useState< + Record + >({}); + const columnSizeStorage = tableId ? storedColumnSizes : unsavedColumnSizes; + const setColumnSizeStorage = tableId + ? setStoredColumnSizes + : setUnsavedColumnSizes; //once the user has scrolled within 500px of the bottom of the table, fetch more data if there is any const FETCH_NEXT_PAGE_PX = 500; @@ -844,13 +854,10 @@ export const RawLogTable = memo( onColumnSizingChange: onColumnSizingChange, }; - return tableId - ? { ...initReactTableProps, ...columnSizeProps } - : initReactTableProps; + return { ...initReactTableProps, ...columnSizeProps }; }, [ columns, dedupedRows, - tableId, sortOrder, enableSorting, onSortingChange, @@ -1127,14 +1134,8 @@ export const RawLogTable = memo( key={header.id} header={header} isLast={isLast} - // Only saved widths feed the last column's fill - // width, so elsewhere a fit would leave the rows - // out of line with the header. - onFitToContent={ - tableId - ? () => - fitColumnToContent(header.column.id, isLast) - : undefined + onFitToContent={() => + fitColumnToContent(header.column.id, isLast) } onRemoveColumn={ onRemoveColumn && diff --git a/packages/app/src/components/__tests__/DBRowTable.test.tsx b/packages/app/src/components/__tests__/DBRowTable.test.tsx index 297ac0d7c..45da8118a 100644 --- a/packages/app/src/components/__tests__/DBRowTable.test.tsx +++ b/packages/app/src/components/__tests__/DBRowTable.test.tsx @@ -391,6 +391,12 @@ describe('RawLogTable', () => { ), ); + // Column widths are only saved for tables with a tableId. + const savedColumnSizeKeys = () => + Object.keys(window.localStorage).filter(key => + key.endsWith('-column-sizes'), + ); + const storedSizes = (): unknown => JSON.parse(window.localStorage.getItem('t1-column-sizes') ?? '{}'); @@ -470,22 +476,43 @@ describe('RawLogTable', () => { expect(getHeaderCell(container, 'col2').style.width).toBe('800px'); }); - it('does not fit columns of a table that does not save its widths', async () => { + it('fits a column of a table that does not save its widths, and the last column fills the rest', async () => { const { container } = renderWithMantine( , ); - const handle = within(getHeaderCell(container, 'col1')).getByTestId( - 'column-resize-handle', - ); - expect(handle.getAttribute('title')).toBeNull(); await fitColumn(container, 'col1'); - expect(getHeaderCell(container, 'col1').style.width).toBe('160px'); - expect(getHeaderCell(container, 'col2').style.width).toBe('840px'); + expect(getHeaderCell(container, 'col1').style.width).toBe('80px'); + expect(getHeaderCell(container, 'col2').style.width).toBe( + `${TABLE_WIDTH - 80}px`, + ); + expect(savedColumnSizeKeys()).toEqual([]); + }); + + it('keeps the last column filling the rest after a drag in a table that does not save its widths', () => { + const { container } = renderWithMantine( + , + ); + + // From the default 160px, 40px to the right + fireEvent.mouseDown( + within(getHeaderCell(container, 'col1')).getByTestId( + 'column-resize-handle', + ), + { clientX: 100 }, + ); + fireEvent.mouseMove(document, { clientX: 140 }); + fireEvent.mouseUp(document, { clientX: 140 }); + + expect(getHeaderCell(container, 'col1').style.width).toBe('200px'); + expect(getHeaderCell(container, 'col2').style.width).toBe( + `${TABLE_WIDTH - 200}px`, + ); + expect(savedColumnSizeKeys()).toEqual([]); }); }); diff --git a/packages/app/tests/e2e/components/TableComponent.ts b/packages/app/tests/e2e/components/TableComponent.ts index e8f77d95b..8e0a67d49 100644 --- a/packages/app/tests/e2e/components/TableComponent.ts +++ b/packages/app/tests/e2e/components/TableComponent.ts @@ -390,4 +390,20 @@ export class TableComponent { .first() .evaluate(label => label.scrollWidth > label.clientWidth); } + + /** + * Width the columns leave empty on the right of the table + */ + getEmptyWidthRightOfColumns() { + return this.tableContainer.evaluate(container => { + const headerRights = Array.from( + container.querySelectorAll('thead th'), + ).map(header => header.getBoundingClientRect().right); + return ( + container.getBoundingClientRect().left + + container.clientWidth - + Math.max(...headerRights) + ); + }); + } } diff --git a/packages/app/tests/e2e/features/search/column-fit.spec.ts b/packages/app/tests/e2e/features/search/column-fit.spec.ts index 17bf48f9a..67c554491 100644 --- a/packages/app/tests/e2e/features/search/column-fit.spec.ts +++ b/packages/app/tests/e2e/features/search/column-fit.spec.ts @@ -1,3 +1,4 @@ +import { TableComponent } from '../../components/TableComponent'; import { SearchPage } from '../../page-objects/SearchPage'; import { expect, test } from '../../utils/base-test'; @@ -105,4 +106,40 @@ test.describe('Search results column fit', { tag: '@search' }, () => { ); }, ); + + test( + 'fits a column of the surrounding context table, which does not save its widths', + { tag: ['@local-mode'] }, + async ({ page }) => { + await searchPage.table.clickFirstRow(); + await expect(searchPage.sidePanel.tabs).toBeVisible(); + await searchPage.sidePanel.clickTab('context'); + const contextTable = new TableComponent( + page, + '[data-testid="side-panel-tab-context"] [data-testid="search-results-table"]', + ); + await expect( + contextTable.container + .locator('tbody [data-column-id="ServiceName"]') + .first(), + ).toBeVisible(); + await contextTable.dragColumnResizeHandle('ServiceName', -100); + await expect + .poll(() => contextTable.countTruncatedCells('ServiceName')) + .toBeGreaterThan(0); + // The last column takes the space the squeezed column gave up + await expect + .poll(() => contextTable.getEmptyWidthRightOfColumns()) + .toBeLessThan(1); + + await contextTable.fitColumnToContent('ServiceName'); + + await expect + .poll(() => contextTable.countTruncatedCells('ServiceName')) + .toBe(0); + await expect + .poll(() => contextTable.getEmptyWidthRightOfColumns()) + .toBeLessThan(1); + }, + ); }); From 57b8bbd6e561104c9d92991b024a3b144dfa4298 Mon Sep 17 00:00:00 2001 From: Alex Fedotyev <61838744+alex-fedotyev@users.noreply.github.com> Date: Tue, 1 Dec 2026 21:31:29 +0000 Subject: [PATCH 2/2] test(app): cover the last column refilling a table that doesn't save widths Double-clicking the last column's handle in a table without a tableId returns it to filling the table, the same as in tables that save their widths, and stores nothing. Co-Authored-By: Claude Opus 5.5 --- .../components/__tests__/DBRowTable.test.tsx | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/app/src/components/__tests__/DBRowTable.test.tsx b/packages/app/src/components/__tests__/DBRowTable.test.tsx index 45da8118a..b3ec9dc72 100644 --- a/packages/app/src/components/__tests__/DBRowTable.test.tsx +++ b/packages/app/src/components/__tests__/DBRowTable.test.tsx @@ -493,6 +493,30 @@ describe('RawLogTable', () => { expect(savedColumnSizeKeys()).toEqual([]); }); + it('returns the last column to filling a table that does not save its widths', async () => { + const { container } = renderWithMantine( + , + ); + + // From the 840px it fills, 140px to the left + fireEvent.mouseDown( + within(getHeaderCell(container, 'col2')).getByTestId( + 'column-resize-handle', + ), + { clientX: 840 }, + ); + fireEvent.mouseMove(document, { clientX: 700 }); + fireEvent.mouseUp(document, { clientX: 700 }); + expect(getHeaderCell(container, 'col2').style.width).toBe('700px'); + + await fitColumn(container, 'col2'); + + expect(getHeaderCell(container, 'col2').style.width).toBe( + `${TABLE_WIDTH - 160}px`, + ); + expect(savedColumnSizeKeys()).toEqual([]); + }); + it('keeps the last column filling the rest after a drag in a table that does not save its widths', () => { const { container } = renderWithMantine( ,