Skip to content

Commit 13d6f79

Browse files
authored
NETOBSERV-2239: fix sorting by packets/bytes (#844)
Array columns were not correctly handled
1 parent 489bd5d commit 13d6f79

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

web/src/components/tabs/netflow-table/netflow-table.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ export const NetflowTable: React.FC<NetflowTableProps> = React.forwardRef(
223223
if (!found) {
224224
return props.flows;
225225
} else {
226-
return props.flows.sort((a: Record, b: Record) => {
227-
return activeSortDirection === 'desc' ? found.sort(a, b, found) : found.sort(b, a, found);
228-
});
226+
return activeSortDirection === 'desc'
227+
? props.flows.sort((a: Record, b: Record) => found.sort(a, b, found))
228+
: props.flows.sort((a: Record, b: Record) => found.sort(b, a, found));
229229
}
230230
}, [activeSortDirection, activeSortId, props.columns, props.flows]);
231231

web/src/utils/columns.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ export const getShortColumnName = (col?: Column): string => {
208208
return '';
209209
};
210210

211+
const getFieldSingleValue = (rec: Record, fvFunc: (flow: Record) => ColValue): ColValue => {
212+
const val = fvFunc(rec);
213+
if (Array.isArray(val) && val.length > 0) {
214+
// E.g. for Bytes / Packets columns as they may include drops
215+
return val[0];
216+
}
217+
return val;
218+
};
219+
211220
export const getDefaultColumns = (columnDefs: ColumnConfigDef[], fieldConfigs: FieldConfig[]): Column[] => {
212221
const columns: Column[] = [];
213222

@@ -241,8 +250,8 @@ export const getDefaultColumns = (columnDefs: ColumnConfigDef[], fieldConfigs: F
241250
if (!col.fieldValue) {
242251
return -1;
243252
}
244-
const valA = col.fieldValue(a);
245-
const valB = col.fieldValue(b);
253+
const valA = getFieldSingleValue(a, col.fieldValue);
254+
const valB = getFieldSingleValue(b, col.fieldValue);
246255
if (typeof valA === 'number' && typeof valB === 'number') {
247256
if (col.id.includes('Port')) {
248257
return comparePorts(valA, valB);

0 commit comments

Comments
 (0)