Skip to content

Commit a3b618e

Browse files
authored
Merge pull request #6971 from Countly/fix/dashboard-app-sorting
[SER-2590] [SER-2591] fix: dashboards list and app management list sorting
2 parents 15f1c20 + 8ca94d5 commit a3b618e

File tree

3 files changed

+78
-10
lines changed

3 files changed

+78
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Fixes:
55
Enterprise Fixes:
66
- [concurrent_users] Fix email check for alert
77
- [data-manager] Correctly show last triggered for events if data masking is enabled
8-
8+
- [dashboards] Keep dashboard sidebar sorted alphabetically after additions
9+
- [applications] Ensure application management list reorders after create/update
910

1011
## Version 25.03.27
1112
Fixes:

frontend/express/public/core/app-management/javascripts/countly.views.js

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@
5959
value: id
6060
};
6161
});
62-
if (countlyGlobal.member.appSortList) {
63-
appList = this.sortBy(appList, countlyGlobal.member.appSortList);
62+
var sortList = (countlyGlobal.member && countlyGlobal.member.appSortList) || [];
63+
if (sortList.length) {
64+
appList = this.sortBy(appList, sortList);
6465
}
6566
else {
66-
appList.sort(function(a, b) {
67-
return a.label > b.label && 1 || -1;
68-
});
67+
appList.sort(this.sortAppOptionsAlphabetically);
6968
}
7069
var app_id = this.$route.params.app_id || countlyCommon.ACTIVE_APP_ID;
7170
return {
@@ -340,6 +339,56 @@
340339
}
341340
}
342341
},
342+
getAppListItemId: function(option) {
343+
if (!option) {
344+
return "";
345+
}
346+
347+
return (option._id || option.value || option.id || option.app_id || "") + "";
348+
},
349+
sortAppOptionsAlphabetically: function(optionA, optionB) {
350+
var labelA = (optionA.label || "").toLowerCase();
351+
var labelB = (optionB.label || "").toLowerCase();
352+
353+
if (labelA < labelB) {
354+
return -1;
355+
}
356+
357+
if (labelA > labelB) {
358+
return 1;
359+
}
360+
361+
var valueA = (optionA.value || "").toLowerCase();
362+
var valueB = (optionB.value || "").toLowerCase();
363+
364+
if (valueA < valueB) {
365+
return -1;
366+
}
367+
368+
if (valueA > valueB) {
369+
return 1;
370+
}
371+
372+
return 0;
373+
},
374+
applyAppListOrdering: function() {
375+
if (!Array.isArray(this.appList)) {
376+
return;
377+
}
378+
379+
var sortList = (countlyGlobal.member && countlyGlobal.member.appSortList) || [];
380+
var currentList = this.appList.slice();
381+
var orderedList;
382+
383+
if (sortList.length) {
384+
orderedList = this.sortBy(currentList, sortList);
385+
}
386+
else {
387+
orderedList = currentList.sort(this.sortAppOptionsAlphabetically);
388+
}
389+
390+
this.appList = orderedList;
391+
},
343392
sortBy: function(arrayToSort, sortList) {
344393
if (!sortList.length) {
345394
return arrayToSort;
@@ -349,9 +398,10 @@
349398
retArr = [];
350399
var i;
351400
for (i = 0; i < arrayToSort.length; i++) {
352-
var objId = arrayToSort[i]._id + "";
353-
if (sortList.indexOf(objId) !== -1) {
354-
tmpArr[sortList.indexOf(objId)] = arrayToSort[i];
401+
var objId = this.getAppListItemId(arrayToSort[i]);
402+
var desiredIndex = sortList.indexOf(objId);
403+
if (desiredIndex !== -1) {
404+
tmpArr[desiredIndex] = arrayToSort[i];
355405
}
356406
}
357407

@@ -392,6 +442,7 @@
392442
value: data._id + "",
393443
label: data.name
394444
});
445+
self.applyAppListOrdering();
395446
self.$store.dispatch("countlyCommon/addToAllApps", data);
396447
self.$store.dispatch("countlyCommon/updateActiveApp", data._id + "");
397448
countlyCommon.setActiveApp(data._id);
@@ -459,6 +510,7 @@
459510
break;
460511
}
461512
}
513+
self.applyAppListOrdering();
462514
self.discardForm();
463515
CountlyHelpers.notify({
464516
title: jQuery.i18n.map["configs.changed"],

plugins/dashboards/frontend/public/javascripts/countly.views.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,22 @@
17221722
allDashboards: function() {
17231723
var query = this.searchQuery;
17241724

1725-
var dashboards = this.$store.getters["countlyDashboards/all"];
1725+
var dashboards = (this.$store.getters["countlyDashboards/all"] || []).slice();
1726+
1727+
dashboards.sort(function(a, b) {
1728+
var nameA = (a.name || "").toLowerCase();
1729+
var nameB = (b.name || "").toLowerCase();
1730+
1731+
if (nameA < nameB) {
1732+
return -1;
1733+
}
1734+
1735+
if (nameA > nameB) {
1736+
return 1;
1737+
}
1738+
1739+
return 0;
1740+
});
17261741

17271742
if (!query) {
17281743
return dashboards;

0 commit comments

Comments
 (0)