settings: Migrate notification checkboxes to table format.

Here we have migrated checkboxes of all general notifications to the table.
By general notifications we mean, Mobile, Email, Desktop audio, and visual
notifications.

This is a part of a bigger migration to simply our notifications setting
changing infrastructure for all streams and individual streams. Later we
will add more row to this for different categories of notifications in
addition to the current ones ("Streams" and "PMs, mentions, alerts").

Fixes: #12182.
This commit is contained in:
Pragati Agrawal
2020-03-23 12:59:48 +05:30
committed by Tim Abbott
parent 2f213f7c8e
commit dd13136371
9 changed files with 117 additions and 70 deletions

View File

@@ -1,4 +1,12 @@
const stream_notification_settings = [
const general_notifications_table_columns = [
/* An array of notification settings of any category like
* `stream_notification_settings` which makes a single row of
* "Notification triggers" table should follow this order
*/
"visual", "audio", "mobile", "email", "all_mentions",
];
exports.stream_notification_settings = [
"enable_stream_desktop_notifications",
"enable_stream_audible_notifications",
"enable_stream_push_notifications",
@@ -37,20 +45,51 @@ const other_notification_settings = desktop_notification_settings.concat(
exports.all_notification_settings = other_notification_settings.concat(
pm_mention_notification_settings,
stream_notification_settings
exports.stream_notification_settings
);
function get_notifications_table_row_data(notify_settings) {
return general_notifications_table_columns.map((column, index) => {
const setting_name = notify_settings[index];
if (setting_name === undefined) {
return {
setting_name: "",
is_disabled: true,
is_checked: false,
};
}
const checkbox = {
setting_name: setting_name,
is_disabled: false,
};
if (column === "mobile") {
checkbox.is_disabled = !page_params.realm_push_notifications_enabled;
}
checkbox.is_checked = page_params[setting_name];
return checkbox;
});
}
exports.all_notifications = {
general_settings: [
{
label: i18n.t("Streams"),
notification_settings: get_notifications_table_row_data(
exports.stream_notification_settings),
},
{
label: i18n.t("PMs, mentions, and alerts"),
notification_settings: get_notifications_table_row_data(
pm_mention_notification_settings),
},
],
settings: {
stream_notification_settings: stream_notification_settings,
pm_mention_notification_settings: pm_mention_notification_settings,
desktop_notification_settings: desktop_notification_settings,
mobile_notification_settings: mobile_notification_settings,
email_notification_settings: email_notification_settings,
},
show_push_notifications_tooltip: {
enable_stream_push_notifications: !page_params.realm_push_notifications_enabled,
enable_offline_push_notifications: !page_params.realm_push_notifications_enabled,
enable_online_push_notifications: !page_params.realm_push_notifications_enabled,
},
};