From 4b206b739435655a8ea7380cae2b4a79f7624b2c Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 2 Oct 2024 23:17:04 +0530 Subject: [PATCH] settings: Refactor code to set group setting pill widget value. This commit refactors set_group_setting_widget_value function to accept pill widget as parameter instead of setting name. This is a prep commit for not needing to store the widgets for group creation form in settings_components.group_setting_widget_map. --- web/src/settings_components.ts | 10 ++++------ web/src/settings_org.js | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/web/src/settings_components.ts b/web/src/settings_components.ts index 35381ac075..d4988172b4 100644 --- a/web/src/settings_components.ts +++ b/web/src/settings_components.ts @@ -1414,11 +1414,9 @@ export function get_group_setting_widget(setting_name: string): GroupSettingPill } export function set_group_setting_widget_value( - property_name: string, + pill_widget: GroupSettingPillContainer, property_value: GroupSettingType, ): void { - const pill_widget = get_group_setting_widget(property_name); - assert(pill_widget !== null); pill_widget.clear(); if (typeof property_value === "number") { @@ -1476,7 +1474,7 @@ export function create_group_setting_widget({ } if (group !== undefined) { - set_group_setting_widget_value(setting_name, group[setting_name]); + set_group_setting_widget_value(pill_widget, group[setting_name]); pill_widget.onPillCreate(() => { save_discard_group_widget_status_handler($("#group_permission_settings"), group); @@ -1490,13 +1488,13 @@ export function create_group_setting_widget({ "group", )!.default_group_name; if (default_group_name === "group_creator") { - set_group_setting_widget_value("new_group_" + setting_name, { + set_group_setting_widget_value(pill_widget, { direct_members: [current_user.user_id], direct_subgroups: [], }); } else { const default_group_id = user_groups.get_user_group_from_name(default_group_name)!.id; - set_group_setting_widget_value("new_group_" + setting_name, default_group_id); + set_group_setting_widget_value(pill_widget, default_group_id); } } } diff --git a/web/src/settings_org.js b/web/src/settings_org.js index 15971772a9..a5d9f8e34b 100644 --- a/web/src/settings_org.js +++ b/web/src/settings_org.js @@ -617,7 +617,8 @@ export function discard_group_property_element_changes(elem, group) { if (property_name === "can_mention_group") { settings_components.set_dropdown_list_widget_setting_value(property_name, property_value); } else if (property_name === "can_manage_group") { - settings_components.set_group_setting_widget_value(property_name, property_value); + const pill_widget = settings_components.get_group_setting_widget(property_name); + settings_components.set_group_setting_widget_value(pill_widget, property_value); } else if (property_value !== undefined) { settings_components.set_input_element_value($elem, property_value); } else {