Skip to content

Commit

Permalink
fix(VirtualTable): make table resizeable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov committed Mar 27, 2024
1 parent 7b8e473 commit 6155bc3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/components/VirtualTable/TableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import type {
} from '../../utils/hooks/useTableResize';

import type {Column, OnSort, SortOrderType, SortParams} from './types';
import {ASCENDING, DEFAULT_SORT_ORDER, DEFAULT_TABLE_ROW_HEIGHT, DESCENDING} from './constants';
import {
ASCENDING,
DEFAULT_RESIZEABLE,
DEFAULT_SORT_ORDER,
DEFAULT_TABLE_ROW_HEIGHT,
DESCENDING,
} from './constants';
import {b} from './shared';

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

interface TableHeadCellProps<T> {
column: Column<T>;
resizeable?: boolean;
sortOrder?: SortOrderType;
defaultSortOrder: SortOrderType;
onSort?: (columnName: string) => void;
Expand All @@ -55,6 +62,7 @@ interface TableHeadCellProps<T> {

export const TableHeadCell = <T,>({
column,
resizeable,
sortOrder,
defaultSortOrder,
onSort,
Expand Down Expand Up @@ -82,9 +90,7 @@ export const TableHeadCell = <T,>({
<th>
<div
ref={cellWrapperRef}
className={b('head-cell-wrapper', {
resizeable: column.resizeable,
})}
className={b('head-cell-wrapper', {resizeable})}
style={{
height: `${rowHeight}px`,
width: `${column.width}px`,
Expand Down Expand Up @@ -213,10 +219,14 @@ export const TableHead = <T,>({
const sortOrder =
sortParams.columnId === column.name ? sortParams.sortOrder : undefined;

const resizeable =
onColumnsResize && (column.resizeable ?? DEFAULT_RESIZEABLE);

return (
<TableHeadCell
key={column.name}
column={column}
resizeable={resizeable}
sortOrder={sortOrder}
defaultSortOrder={defaultSortOrder}
onSort={handleSort}
Expand Down
1 change: 1 addition & 0 deletions src/components/VirtualTable/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const CENTER = 'center';
export const RIGHT = 'right';

export const DEFAULT_ALIGN = LEFT;
export const DEFAULT_RESIZEABLE = true;

export const ASCENDING = 1;
export const DESCENDING = -1;
Expand Down
1 change: 0 additions & 1 deletion src/containers/Nodes/getNodesColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const versionColumn: NodesColumn = {
return <CellWithPopover content={row.Version}>{row.Version}</CellWithPopover>;
},
sortable: false,
resizeable: true,
};

const uptimeColumn: NodesColumn = {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/hooks/useTableResize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useCallback, useState} from 'react';
import type {Column as DataTableColumn} from '@gravity-ui/react-data-table';
import type {Column as VirtualTableColumn} from '../../components/VirtualTable';
import {DEFAULT_RESIZEABLE, type Column as VirtualTableColumn} from '../../components/VirtualTable';
import {settingsManager} from '../../services/settings';

export type Column<T> = VirtualTableColumn<T> & DataTableColumn<T>;
Expand All @@ -14,7 +14,9 @@ export const updateColumnsWidth = <T>(
columnsWidthSetup: TableColumnsWidthSetup,
) => {
return columns.map((column) => {
if (!column.resizeable) {
const resizeable = column.resizeable ?? DEFAULT_RESIZEABLE;

if (!resizeable) {
return column;
}
return {...column, width: columnsWidthSetup[column.name] ?? column.width};
Expand Down

0 comments on commit 6155bc3

Please sign in to comment.