-
Notifications
You must be signed in to change notification settings - Fork 7
Version sorting broken in Searchkit upgrade #381
Comments
Hey @ssetem can you give me a hint here? diff --git a/ui/src/App.js b/ui/src/App.js
index a47dabc..4d52cb2 100644
--- a/ui/src/App.js
+++ b/ui/src/App.js
@@ -192,6 +192,45 @@ class ProjectInfo extends React.PureComponent {
}
}
+const sortVersions = filters => {
+ return filters.sort((a, b) => {
+ const partsA = a.key.split(".");
+ const partsB = b.key.split(".");
+ if (partsA.length < 2 || partsB.length < 2) {
+ // Bogus version, list is last.
+ return 1;
+ }
+ let i = 0;
+ while (partsA[i] === partsB[i] && i <= partsA.length) {
+ // Skip all the parts that are equal.
+ i++;
+ }
+ if (!partsA[i] || !partsB[i]) {
+ // Both versions have the same parts, but one has more parts, eg 56.0 and 56.0.1.
+ return partsB.length - partsA.length;
+ }
+ const subPartRegex = /^(\d+)([a-zA-Z]+)?(\d+)?([a-zA-Z]+)?/; // Eg: 0b12pre
+ const subPartA = partsA[i].match(subPartRegex); // Eg: ["0b1pre", "0", "b", "12", "pre"]
+ const subPartB = partsB[i].match(subPartRegex);
+ if (subPartA[1] !== subPartB[1]) {
+ return parseInt(subPartB[1], 10) - parseInt(subPartA[1], 10);
+ }
+ if (subPartA[2] !== subPartB[2]) {
+ if (subPartA[2] && !subPartB[2]) {
+ return 1;
+ }
+ if (subPartB[2] && !subPartA[2]) {
+ return -1;
+ }
+ return subPartB[2].localeCompare(subPartA[2]);
+ }
+ if (subPartA[3] !== subPartB[3]) {
+ return parseInt(subPartB[3], 10) - parseInt(subPartA[3], 10);
+ }
+ return parseInt(partsB[2], 10) - parseInt(partsA[2], 10);
+ });
+};
+
class App extends Component {
render() {
return (
@@ -243,6 +282,7 @@ class App extends Component {
size={20}
operator="OR"
multi={true}
+ bucketsTransform={sortVersions}
/>
<RefinementAutosuggest
field="target.platform" What I mean by it not working is that the What I did do was add It was my mistake to not notice that some of the custom options were lost such as the sort on certain fields like |
Here's my fumbling start: mozilla-services:master...peterbe:correct-sort-order-for-refinement-lists-fixes-381 |
This doesn't entirely fix it but it makes it much better #419 |
See
This merged pull request is probably "guilty".
The text was updated successfully, but these errors were encountered: