fix sorting for index management (#20266) (#20346)

* fix sorting for index management

* PR feedback
This commit is contained in:
Bill McConaghy 2018-06-29 12:08:05 -04:00 committed by GitHub
parent 498c054f89
commit 2b85a2ada9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,7 +17,15 @@ const unitMagnitude = {
};
const byteSort = (fieldName) => (item) => {
const rawValue = item[fieldName];
const [ , number, unit] = rawValue.match(/(.*)([kmgtp]b)/);
// raw value can be missing if index is closed
if (!rawValue) {
return 0;
}
const matchResult = rawValue.match(/(.*)([kmgtp]b)/);
if (!matchResult) {
return 0;
}
const [ , number, unit] = matchResult;
return +number * Math.pow(1024, unitMagnitude[unit]);
};