Skip to content

Commit 0af8e36

Browse files
authored
Fix resource table name column collapse (#822)
1 parent bba06ed commit 0af8e36

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

packages/k8s-ui/src/components/resources/ResourcesView.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ const TAILWIND_WIDTH_TO_PX: Record<string, number> = {
229229
'w-48': 192, 'w-56': 224, 'w-64': 256,
230230
}
231231

232+
const COMPARE_COLUMN_WIDTH = 36
233+
const COMPARE_COLUMN_STYLE: React.CSSProperties = {
234+
width: COMPARE_COLUMN_WIDTH,
235+
minWidth: COMPARE_COLUMN_WIDTH,
236+
maxWidth: COMPARE_COLUMN_WIDTH,
237+
}
238+
232239
function getColumnMinWidth(col: Column): number {
233240
if (col.minWidth) return col.minWidth
234241
if (!col.width) return 200 // Name column (no width class) gets wider minimum
@@ -3367,6 +3374,18 @@ export function ResourcesView({
33673374
return allColumns.filter(c => visibleColumns.has(c.key))
33683375
}, [allColumns, visibleColumns])
33693376

3377+
// Fixed-width columns can consume the table's flexible space and collapse
3378+
// the required name column. Keep a real table minimum and let the container
3379+
// scroll horizontally when the viewport is too narrow.
3380+
const tableMinWidth = useMemo(() => {
3381+
const compareColumnWidth = compareMode ? COMPARE_COLUMN_WIDTH : 0
3382+
const baseMinWidth = columns.reduce((sum, col) => sum + (columnWidths[col.key] || getColumnMinWidth(col)), compareColumnWidth)
3383+
const flexibleNameColumn = columns.find(col => col.key === 'name' && !columnWidths[col.key])
3384+
3385+
if (!hasResizedColumns || !flexibleNameColumn) return baseMinWidth
3386+
return baseMinWidth + getColumnMinWidth(flexibleNameColumn)
3387+
}, [columns, columnWidths, compareMode, hasResizedColumns])
3388+
33703389
// Stable virtuoso components — memoized to avoid remounting the table on every render
33713390
const virtuosoComponents = useMemo(() => ({
33723391
Table: React.forwardRef<HTMLTableElement, React.TableHTMLAttributes<HTMLTableElement>>(function VirtuosoTable(props, ref) {
@@ -3375,7 +3394,7 @@ export function ResourcesView({
33753394
{...props}
33763395
ref={ref}
33773396
className="w-full"
3378-
style={{ ...props.style, tableLayout: 'fixed' }}
3397+
style={{ ...props.style, tableLayout: 'fixed', minWidth: tableMinWidth }}
33793398
>
33803399
<colgroup>
33813400
{/*
@@ -3385,7 +3404,7 @@ export function ResourcesView({
33853404
the missing entry by stealing width from a sized neighbour
33863405
— typically blowing this narrow column out to ~200px.
33873406
*/}
3388-
{compareMode && <col style={{ width: 36 }} />}
3407+
{compareMode && <col style={{ width: COMPARE_COLUMN_WIDTH }} />}
33893408
{columns.map(col => (
33903409
<col
33913410
key={col.key}
@@ -3403,7 +3422,7 @@ export function ResourcesView({
34033422
)
34043423
}),
34053424
TableRow: VirtuosoTableRow,
3406-
}), [columns, columnWidths, hasResizedColumns, compareMode])
3425+
}), [columns, columnWidths, hasResizedColumns, compareMode, tableMinWidth])
34073426

34083427
// Calculate filter options with counts based on current resources (before filtering)
34093428
const filterOptions = useMemo(() => {
@@ -3949,7 +3968,7 @@ export function ResourcesView({
39493968

39503969
{/* Table */}
39513970
<div
3952-
className="flex-1 overflow-y-auto overflow-x-hidden relative"
3971+
className="flex-1 overflow-auto relative"
39533972
ref={tableContainerRef}
39543973
onClick={(e) => {
39553974
if (e.target === e.currentTarget && selectedResource) {
@@ -4062,7 +4081,7 @@ export function ResourcesView({
40624081
// Inline px width — under `table-layout:fixed`,
40634082
// `w-9` is a hint the browser absorbs into leftover
40644083
// row width on an icon-only column.
4065-
style={{ width: 36, minWidth: 36, maxWidth: 36 }}
4084+
style={COMPARE_COLUMN_STYLE}
40664085
className="px-2 py-3 text-xs font-medium uppercase tracking-wide bg-theme-base border-b border-r-subtle border-theme-border text-center text-skyhook-400"
40674086
title="Compare mode"
40684087
>
@@ -4344,7 +4363,7 @@ function ResourceRowCells({ resource, kind, group, columns, extraColumnsByKey, h
43444363
<td
43454364
onClick={onClick}
43464365
onMouseEnter={onMouseEnter}
4347-
style={{ width: 36, minWidth: 36, maxWidth: 36 }}
4366+
style={COMPARE_COLUMN_STYLE}
43484367
className={clsx('px-2 py-3 border-b-subtle cursor-pointer text-center align-middle transition-colors', rowHighlight)}
43494368
>
43504369
{pickedSide ? (

0 commit comments

Comments
 (0)