Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SER-1747] alerts table default order should be by creation time newest at the top #5717

Open
wants to merge 7 commits into
base: next
Choose a base branch
from
25 changes: 25 additions & 0 deletions bin/upgrade/DEV/add_creation_date_for_existing_alerts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Script that adds creation date for existing alerts.

const pluginManager = require('../../../plugins/pluginManager.js');

pluginManager.dbConnection().then(async(countlyDb) => {
try {
await countlyDb.collection('alerts').updateMany(
{ createdAt: { $exists: false } },
[
{
$set: {
createdAt: { $toDouble: { $toDate: "$_id" } }
}
}
]
);
console.log("Finished adding creation date for existing alerts.");
}
catch (error) {
console.log(`Error adding creation date for existing alerts: ${error}`);
}
finally {
countlyDb.close();
}
});
3 changes: 3 additions & 0 deletions plugins/alerts/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ const PERIOD_TO_TEXT_EXPRESSION_MAPPER = {
}
});
}
if (!alertConfig._id) {
alertConfig.createdAt = new Date().getTime();
}
alertConfig.createdBy = params.member._id;
return common.db.collection("alerts").insert(
alertConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@
enabled: alertsList[i].enabled || false,
createdByUser:
alertsList[i].createdByUser || "",
createdAt: alertsList[i].createdAt || "",
_canUpdate: countlyAuth.validateUpdate(
FEATURE_NAME,
countlyGlobal.member,
Expand Down
8 changes: 4 additions & 4 deletions plugins/alerts/frontend/public/localization/alerts.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ alert.plugin-title = Alerts

alert.Add_New_Alert=Add New Alert
alert.Edit_Your_Alert=Edit Your Alert
alert.Alert_Name=Alert Name
alerts.Alert_Name=Alert Name
alert.Event=Events
alert.View=Views
alert.Session=Sessions
Expand Down Expand Up @@ -59,9 +59,9 @@ alert.delete-confirm = Confirm to delete this alert?
alert.yes-delete-alert = Yes, delete alert
alert.email-place-holder=Enter emails
alert.enter-alert-name = Enter alert name
alert.Application = Application
alert.Condition = Condition
alert.CreateBy = Created by
alerts.Application = Application
alerts.Condition = Condition
alerts.CreateBy = Created by
alert.compare-remind = Metrics are compared on a daily basis.
alert.add-number = Add Number
alert.make-changes-remind = You made {0} changes.
Expand Down
12 changes: 7 additions & 5 deletions plugins/alerts/frontend/public/templates/vue-main.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
class="cly-vue-alerts-table"
:tracked-fields="localTableTrackedFields"
:rows="tableRows"
:resizable="false">
:resizable="false"
:default-sort="{prop: 'createdAt', order: 'descending'}"
>
<template v-slot:header-left="scope">
<div class="alerts-table-app-selector">
<cly-select-x
Expand All @@ -67,21 +69,21 @@
</template>
</el-table-column>

<el-table-column fixed min-width="240" prop="alertName" :label="i18n('alert.Alert_Name')" sortable="true">
<el-table-column fixed min-width="240" prop="alertName" :label="i18n('alerts.Alert_Name')" sortable="true">
<template slot-scope="scope">
<div style="text-overflow: ellipsis; overflow: hidden;" :data-test-id="'datatable-alert-name-' + scope.$index" v-html="scope.row.alertName"></div>
</template>
</el-table-column>

<template v-for="(col, idx) in scope.dynamicCols">
<el-table-column min-width="175" v-if="col.value === 'appNameList'" prop="appNameList" sortable="true" :label="i18n('alert.Application')">
<el-table-column min-width="175" v-if="col.value === 'appNameList'" prop="appNameList" sortable="true" :label="i18n('alerts.Application')">
<template slot-scope="scope">
<div :data-test-id="'datatable-application-' + scope.$index">
{{scope.row.appNameList}}
</div>
</template>
</el-table-column>
<el-table-column min-width="415" v-if="col.value === 'conditionText'" prop="conditionText" sortable="true" :label="i18n('alert.Condition')">
<el-table-column min-width="415" v-if="col.value === 'conditionText'" prop="conditionText" sortable="true" :label="i18n('alerts.Condition')">
<template slot-scope="scope" sortable="true">
<span :data-test-id="'datatable-condition-' + scope.$index">
{{unescapeHtml(scope.row.condtionText)}}
Expand All @@ -90,7 +92,7 @@
</el-table-column>
</template>

<el-table-column min-width="130" sortable="true" prop="createdByUser" :label="i18n('alert.CreateBy')">
<el-table-column min-width="130" sortable="true" prop="createdByUser" :label="i18n('alerts.CreateBy')">
<template slot-scope="scope">
<div class="bu-level">
<div class="bu-level-left">
Expand Down
Loading