Skip to content

Commit 2626ede

Browse files
Copilotadameat
andcommitted
Fix VDisk tablets table data parsing to handle actual API response structure
Co-authored-by: adameat <[email protected]>
1 parent e397175 commit 2626ede

File tree

2 files changed

+73
-50
lines changed

2 files changed

+73
-50
lines changed

src/containers/VDiskPage/VDiskTablets/VDiskTablets.tsx

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

3535
const loading = isFetching && currentData === undefined;
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
36+
37+
// Transform the actual API response structure into the expected flat table format
5138
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-
}
39+
if (!currentData) {
40+
return [];
6841
}
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-
}
42+
43+
// Debug: Log the actual response structure
44+
console.info('VDisk BlobIndexStat Response:', currentData);
45+
46+
// Check if we have the expected structure: {stat: {tablets: [...]}}
47+
const stat = currentData.stat;
48+
if (!stat || !Array.isArray(stat.tablets)) {
49+
console.info('No stat.tablets array found in response');
50+
return [];
7651
}
77-
78-
console.log('No array found in response, returning empty array');
79-
return [];
52+
53+
// Transform the nested structure into flat table rows
54+
const flatData: VDiskBlobIndexItem[] = [];
55+
56+
stat.tablets.forEach((tablet: any) => {
57+
const tabletId = tablet.tablet_id;
58+
if (!tabletId || !Array.isArray(tablet.channels)) {
59+
return; // Skip tablets without ID or channels
60+
}
61+
62+
tablet.channels.forEach((channel: any, channelIndex: number) => {
63+
// Only include channels that have count and data_size
64+
if (channel.count && channel.data_size) {
65+
flatData.push({
66+
TabletId: tabletId,
67+
ChannelId: channelIndex,
68+
Count: parseInt(channel.count, 10) || 0,
69+
Size: parseInt(channel.data_size, 10) || 0,
70+
});
71+
}
72+
});
73+
});
74+
75+
console.info('Transformed data:', flatData);
76+
return flatData;
8077
}, [currentData]);
8178

8279
// Sort by size descending by default
8380
const sortedData = React.useMemo(() => {
8481
return [...tableData].sort((a, b) => {
85-
const sizeA = Number(a.Size ?? a.size) || 0;
86-
const sizeB = Number(b.Size ?? b.size) || 0;
82+
const sizeA = Number(a.Size) || 0;
83+
const sizeB = Number(b.Size) || 0;
8784
return sizeB - sizeA;
8885
});
8986
}, [tableData]);

src/types/api/vdiskBlobIndex.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,44 @@ export interface VDiskBlobIndexItem {
2525
[key: string]: any;
2626
}
2727

28+
export interface VDiskBlobIndexChannel {
29+
/** Channel count */
30+
count?: string;
31+
/** Channel data size */
32+
data_size?: string;
33+
/** Channel minimum ID */
34+
min_id?: string;
35+
/** Channel maximum ID */
36+
max_id?: string;
37+
}
38+
39+
export interface VDiskBlobIndexTablet {
40+
/** Tablet identifier */
41+
tablet_id?: string;
42+
/** Array of tablet channels */
43+
channels?: VDiskBlobIndexChannel[];
44+
}
45+
46+
export interface VDiskBlobIndexStat {
47+
/** Array of tablets */
48+
tablets?: VDiskBlobIndexTablet[];
49+
/** Array of channels */
50+
channels?: VDiskBlobIndexChannel[];
51+
}
52+
2853
export interface VDiskBlobIndexResponse {
29-
/** Array of blob index statistics */
30-
BlobIndexStat?: VDiskBlobIndexItem[];
31-
/** Alternative possible field name (camelCase) */
32-
blobIndexStat?: VDiskBlobIndexItem[];
33-
/** Alternative possible field name (lowercase) */
34-
blobindexstat?: VDiskBlobIndexItem[];
54+
/** Response status */
55+
status?: string;
56+
/** Statistics data */
57+
stat?: VDiskBlobIndexStat;
3558
/** Response time */
3659
ResponseTime?: string;
3760
/** Response duration */
3861
ResponseDuration?: number;
39-
/** Alternative response structures */
62+
/** Alternative response structures for backward compatibility */
63+
BlobIndexStat?: VDiskBlobIndexItem[];
64+
blobIndexStat?: VDiskBlobIndexItem[];
65+
blobindexstat?: VDiskBlobIndexItem[];
4066
result?: VDiskBlobIndexItem[];
4167
data?: VDiskBlobIndexItem[];
4268
[key: string]: any; // Allow for other possible field names

0 commit comments

Comments
 (0)