Skip to content

Commit 246d95c

Browse files
CopilotRaubzeug
andcommitted
Implement sticky header, resizable and sortable columns for VDisk tablets table
Co-authored-by: Raubzeug <[email protected]>
1 parent 2626ede commit 246d95c

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/containers/VDiskPage/VDiskTablets/VDiskTablets.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22

33
import {useTable} from '@gravity-ui/table';
44
import {skipToken} from '@reduxjs/toolkit/query';
5+
import type {SortingState} from '@tanstack/react-table';
56

67
import {InfoViewerSkeleton} from '../../../components/InfoViewerSkeleton/InfoViewerSkeleton';
78
import {Table} from '../../../components/Table/Table';
@@ -25,6 +26,9 @@ interface VDiskTabletsProps {
2526

2627
export function VDiskTablets({nodeId, pDiskId, vDiskSlotId, className}: VDiskTabletsProps) {
2728
const [autoRefreshInterval] = useAutoRefreshInterval();
29+
const [sorting, setSorting] = React.useState<SortingState>([
30+
{id: 'Size', desc: true}, // Default sort by size descending
31+
]);
2832

2933
const params = nodeId && pDiskId && vDiskSlotId ? {nodeId, pDiskId, vDiskSlotId} : skipToken;
3034

@@ -34,7 +38,7 @@ export function VDiskTablets({nodeId, pDiskId, vDiskSlotId, className}: VDiskTab
3438

3539
const loading = isFetching && currentData === undefined;
3640

37-
// Transform the actual API response structure into the expected flat table format
41+
// Remove the manual sorting since we'll let the table handle it with enableSorting
3842
const tableData: VDiskBlobIndexItem[] = React.useMemo(() => {
3943
if (!currentData) {
4044
return [];
@@ -76,20 +80,18 @@ export function VDiskTablets({nodeId, pDiskId, vDiskSlotId, className}: VDiskTab
7680
return flatData;
7781
}, [currentData]);
7882

79-
// Sort by size descending by default
80-
const sortedData = React.useMemo(() => {
81-
return [...tableData].sort((a, b) => {
82-
const sizeA = Number(a.Size) || 0;
83-
const sizeB = Number(b.Size) || 0;
84-
return sizeB - sizeA;
85-
});
86-
}, [tableData]);
87-
8883
const columns = React.useMemo(() => getColumns(), []);
8984

9085
const table = useTable({
9186
columns,
92-
data: sortedData,
87+
data: tableData,
88+
enableSorting: true,
89+
enableColumnResizing: true,
90+
columnResizeMode: 'onChange',
91+
onSortingChange: setSorting,
92+
state: {
93+
sorting,
94+
},
9395
});
9496

9597
if (error) {
@@ -106,7 +108,7 @@ export function VDiskTablets({nodeId, pDiskId, vDiskSlotId, className}: VDiskTab
106108

107109
return (
108110
<div className={vDiskTabletsCn(null, className)}>
109-
<Table table={table} />
111+
<Table table={table} stickyHeader width="max" />
110112
</div>
111113
);
112114
}

src/containers/VDiskPage/VDiskTablets/columns.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function TabletIdCell({row}: CellContext<VDiskBlobIndexItem, unknown>) {
2424
function MetricsCell({row, column}: CellContext<VDiskBlobIndexItem, unknown>) {
2525
const item = row.original;
2626
const fieldName = column.id;
27-
27+
2828
// Handle both PascalCase and camelCase field names
2929
let value;
3030
if (fieldName === 'ChannelId') {
@@ -34,7 +34,7 @@ function MetricsCell({row, column}: CellContext<VDiskBlobIndexItem, unknown>) {
3434
} else {
3535
value = item[fieldName];
3636
}
37-
37+
3838
return <span className={b('metrics-cell')}>{value ?? '-'}</span>;
3939
}
4040

@@ -51,28 +51,37 @@ export function getColumns() {
5151
accessorKey: 'TabletId',
5252
header: () => <ColumnHeader>{vDiskPageKeyset('tablet-id')}</ColumnHeader>,
5353
size: 150,
54+
minSize: 100,
5455
cell: TabletIdCell,
56+
enableSorting: true,
5557
},
5658
{
5759
accessorKey: 'ChannelId',
5860
header: () => <ColumnHeader>{vDiskPageKeyset('channel-id')}</ColumnHeader>,
5961
size: 100,
62+
minSize: 80,
6063
cell: MetricsCell,
6164
meta: {align: 'right'},
65+
enableSorting: true,
6266
},
6367
{
6468
accessorKey: 'Count',
6569
header: () => <ColumnHeader>{vDiskPageKeyset('count')}</ColumnHeader>,
6670
size: 100,
71+
minSize: 80,
6772
cell: MetricsCell,
6873
meta: {align: 'right'},
74+
enableSorting: true,
6975
},
7076
{
7177
accessorKey: 'Size',
7278
header: () => <ColumnHeader>{vDiskPageKeyset('size')}</ColumnHeader>,
7379
size: 120,
80+
minSize: 100,
7481
cell: SizeCell,
7582
meta: {align: 'right'},
83+
enableSorting: true,
84+
sortingFn: 'basic', // Use basic sorting for numeric values
7685
},
7786
];
7887

0 commit comments

Comments
 (0)