Skip to content

Commit e397175

Browse files
Copilotadameat
andcommitted
Fix VDisk tablets table display issue by handling multiple API response structures
Co-authored-by: adameat <[email protected]>
1 parent a2b3555 commit e397175

File tree

3 files changed

+85
-9
lines changed

3 files changed

+85
-9
lines changed

src/containers/VDiskPage/VDiskTablets/VDiskTablets.tsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,57 @@ export function VDiskTablets({nodeId, pDiskId, vDiskSlotId, className}: VDiskTab
3333
});
3434

3535
const loading = isFetching && currentData === undefined;
36-
const tableData: VDiskBlobIndexItem[] = currentData?.BlobIndexStat || [];
36+
37+
// Debug: Log the actual response to understand the structure
38+
React.useEffect(() => {
39+
if (currentData) {
40+
console.log('VDisk BlobIndexStat Response:', currentData);
41+
console.log('Response keys:', Object.keys(currentData));
42+
console.log('BlobIndexStat field:', currentData.BlobIndexStat);
43+
console.log('blobIndexStat field:', currentData.blobIndexStat);
44+
console.log('blobindexstat field:', currentData.blobindexstat);
45+
console.log('result field:', currentData.result);
46+
console.log('data field:', currentData.data);
47+
}
48+
}, [currentData]);
49+
50+
// Try multiple possible field names for the data array
51+
const tableData: VDiskBlobIndexItem[] = React.useMemo(() => {
52+
if (!currentData) return [];
53+
54+
// Try different possible field names
55+
const possibleFields = [
56+
currentData.BlobIndexStat,
57+
currentData.blobIndexStat,
58+
currentData.blobindexstat,
59+
currentData.result,
60+
currentData.data,
61+
];
62+
63+
for (const field of possibleFields) {
64+
if (Array.isArray(field)) {
65+
console.log('Using field:', field);
66+
return field;
67+
}
68+
}
69+
70+
// If none of the expected fields work, try to find any array in the response
71+
for (const [key, value] of Object.entries(currentData)) {
72+
if (Array.isArray(value)) {
73+
console.log('Found array field:', key, value);
74+
return value;
75+
}
76+
}
77+
78+
console.log('No array found in response, returning empty array');
79+
return [];
80+
}, [currentData]);
3781

3882
// Sort by size descending by default
3983
const sortedData = React.useMemo(() => {
4084
return [...tableData].sort((a, b) => {
41-
const sizeA = Number(a.Size) || 0;
42-
const sizeB = Number(b.Size) || 0;
85+
const sizeA = Number(a.Size ?? a.size) || 0;
86+
const sizeB = Number(b.Size ?? b.size) || 0;
4387
return sizeB - sizeA;
4488
});
4589
}, [tableData]);

src/containers/VDiskPage/VDiskTablets/columns.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {vDiskPageKeyset} from '../i18n';
1010

1111
const b = cn('ydb-vdisk-tablets');
1212

13-
function TabletIdCell({getValue}: CellContext<VDiskBlobIndexItem, unknown>) {
14-
const tabletId = getValue<string | number>();
13+
function TabletIdCell({row}: CellContext<VDiskBlobIndexItem, unknown>) {
14+
const item = row.original;
15+
const tabletId = item.TabletId || item.tabletId;
1516

1617
if (!tabletId) {
1718
return <span>-</span>;
@@ -20,13 +21,26 @@ function TabletIdCell({getValue}: CellContext<VDiskBlobIndexItem, unknown>) {
2021
return <InternalLink to={getTabletPagePath(String(tabletId))}>{tabletId}</InternalLink>;
2122
}
2223

23-
function MetricsCell({getValue}: CellContext<VDiskBlobIndexItem, unknown>) {
24-
const value = getValue<string | number>();
24+
function MetricsCell({row, column}: CellContext<VDiskBlobIndexItem, unknown>) {
25+
const item = row.original;
26+
const fieldName = column.id;
27+
28+
// Handle both PascalCase and camelCase field names
29+
let value;
30+
if (fieldName === 'ChannelId') {
31+
value = item.ChannelId ?? item.channelId;
32+
} else if (fieldName === 'Count') {
33+
value = item.Count ?? item.count;
34+
} else {
35+
value = item[fieldName];
36+
}
37+
2538
return <span className={b('metrics-cell')}>{value ?? '-'}</span>;
2639
}
2740

28-
function SizeCell({getValue}: CellContext<VDiskBlobIndexItem, unknown>) {
29-
const size = getValue<string | number>();
41+
function SizeCell({row}: CellContext<VDiskBlobIndexItem, unknown>) {
42+
const item = row.original;
43+
const size = item.Size ?? item.size;
3044
const numericSize = Number(size) || 0;
3145
return <span className={b('size-cell')}>{formatBytes(numericSize)}</span>;
3246
}

src/types/api/vdiskBlobIndex.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,37 @@
77
export interface VDiskBlobIndexItem {
88
/** Tablet ID */
99
TabletId?: string | number;
10+
/** Alternative field name for Tablet ID */
11+
tabletId?: string | number;
1012
/** Channel ID */
1113
ChannelId?: number;
14+
/** Alternative field name for Channel ID */
15+
channelId?: number;
1216
/** Count */
1317
Count?: number;
18+
/** Alternative field name for Count */
19+
count?: number;
1420
/** Size in bytes */
1521
Size?: number | string;
22+
/** Alternative field name for Size */
23+
size?: number | string;
24+
/** Allow for other possible field names */
25+
[key: string]: any;
1626
}
1727

1828
export interface VDiskBlobIndexResponse {
1929
/** Array of blob index statistics */
2030
BlobIndexStat?: VDiskBlobIndexItem[];
31+
/** Alternative possible field name (camelCase) */
32+
blobIndexStat?: VDiskBlobIndexItem[];
33+
/** Alternative possible field name (lowercase) */
34+
blobindexstat?: VDiskBlobIndexItem[];
2135
/** Response time */
2236
ResponseTime?: string;
2337
/** Response duration */
2438
ResponseDuration?: number;
39+
/** Alternative response structures */
40+
result?: VDiskBlobIndexItem[];
41+
data?: VDiskBlobIndexItem[];
42+
[key: string]: any; // Allow for other possible field names
2543
}

0 commit comments

Comments
 (0)