js: Break cyclic dependency between `admin.js` and `settings.js`.

There was a direct dependency between `admin.js` and `settings.js` which
was due to the fact that we needed to call `build_page` of both modules
in each other's `launch` function.

This is solved by lifting those `build_page` calls up from both modules to
`hashchange.js` which is the module which calls the `launch` function
of both modules.
This commit is contained in:
Lalit 2023-04-15 22:22:44 +05:30 committed by Tim Abbott
parent 98176ddb57
commit 915b6cd9e7
4 changed files with 10 additions and 5 deletions

View File

@ -231,8 +231,6 @@ export function build_page() {
} }
export function launch(section) { export function launch(section) {
settings.build_page();
build_page();
settings_sections.reset_sections(); settings_sections.reset_sections();
settings.open_settings_overlay(); settings.open_settings_overlay();

View File

@ -343,11 +343,15 @@ function do_hashchange_overlay(old_hash) {
} }
if (base === "settings") { if (base === "settings") {
settings.build_page();
admin.build_page();
settings.launch(section); settings.launch(section);
return; return;
} }
if (base === "organization") { if (base === "organization") {
settings.build_page();
admin.build_page();
admin.launch(section); admin.launch(section);
return; return;
} }

View File

@ -5,7 +5,6 @@ import timezones from "../generated/timezones.json";
import render_settings_overlay from "../templates/settings_overlay.hbs"; import render_settings_overlay from "../templates/settings_overlay.hbs";
import render_settings_tab from "../templates/settings_tab.hbs"; import render_settings_tab from "../templates/settings_tab.hbs";
import * as admin from "./admin";
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import * as browser_history from "./browser_history"; import * as browser_history from "./browser_history";
import {$t, $t_html} from "./i18n"; import {$t, $t_html} from "./i18n";
@ -134,8 +133,6 @@ export function open_settings_overlay() {
} }
export function launch(section) { export function launch(section) {
build_page();
admin.build_page();
settings_sections.reset_sections(); settings_sections.reset_sections();
open_settings_overlay(); open_settings_overlay();

View File

@ -125,11 +125,13 @@ function test_helper({override, change_tab}) {
} }
stub(admin, "launch"); stub(admin, "launch");
stub(admin, "build_page");
stub(drafts, "launch"); stub(drafts, "launch");
stub(message_viewport, "stop_auto_scrolling"); stub(message_viewport, "stop_auto_scrolling");
stub(narrow, "deactivate"); stub(narrow, "deactivate");
stub(overlays, "close_for_hash_change"); stub(overlays, "close_for_hash_change");
stub(settings, "launch"); stub(settings, "launch");
stub(settings, "build_page");
stub(stream_settings_ui, "launch"); stub(stream_settings_ui, "launch");
stub(ui_util, "blur_active_element"); stub(ui_util, "blur_active_element");
stub(ui_report, "error"); stub(ui_report, "error");
@ -294,6 +296,8 @@ run_test("hash_interactions", ({override}) => {
$window_stub.trigger("hashchange"); $window_stub.trigger("hashchange");
helper.assert_events([ helper.assert_events([
[overlays, "close_for_hash_change"], [overlays, "close_for_hash_change"],
[settings, "build_page"],
[admin, "build_page"],
[settings, "launch"], [settings, "launch"],
]); ]);
@ -303,6 +307,8 @@ run_test("hash_interactions", ({override}) => {
$window_stub.trigger("hashchange"); $window_stub.trigger("hashchange");
helper.assert_events([ helper.assert_events([
[overlays, "close_for_hash_change"], [overlays, "close_for_hash_change"],
[settings, "build_page"],
[admin, "build_page"],
[admin, "launch"], [admin, "launch"],
]); ]);