Skip to content

Commit

Permalink
Fixes liferay#1111 - Fix sort from menu
Browse files Browse the repository at this point in the history
  • Loading branch information
matuzalemsteles committed Sep 24, 2018
1 parent 7d82f3e commit 546eb2b
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions clayui.com/src/utils/arrangeIntoTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,20 @@ function arrangeIntoTree(paths) {
return tree;
}

function compareName(a, b) {
let nameA = a.title.toUpperCase();
let nameB = b.title.toUpperCase();

if (nameA < nameB) {
return -1;
}

if (nameA > nameB) {
return 1;
}

return 0;
}

function compareWeight(a, b) {
return b.weight - a.weight;
}
const regexSpace = /\s+/g;

function sortBy(tree) {
if (tree.items) {
tree.items.sort(compareName);
tree.items.sort(compareWeight);
tree.items = tree.items.sort((a, b) => {
let titleA = a.title.toUpperCase().replace(regexSpace, '');
let titleB = b.title.toUpperCase().replace(regexSpace, '');

if (a.weight < b.weight) return 1;
if (a.weight > b.weight) return -1;

if (titleA > titleB) return 1;
if (titleA < titleB) return -1;
});

tree.items.map((item) => sortBy(item));
}
Expand Down

0 comments on commit 546eb2b

Please sign in to comment.