mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
moebius#342: Columns are not sorted correctly (Natural Sort algorithm)
Issue #31 https://github.com/MoonchildProductions/moebius/pull/342
This commit is contained in:
parent
6d865bfda3
commit
8a1405d8b9
8 changed files with 218 additions and 35 deletions
|
|
@ -17,6 +17,9 @@ const { Task } = require("devtools/shared/task");
|
|||
|
||||
const DEFAULT_VALUE = "value";
|
||||
|
||||
loader.lazyRequireGetter(this, "naturalSortCaseInsensitive",
|
||||
"devtools/client/shared/natural-sort", true);
|
||||
|
||||
// GUID to be used as a separator in compound keys. This must match the same
|
||||
// constant in devtools/client/storage/ui.js,
|
||||
// devtools/client/storage/test/head.js and
|
||||
|
|
@ -326,15 +329,20 @@ StorageActors.defaults = function (typeName, observationTopic) {
|
|||
toReturn.data.push(...values);
|
||||
}
|
||||
}
|
||||
|
||||
toReturn.total = this.getObjectsSize(host, names, options);
|
||||
|
||||
if (offset > toReturn.total) {
|
||||
// In this case, toReturn.data is an empty array.
|
||||
toReturn.offset = toReturn.total;
|
||||
toReturn.data = [];
|
||||
} else {
|
||||
toReturn.data = toReturn.data.sort((a, b) => {
|
||||
return a[sortOn] - b[sortOn];
|
||||
}).slice(offset, offset + size).map(a => this.toStoreObject(a));
|
||||
// We need to use natural sort before slicing.
|
||||
let sorted = toReturn.data.sort((a, b) => {
|
||||
return naturalSortCaseInsensitive(a[sortOn], b[sortOn]);
|
||||
});
|
||||
let sliced = sorted.slice(offset, offset + size);
|
||||
toReturn.data = sliced.map(a => this.toStoreObject(a));
|
||||
}
|
||||
} else {
|
||||
let obj = yield this.getValuesForHost(host, undefined, undefined,
|
||||
|
|
@ -344,15 +352,18 @@ StorageActors.defaults = function (typeName, observationTopic) {
|
|||
}
|
||||
|
||||
toReturn.total = obj.length;
|
||||
|
||||
if (offset > toReturn.total) {
|
||||
// In this case, toReturn.data is an empty array.
|
||||
toReturn.offset = offset = toReturn.total;
|
||||
toReturn.data = [];
|
||||
} else {
|
||||
toReturn.data = obj.sort((a, b) => {
|
||||
return a[sortOn] - b[sortOn];
|
||||
}).slice(offset, offset + size)
|
||||
.map(object => this.toStoreObject(object));
|
||||
// We need to use natural sort before slicing.
|
||||
let sorted = obj.sort((a, b) => {
|
||||
return naturalSortCaseInsensitive(a[sortOn], b[sortOn]);
|
||||
});
|
||||
let sliced = sorted.slice(offset, offset + size);
|
||||
toReturn.data = sliced.map(object => this.toStoreObject(object));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue