Table: Fields and Column Widths arrays can get out-of-sync on length (#109997)

* Table: Fields and Column Widths arrays can get out-of-sync on length

* slight cleanup for e2e

* remove a couple of page desctructures
This commit is contained in:
Paul Marbach 2025-08-21 16:49:53 -04:00 committed by GitHub
parent a180601968
commit 61c160b30f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 2 deletions

View File

@ -133,6 +133,15 @@ test.describe('Panels test: Table - Kitchen Sink', { tag: ['@panels', '@table']
await displayNameInput.fill('State (renamed)');
await displayNameInput.press('Enter');
expect(page.getByRole('row').nth(0)).toContainText('State (renamed)');
// toggle the "State" column visibility again to hide it again. this confirms that we avoid bugs related to
// array lengths between the fields array and the column widths array.
await hideStateColumnSwitch.click();
expect(page.getByRole('row').nth(0)).not.toContainText('State');
// since the previous assertion is just for the absence of text, let's also confirm that the table is
// actually still on the page and that an error has not been throw.
await waitForTableLoad(page);
});
// we test niche cases for sorting, filtering, pagination, etc. in a unit tests already.

View File

@ -551,6 +551,20 @@ describe('TableNG hooks', () => {
expect(heightFn).toHaveBeenCalledWith('Longer name that needs wrapping', 26, modifiedFields[0], -1, 22);
});
it('does not throw if a field has been deleted but the colWidth has not yet been updated', () => {
const { fields } = setupData();
const { result } = renderHook(() => {
return useHeaderHeight({
fields,
columnWidths: [100, 100, 100, 100],
enabled: true,
typographyCtx,
sortColumns: [],
});
});
expect(result.current).toBe(28);
});
});
describe('useRowHeight', () => {

View File

@ -353,13 +353,19 @@ export function useHeaderHeight({
const columnAvailableWidths = useMemo(
() =>
columnWidths.map((c, idx) => {
if (idx >= fields.length) {
return 0; // no width available for this column yet
}
let width = c - 2 * TABLE.CELL_PADDING - TABLE.BORDER_RIGHT;
const field = fields[idx];
// filtering icon
if (fields[idx]?.config?.custom?.filterable) {
if (field.config?.custom?.filterable) {
width -= perIconSpace;
}
// sorting icon
if (sortColumns.some((col) => col.columnKey === getDisplayName(fields[idx]))) {
if (sortColumns.some((col) => col.columnKey === getDisplayName(field))) {
width -= perIconSpace;
}
// type icon