From 67a8da6e76a9cfd2314871b57e6116a2ea62d884 Mon Sep 17 00:00:00 2001 From: Joel Takvorian Date: Tue, 13 May 2025 10:47:34 +0200 Subject: [PATCH] NETOBSERV-2239: fix sorting by packets/bytes Array columns were not correctly handled --- .../components/tabs/netflow-table/netflow-table.tsx | 6 +++--- web/src/utils/columns.ts | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/web/src/components/tabs/netflow-table/netflow-table.tsx b/web/src/components/tabs/netflow-table/netflow-table.tsx index 9d8fec5bc..dc3cd3360 100644 --- a/web/src/components/tabs/netflow-table/netflow-table.tsx +++ b/web/src/components/tabs/netflow-table/netflow-table.tsx @@ -223,9 +223,9 @@ export const NetflowTable: React.FC = React.forwardRef( if (!found) { return props.flows; } else { - return props.flows.sort((a: Record, b: Record) => { - return activeSortDirection === 'desc' ? found.sort(a, b, found) : found.sort(b, a, found); - }); + return activeSortDirection === 'desc' + ? props.flows.sort((a: Record, b: Record) => found.sort(a, b, found)) + : props.flows.sort((a: Record, b: Record) => found.sort(b, a, found)); } }, [activeSortDirection, activeSortId, props.columns, props.flows]); diff --git a/web/src/utils/columns.ts b/web/src/utils/columns.ts index e5751720f..04fd2577f 100644 --- a/web/src/utils/columns.ts +++ b/web/src/utils/columns.ts @@ -208,6 +208,15 @@ export const getShortColumnName = (col?: Column): string => { return ''; }; +const getFieldSingleValue = (rec: Record, fvFunc: (flow: Record) => ColValue): ColValue => { + const val = fvFunc(rec); + if (Array.isArray(val) && val.length > 0) { + // E.g. for Bytes / Packets columns as they may include drops + return val[0]; + } + return val; +}; + export const getDefaultColumns = (columnDefs: ColumnConfigDef[], fieldConfigs: FieldConfig[]): Column[] => { const columns: Column[] = []; @@ -241,8 +250,8 @@ export const getDefaultColumns = (columnDefs: ColumnConfigDef[], fieldConfigs: F if (!col.fieldValue) { return -1; } - const valA = col.fieldValue(a); - const valB = col.fieldValue(b); + const valA = getFieldSingleValue(a, col.fieldValue); + const valB = getFieldSingleValue(b, col.fieldValue); if (typeof valA === 'number' && typeof valB === 'number') { if (col.id.includes('Port')) { return comparePorts(valA, valB);