Skip to content

Commit fd1367b

Browse files
authored
Merge pull request #6226 from Countly/SER-1125-unifying-alphabetical-order-for-dropdowns-with-dashboard-apps
[SER-1125] Unifying alphabetical order for dropdowns with dashboard apps
2 parents 74e3037 + 9e10290 commit fd1367b

7 files changed

Lines changed: 145 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11

22
## Version 25.03.x
3+
4+
Fixes:
5+
- [core] Unifying alphabetical order for dropdowns with dashboard apps
6+
37
Enterprise Fixes:
48
- [content] Asset URL was wrongly constructed when user switches between apps
59
- [ab-testing] Updates
610
- Do not wait for result calculation when requesting experiments
711
- Do not calculate result for completed experiments
812

13+
914
Dependencies:
1015
- Bump lint-staged from 15.5.2 to 16.0.0
1116
- Bump nodemailer from 6.10.1 to 7.0.3

frontend/express/public/core/report-manager/javascripts/countly.views.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,30 @@
169169
"independent": CV.i18n("report-manager.app-independent")
170170
};
171171
if (countlyGlobal.apps && Object.keys(countlyGlobal.apps).length !== 0) {
172-
for (var app in countlyGlobal.apps) {
173-
obj[app] = countlyGlobal.apps[app].name;
172+
const globalApps = Object.values(countlyGlobal.apps)
173+
.sort(function(a, b) {
174+
const aLabel = a?.label || '';
175+
const bLabel = b?.label || '';
176+
const locale = countlyCommon.BROWSER_LANG || 'en';
177+
178+
if (aLabel && bLabel) {
179+
return aLabel.localeCompare(bLabel, locale, { numeric: true }) || 0;
180+
}
181+
182+
// Move items with no label to the end
183+
if (!aLabel && bLabel) {
184+
return 1;
185+
}
186+
187+
if (aLabel && !bLabel) {
188+
return -1;
189+
}
190+
191+
return 0;
192+
});
193+
194+
for (var app of globalApps) {
195+
obj[app._id] = app.name;
174196
}
175197
}
176198
return obj;
@@ -563,4 +585,4 @@
563585
app.navigate("/", true);
564586
}
565587
});
566-
})();
588+
})();

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,27 @@
10131013
for (var app in countlyGlobal.apps) {
10141014
this.apps.push({value: countlyGlobal.apps[app]._id, label: countlyGlobal.apps[app].name });
10151015
}
1016+
1017+
this.apps.sort(function(a, b) {
1018+
const aLabel = a?.label || '';
1019+
const bLabel = b?.label || '';
1020+
const locale = countlyCommon.BROWSER_LANG || 'en';
1021+
1022+
if (aLabel && bLabel) {
1023+
return aLabel.localeCompare(bLabel, locale, { numeric: true }) || 0;
1024+
}
1025+
1026+
// Move items with no label to the end
1027+
if (!aLabel && bLabel) {
1028+
return 1;
1029+
}
1030+
1031+
if (aLabel && !bLabel) {
1032+
return -1;
1033+
}
1034+
1035+
return 0;
1036+
});
10161037
}
10171038
});
10181039

frontend/express/public/javascripts/countly/vue/components/helpers.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,13 @@
583583
},
584584
apps: function() {
585585
var apps = countlyGlobal.apps || {};
586+
let formattedApps = [];
586587

587588
if (this.auth && this.auth.feature && this.auth.permission) {
588589
var expectedPermission = this.auth.permission,
589590
targetFeature = this.auth.feature;
590591

591-
return Object.keys(apps).reduce(function(acc, key) {
592+
formattedApps = Object.keys(apps).reduce(function(acc, key) {
592593
var currentApp = apps[key];
593594

594595
if (countlyAuth.validate(expectedPermission, targetFeature, null, currentApp._id)) {
@@ -600,12 +601,34 @@
600601
return acc;
601602
}, []);
602603
}
604+
else {
605+
formattedApps = Object.keys(apps).map(function(key) {
606+
return {
607+
label: countlyCommon.unescapeHtml(apps[key].name),
608+
value: apps[key]._id
609+
};
610+
});
611+
}
603612

604-
return Object.keys(apps).map(function(key) {
605-
return {
606-
label: countlyCommon.unescapeHtml(apps[key].name),
607-
value: apps[key]._id
608-
};
613+
return formattedApps.sort(function(a, b) {
614+
const aLabel = a?.label || '';
615+
const bLabel = b?.label || '';
616+
const locale = countlyCommon.BROWSER_LANG || 'en';
617+
618+
if (aLabel && bLabel) {
619+
return aLabel.localeCompare(bLabel, locale, { numeric: true }) || 0;
620+
}
621+
622+
// Move items with no label to the end
623+
if (!aLabel && bLabel) {
624+
return 1;
625+
}
626+
627+
if (aLabel && !bLabel) {
628+
return -1;
629+
}
630+
631+
return 0;
609632
});
610633
}
611634
},

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,27 @@
336336
value: countlyGlobal.apps[apps[i]]._id
337337
});
338338
}
339+
340+
this.apps.sort(function(a, b) {
341+
const aLabel = a?.label || '';
342+
const bLabel = b?.label || '';
343+
const locale = countlyCommon.BROWSER_LANG || 'en';
344+
345+
if (aLabel && bLabel) {
346+
return aLabel.localeCompare(bLabel, locale, { numeric: true }) || 0;
347+
}
348+
349+
// Move items with no label to the end
350+
if (!aLabel && bLabel) {
351+
return 1;
352+
}
353+
354+
if (aLabel && !bLabel) {
355+
return -1;
356+
}
357+
358+
return 0;
359+
});
339360
}
340361
});
341362

@@ -434,4 +455,4 @@
434455
});
435456

436457
app.addMenu("management", {code: "data-migration", permission: FEATURE_NAME, url: "#/manage/data-migration", text: "data-migration.page-title", icon: '<div class="logo-icon fa fa-arrows-alt-h"></div>', priority: 70});
437-
})();
458+
})();

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@
449449
var apps = countlyGlobal.apps || {};
450450
var appKeys = Object.keys(apps);
451451
var formattedApps = [];
452+
452453
for (var i = 0; i < appKeys.length; i++) {
453454
formattedApps.push({
454455
label: apps[appKeys[i]].name,
@@ -457,12 +458,23 @@
457458
}
458459

459460
formattedApps.sort(function(a, b) {
460-
if (a.label < b.label) {
461-
return -1;
461+
const aLabel = a?.label || '';
462+
const bLabel = b?.label || '';
463+
const locale = countlyCommon.BROWSER_LANG || 'en';
464+
465+
if (aLabel && bLabel) {
466+
return aLabel.localeCompare(bLabel, locale, { numeric: true }) || 0;
462467
}
463-
if (a.label > b.label) {
468+
469+
// Move items with no label to the end
470+
if (!aLabel && bLabel) {
464471
return 1;
465472
}
473+
474+
if (aLabel && !bLabel) {
475+
return -1;
476+
}
477+
466478
return 0;
467479
});
468480

@@ -670,4 +682,4 @@
670682

671683
app.addMenu("management", {code: "db", permission: FEATURE_NAME, url: "#/manage/db", text: "dbviewer.title", priority: 120});
672684
}
673-
})();
685+
})();

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@
44
(function() {
55
var FEATURE_NAME = "hooks";
66

7+
var appsSortFunction = function(a, b) {
8+
const aLabel = a?.label || '';
9+
const bLabel = b?.label || '';
10+
const locale = countlyCommon.BROWSER_LANG || 'en';
11+
12+
if (aLabel && bLabel) {
13+
return aLabel.localeCompare(bLabel, locale, { numeric: true }) || 0;
14+
}
15+
16+
// Move items with no label to the end
17+
if (!aLabel && bLabel) {
18+
return 1;
19+
}
20+
21+
if (aLabel && !bLabel) {
22+
return -1;
23+
}
24+
25+
return 0;
26+
};
27+
728
var TableView = countlyVue.views.BaseView.extend({
829
template: '#hooks-table',
930
mixins: [
@@ -44,6 +65,9 @@
4465
for (var id in countlyGlobal.apps) {
4566
appsSelectorOption.push({label: countlyGlobal.apps[id].name, value: id, image: "background-image:url(" + countlyGlobal.apps[id].image + ")"});
4667
}
68+
69+
appsSelectorOption.sort(appsSortFunction);
70+
4771
return {
4872
appsSelectorOption: appsSelectorOption,
4973
filterStatus: 'all',
@@ -741,6 +765,9 @@
741765
}
742766
}
743767

768+
appsSelectorOption.sort(appsSortFunction);
769+
appsSelectorOption2.sort(appsSortFunction);
770+
744771
return {
745772
title: "",
746773
saveButtonLabel: "",

0 commit comments

Comments
 (0)