Skip to content

Commit 604e99a

Browse files
fix(TopShards): fix table crash on undefined values
1 parent 032f185 commit 604e99a

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

src/containers/Node/NodePages.js renamed to src/containers/Node/NodePages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const NODE_PAGES = [
2121
},
2222
];
2323

24-
export function getDefaultNodePath(nodeId) {
24+
export function getDefaultNodePath(nodeId: string | number) {
2525
return createHref(routes.node, {
2626
id: nodeId,
2727
activeTab: OVERVIEW,

src/containers/Tenant/Diagnostics/TopShards/TopShards.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {setCurrentSchemaPath, getSchema} from '../../../../store/reducers/schema
2020
import {EShardsWorkloadMode, IShardsWorkloadFilters} from '../../../../types/store/shardsWorkload';
2121

2222
import type {EPathType} from '../../../../types/api/schema';
23+
import type {CellValue, KeyValueRow} from '../../../../types/api/query';
2324

2425
import {formatDateTime, formatNumber} from '../../../../utils';
2526
import {DEFAULT_TABLE_SETTINGS, HOUR_IN_SECONDS} from '../../../../utils/constants';
@@ -57,10 +58,17 @@ const tableColumnsNames = {
5758
IntervalEnd: 'IntervalEnd',
5859
};
5960

60-
function prepareCPUWorkloadValue(value: string) {
61+
function prepareCPUWorkloadValue(value: string | number) {
6162
return `${(Number(value) * 100).toFixed(2)}%`;
6263
}
6364

65+
function prepareDateTimeValue(value: CellValue) {
66+
if (!value) {
67+
return '–';
68+
}
69+
return formatDateTime(new Date(value).getTime());
70+
}
71+
6472
function stringToDataTableSortOrder(value: string): SortOrder[] | undefined {
6573
return value
6674
? value.split(',').map((columnId) => ({
@@ -190,53 +198,60 @@ export const TopShards = ({tenantPath, type}: TopShardsProps) => {
190198
};
191199
};
192200

193-
const columns: Column<any>[] = [
201+
const columns: Column<KeyValueRow>[] = [
194202
{
195203
name: tableColumnsNames.Path,
196-
render: ({value: relativeNodePath}) => {
204+
render: ({row}) => {
205+
// row.Path - relative schema path
197206
return (
198207
<span
199-
onClick={onSchemaClick(tenantPath + relativeNodePath)}
208+
onClick={onSchemaClick(tenantPath + row.Path)}
200209
className={bLink({view: 'normal'})}
201210
>
202-
{relativeNodePath as string}
211+
{row.Path}
203212
</span>
204213
);
205214
},
206215
sortable: false,
207216
},
208217
{
209218
name: tableColumnsNames.CPUCores,
210-
render: ({value}) => {
211-
return prepareCPUWorkloadValue(value as string);
219+
render: ({row}) => {
220+
return prepareCPUWorkloadValue(row.CPUCores || 0);
212221
},
213222
align: DataTable.RIGHT,
214223
},
215224
{
216225
name: tableColumnsNames.DataSize,
217226
header: 'DataSize (B)',
218-
render: ({value}) => {
219-
return formatNumber(value as number);
227+
render: ({row}) => {
228+
return formatNumber(row.DataSize);
220229
},
221230
align: DataTable.RIGHT,
222231
},
223232
{
224233
name: tableColumnsNames.TabletId,
225-
render: ({value}) => {
234+
render: ({row}) => {
235+
if (!row.TabletId) {
236+
return '–';
237+
}
226238
return (
227-
<InternalLink to={createHref(routes.tablet, {id: value})}>
228-
{value as string}
239+
<InternalLink to={createHref(routes.tablet, {id: row.TabletId})}>
240+
{row.TabletId}
229241
</InternalLink>
230242
);
231243
},
232244
sortable: false,
233245
},
234246
{
235247
name: tableColumnsNames.NodeId,
236-
render: ({value: nodeId}) => {
248+
render: ({row}) => {
249+
if (!row.NodeId) {
250+
return '–';
251+
}
237252
return (
238-
<InternalLink to={getDefaultNodePath(nodeId as string)}>
239-
{nodeId as string}
253+
<InternalLink to={getDefaultNodePath(row.NodeId)}>
254+
{row.NodeId}
240255
</InternalLink>
241256
);
242257
},
@@ -245,7 +260,7 @@ export const TopShards = ({tenantPath, type}: TopShardsProps) => {
245260
},
246261
{
247262
name: tableColumnsNames.InFlightTxCount,
248-
render: ({value}) => formatNumber(value as number),
263+
render: ({row}) => formatNumber(row.InFlightTxCount),
249264
align: DataTable.RIGHT,
250265
sortable: false,
251266
},
@@ -255,12 +270,16 @@ export const TopShards = ({tenantPath, type}: TopShardsProps) => {
255270
// after NodeId
256271
columns.splice(5, 0, {
257272
name: tableColumnsNames.PeakTime,
258-
render: ({value}) => formatDateTime(new Date(value as string).valueOf()),
273+
render: ({row}) => {
274+
return prepareDateTimeValue(row.PeakTime);
275+
},
259276
sortable: false,
260277
});
261278
columns.push({
262279
name: tableColumnsNames.IntervalEnd,
263-
render: ({value}) => formatDateTime(new Date(value as string).getTime()),
280+
render: ({row}) => {
281+
return prepareDateTimeValue(row.IntervalEnd);
282+
},
264283
});
265284
}
266285

src/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const CLUSTER_PAGES = {
2828

2929
export function createHref(
3030
route: string,
31-
params?: object,
31+
params?: Record<string, string | number>,
3232
query: Record<string | number, string | number | string[] | number[] | undefined> = {},
3333
) {
3434
let extendedQuery = query;

src/types/api/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type Schemas = 'classic' | 'modern' | 'ydb' | undefined;
3030

3131
// common types
3232

33-
type CellValue = string | number | null | undefined;
33+
export type CellValue = string | number | null | undefined;
3434

3535
export type KeyValueRow<T = CellValue> = {
3636
[key: string]: T;

0 commit comments

Comments
 (0)