Skip to content

Commit 69022df

Browse files
authored
Merge pull request #5717 from Countly/SER-1747-alerts-table-default-order-should-be-by-creation-time-newest-at-the-top
[SER-1747] alerts table default order should be by creation time newest at the top
2 parents f9849fd + 27c4ad8 commit 69022df

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 25.x.x
2+
Features:
3+
- [alerts] alerts table default order should be by creation time newest at the top
4+
15
## Version 24.12.x
26

37
Fixes:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Script that adds creation date for existing alerts.
2+
3+
const pluginManager = require('../../../plugins/pluginManager.js');
4+
5+
pluginManager.dbConnection().then(async(countlyDb) => {
6+
try {
7+
await countlyDb.collection('alerts').updateMany(
8+
{ createdAt: { $exists: false } },
9+
[
10+
{
11+
$set: {
12+
createdAt: { $toDouble: { $toDate: "$_id" } }
13+
}
14+
}
15+
]
16+
);
17+
console.log("Finished adding creation date for existing alerts.");
18+
}
19+
catch (error) {
20+
console.log(`Error adding creation date for existing alerts: ${error}`);
21+
}
22+
finally {
23+
countlyDb.close();
24+
}
25+
});

plugins/alerts/api/api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ const PERIOD_TO_TEXT_EXPRESSION_MAPPER = {
229229
}
230230
});
231231
}
232+
if (!alertConfig._id) {
233+
alertConfig.createdAt = new Date().getTime();
234+
}
232235
alertConfig.createdBy = params.member._id;
233236
return common.db.collection("alerts").insert(
234237
alertConfig,

plugins/alerts/frontend/public/javascripts/countly.models.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@
503503
enabled: alertsList[i].enabled || false,
504504
createdByUser:
505505
alertsList[i].createdByUser || "",
506+
createdAt: alertsList[i].createdAt || "",
506507
_canUpdate: countlyAuth.validateUpdate(
507508
FEATURE_NAME,
508509
countlyGlobal.member,

plugins/alerts/frontend/public/templates/vue-main.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
class="cly-vue-alerts-table"
4545
:tracked-fields="localTableTrackedFields"
4646
:rows="tableRows"
47-
:resizable="false">
47+
:resizable="false"
48+
:default-sort="{prop: 'createdAt', order: 'descending'}"
49+
>
4850
<template v-slot:header-left="scope">
4951
<div class="alerts-table-app-selector">
5052
<cly-select-x

0 commit comments

Comments
 (0)