From 96abf2501a413fa2167c82d5b55a8f6ab696a6a4 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 11 Oct 2024 21:11:34 +0530 Subject: [PATCH] user_groups: Handle live-update of group settings like other settings. This commit updates live-update of group settings like we do for stream and realm settings. Current behavior is - - If the save discard buttons are visible, meaning that the current user was in the middle of changing a setting, then all the settings elements are synced to the original value irrespective of whether that setting was actual updated, including the setting which the current user was changing. - If the save discard buttons are not visible, then only the element of updated setting is synced as it is not needed to reset the UI for other settings. We make the change similar to what we did for realm and stream settings in 5da1e57fc28. 5da1e57fc28 did not had the changes for group settings since we had only one group setting then but now we have multiple settings. --- web/src/user_group_edit.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/web/src/user_group_edit.js b/web/src/user_group_edit.js index 42a099627f..cd8df8c62d 100644 --- a/web/src/user_group_edit.js +++ b/web/src/user_group_edit.js @@ -354,20 +354,10 @@ export function handle_member_edit_event(group_id, user_ids) { } } -export function update_settings_pane(group) { +export function update_group_details(group) { const $edit_container = get_edit_container(group); $edit_container.find(".group-name").text(group.name); $edit_container.find(".group-description").text(group.description); - - const $subsection = $edit_container.find(".settings-subsection-parent"); - // We currently have only one group-level setting, so it is - // fine to just call the function to discard changes in the - // complete subsection. - // - // We can update this code to be similar to how we handle realm - // settings in settings_org.sync_realm_settings when we add more - // group-level settings. - settings_org.discard_group_settings_subsection_changes($subsection, group); } function update_toggler_for_group_setting() { @@ -618,6 +608,16 @@ export function add_group_to_table(group) { } } +export function sync_group_permission_setting(property, group) { + const $elem = $(`#id_${CSS.escape(property)}`); + const $subsection = $elem.closest(".settings-subsection-parent"); + if ($subsection.find(".save-button-controls").hasClass("hide")) { + settings_org.discard_group_property_element_changes($elem, group); + } else { + settings_org.discard_group_settings_subsection_changes($subsection, group); + } +} + export function update_group(event) { if (!overlays.groups_open()) { return; @@ -643,15 +643,20 @@ export function update_group(event) { if (get_active_data().id === group.id) { // update right side pane - update_settings_pane(group); + update_group_details(group); if (event.data.name !== undefined) { // update settings title $("#groups_overlay .user-group-info-title").text(group.name); } + if (event.data.can_mention_group !== undefined) { + sync_group_permission_setting("can_mention_group", group); + } if (event.data.can_manage_group !== undefined) { + sync_group_permission_setting("can_manage_group", group); update_group_management_ui(); } if (event.data.can_join_group !== undefined) { + sync_group_permission_setting("can_mention_group", group); update_group_membership_button(group.id); } }