settings: Refactor code to handle tabs in user settings.

This commit updates code which handles user settings tab to refactor
and rename functions and variables in such a way that they can be
used for bot settings tabs as well in further commits.

Changes done are:
- Renamed handle_invalid_users_section_url to handle_invalid_section_url
and also updated it such that it can be used for sections other than
"users" as well.
- Renamed get_user_settings_tab to get_settings_tab and also
updated its variable names similarly.
- Updated name for tab variables in activate_section_or_default and
admin.launch functions similarly.

Fixes part of #31156.
This commit is contained in:
Maneesh Shukla 2025-08-21 18:52:11 +05:30 committed by Tim Abbott
parent 9e5622bd30
commit 7784a5eb53
3 changed files with 21 additions and 18 deletions

View File

@ -329,7 +329,7 @@ export function build_page(): void {
}
}
export function launch(section: string, user_settings_tab: string | undefined): void {
export function launch(section: string, settings_tab: string | undefined): void {
settings_sections.reset_sections();
settings.open_settings_overlay();
@ -337,7 +337,7 @@ export function launch(section: string, user_settings_tab: string | undefined):
settings_panel_menu.org_settings.set_current_tab(section);
}
if (section === "users") {
settings_panel_menu.org_settings.set_user_settings_tab(user_settings_tab);
settings_panel_menu.org_settings.set_user_settings_tab(settings_tab);
}
settings_toggle.goto("organization");
}

View File

@ -74,20 +74,23 @@ function is_somebody_else_profile_open(): boolean {
);
}
function handle_invalid_users_section_url(user_settings_tab: string): string {
const valid_user_settings_tab_values = new Set(["active", "deactivated", "invitations"]);
if (!valid_user_settings_tab_values.has(user_settings_tab)) {
const valid_users_section_url = "#organization/users/active";
browser_history.update(valid_users_section_url);
return "active";
function handle_invalid_section_url(section: "users", settings_tab: string): string {
const valid_tab_values = {
users: new Set(["active", "deactivated", "invitations"]),
};
if (!valid_tab_values[section].has(settings_tab)) {
const valid_section_url = `#organization/${section}/${[...valid_tab_values[section]][0]}`;
browser_history.update(valid_section_url);
return [...valid_tab_values[section]][0]!;
}
return user_settings_tab;
return settings_tab;
}
function get_user_settings_tab(section: string): string | undefined {
function get_settings_tab(section: string): string | undefined {
if (section === "users") {
const current_user_settings_tab = hash_parser.get_current_nth_hash_section(2);
return handle_invalid_users_section_url(current_user_settings_tab);
const current_settings_tab = hash_parser.get_current_nth_hash_section(2);
return handle_invalid_section_url(section, current_settings_tab);
}
return undefined;
}
@ -387,7 +390,7 @@ function do_hashchange_overlay(old_hash: string | undefined): void {
}
settings_panel_menu.org_settings.activate_section_or_default(
section,
get_user_settings_tab(section),
get_settings_tab(section),
);
return;
}
@ -409,7 +412,7 @@ function do_hashchange_overlay(old_hash: string | undefined): void {
settings_panel_menu.normal_settings.set_current_tab(section);
} else {
settings_panel_menu.org_settings.set_current_tab(section);
settings_panel_menu.org_settings.set_user_settings_tab(get_user_settings_tab(section));
settings_panel_menu.org_settings.set_user_settings_tab(get_settings_tab(section));
}
settings_toggle.goto(base);
return;
@ -483,7 +486,7 @@ function do_hashchange_overlay(old_hash: string | undefined): void {
if (base === "organization") {
settings.build_page();
admin.build_page();
admin.launch(section, get_user_settings_tab(section));
admin.launch(section, get_settings_tab(section));
return;
}

View File

@ -187,7 +187,7 @@ export class SettingsPanelMenu {
activate_section_or_default(
section: string | undefined,
user_settings_tab?: string,
settings_tab?: string,
activate_section_for_mobile = true,
): void {
popovers.hide_all();
@ -225,9 +225,9 @@ export class SettingsPanelMenu {
browser_history.update_hash_internally_if_required(settings_section_hash);
}
if (section === "users" && this.org_user_settings_toggler !== undefined) {
assert(user_settings_tab !== undefined);
assert(settings_tab !== undefined);
this.show_org_user_settings_toggler();
this.org_user_settings_toggler.goto(user_settings_tab);
this.org_user_settings_toggler.goto(settings_tab);
}
$(".settings-section").removeClass("show");