mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
ui: improve sort utility for metrics (#9247)
This improves the UI sorting utility to check for metrics data and sort after cleaning the string data. Fixes #8663 Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
2ca0857bd5
commit
6ce2a58f9b
@ -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 })
|
||||
}
|
||||
|
||||
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)
|
||||
@ -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
|
||||
*
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user