Skip to content

Commit 4b141b9

Browse files
committed
Fix last table column resizing
1 parent 1e9cc8b commit 4b141b9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

frontend/components/table/DatasetTable.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const DEFAULT_COL_WIDTH = 180;
2121
const MIN_COL_WIDTH = 80;
2222
const ROW_HEIGHT = 34;
2323
const GHOST_ROW_COUNT = 50;
24+
const LAST_COLUMN_RESIZE_GUTTER = 160;
2425

2526
const columnHelper = createColumnHelper<DatasetRow>();
2627

@@ -68,6 +69,7 @@ export function DatasetTable({
6869
selection: Selection;
6970
}) {
7071
const tableContainerRef = useRef<HTMLDivElement>(null);
72+
const previousResizingColumnIdRef = useRef<string | false>(false);
7173
const [containerHeight, setContainerHeight] = useState(600);
7274

7375
useEffect(() => {
@@ -112,8 +114,16 @@ export function DatasetTable({
112114
const isBuilding = dataset.status === "building";
113115
const displayCount = isBuilding ? Math.max(tableRows.length, GHOST_ROW_COUNT) : tableRows.length;
114116
const totalWidth = columnWidths.reduce((sum, w) => sum + w, 0);
117+
const tableContentWidth = totalWidth + LAST_COLUMN_RESIZE_GUTTER;
115118
const resizingColumnId = table.getState().columnSizingInfo.isResizingColumn;
116119

120+
useEffect(() => {
121+
if (previousResizingColumnIdRef.current && !resizingColumnId) {
122+
persistWidths();
123+
}
124+
previousResizingColumnIdRef.current = resizingColumnId;
125+
}, [resizingColumnId, persistWidths]);
126+
117127
const toggleRow = useCallback(
118128
(id: string, shiftKey: boolean) => {
119129
if (shiftKey) selection.shiftToggle(id);
@@ -143,7 +153,7 @@ export function DatasetTable({
143153
if (resizingColumnId) persistWidths();
144154
}}
145155
>
146-
<div style={{ minWidth: totalWidth }}>
156+
<div style={{ minWidth: tableContentWidth }}>
147157
<TableHeader
148158
headers={headers}
149159
columns={dataset.columns}

0 commit comments

Comments
 (0)