Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion ui/src/utils/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ function filterNumber (value) {
}

function stringComparator (a, b) {
return a.toString().localeCompare(b.toString())
return a.toString().localeCompare(b.toString(), undefined, { numeric: true })

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - this would also consider for cases where there is numeric string data

}

function numericComparator (a, b) {
return filterNumber(a) < filterNumber(b) ? 1 : -1
}

function metricComparator (ma, mb) {
var a = ('' + ma).replace(/((%)|(Ghz)|(Mhz)|(MiB)|(GiB)|(GB)).*$/g, '')
var b = ('' + mb).replace(/((%)|(Ghz)|(Mhz)|(MiB)|(GiB)|(GB)).*$/g, '')
return parseFloat(a) < parseFloat(b) ? 1 : -1
}

function ipV4AddressCIDRComparator (a, b) {
a = a.split(/[./]/gm)
b = b.split(/[./]/gm)
Expand Down Expand Up @@ -76,6 +82,10 @@ function isNumeric (obj) {
return !Array.isArray(obj) && !isNaN(filterNumber(obj))
}

function isMetric (value) {
return /^[0-9\\. ]*((%)|(Ghz)|(Mhz)|(MiB)|(GiB)|(GB))/.test(value)
}

/**
* Compare elements, attempting to determine type of element to get the best comparison
*
Expand All @@ -97,6 +107,9 @@ export function genericCompare (a, b) {
if (isNumeric(a) && isNumeric(b)) {
comparator = numericComparator
}
if (isMetric(a) && isMetric(b)) {
comparator = metricComparator
}

return comparator(a, b)
}