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.
This commit is contained in:
Sahil Batra 2024-10-02 23:17:04 +05:30 committed by Tim Abbott
parent 7bd5ec28ae
commit 4b206b7394
2 changed files with 6 additions and 7 deletions

View File

@ -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);
}
}
}

View File

@ -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 {