Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VirtualTable): make table columns resizeable by default #772

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading