Skip to content

Commit fe6ad27

Browse files
fix(VirtualTable): make table resizeable by default (#772)
1 parent 7b8e473 commit fe6ad27

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/components/VirtualTable/TableHead.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import type {
66
} from '../../utils/hooks/useTableResize';
77

88
import type {Column, OnSort, SortOrderType, SortParams} from './types';
9-
import {ASCENDING, DEFAULT_SORT_ORDER, DEFAULT_TABLE_ROW_HEIGHT, DESCENDING} from './constants';
9+
import {
10+
ASCENDING,
11+
DEFAULT_RESIZEABLE,
12+
DEFAULT_SORT_ORDER,
13+
DEFAULT_TABLE_ROW_HEIGHT,
14+
DESCENDING,
15+
} from './constants';
1016
import {b} from './shared';
1117

1218
const COLUMN_NAME_HTML_ATTRIBUTE = 'data-columnname';
@@ -45,6 +51,7 @@ const ColumnSortIcon = ({sortOrder, sortable, defaultSortOrder}: ColumnSortIconP
4551

4652
interface TableHeadCellProps<T> {
4753
column: Column<T>;
54+
resizeable?: boolean;
4855
sortOrder?: SortOrderType;
4956
defaultSortOrder: SortOrderType;
5057
onSort?: (columnName: string) => void;
@@ -55,6 +62,7 @@ interface TableHeadCellProps<T> {
5562

5663
export const TableHeadCell = <T,>({
5764
column,
65+
resizeable,
5866
sortOrder,
5967
defaultSortOrder,
6068
onSort,
@@ -82,9 +90,7 @@ export const TableHeadCell = <T,>({
8290
<th>
8391
<div
8492
ref={cellWrapperRef}
85-
className={b('head-cell-wrapper', {
86-
resizeable: column.resizeable,
87-
})}
93+
className={b('head-cell-wrapper', {resizeable})}
8894
style={{
8995
height: `${rowHeight}px`,
9096
width: `${column.width}px`,
@@ -213,10 +219,14 @@ export const TableHead = <T,>({
213219
const sortOrder =
214220
sortParams.columnId === column.name ? sortParams.sortOrder : undefined;
215221

222+
const resizeable =
223+
onColumnsResize && (column.resizeable ?? DEFAULT_RESIZEABLE);
224+
216225
return (
217226
<TableHeadCell
218227
key={column.name}
219228
column={column}
229+
resizeable={resizeable}
220230
sortOrder={sortOrder}
221231
defaultSortOrder={defaultSortOrder}
222232
onSort={handleSort}

src/components/VirtualTable/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const CENTER = 'center';
33
export const RIGHT = 'right';
44

55
export const DEFAULT_ALIGN = LEFT;
6+
export const DEFAULT_RESIZEABLE = true;
67

78
export const ASCENDING = 1;
89
export const DESCENDING = -1;

src/containers/Nodes/getNodesColumns.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ const versionColumn: NodesColumn = {
9090
return <CellWithPopover content={row.Version}>{row.Version}</CellWithPopover>;
9191
},
9292
sortable: false,
93-
resizeable: true,
9493
};
9594

9695
const uptimeColumn: NodesColumn = {

src/utils/hooks/useTableResize.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {useCallback, useState} from 'react';
22
import type {Column as DataTableColumn} from '@gravity-ui/react-data-table';
3-
import type {Column as VirtualTableColumn} from '../../components/VirtualTable';
3+
import {DEFAULT_RESIZEABLE, type Column as VirtualTableColumn} from '../../components/VirtualTable';
44
import {settingsManager} from '../../services/settings';
55

66
export type Column<T> = VirtualTableColumn<T> & DataTableColumn<T>;
@@ -14,7 +14,9 @@ export const updateColumnsWidth = <T>(
1414
columnsWidthSetup: TableColumnsWidthSetup,
1515
) => {
1616
return columns.map((column) => {
17-
if (!column.resizeable) {
17+
const resizeable = column.resizeable ?? DEFAULT_RESIZEABLE;
18+
19+
if (!resizeable) {
1820
return column;
1921
}
2022
return {...column, width: columnsWidthSetup[column.name] ?? column.width};

0 commit comments

Comments
 (0)