Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

stream_settings: Fix stream row switching behavior.

PieterCK2457a8b655dc
diff --git a/web/src/hash_parser.ts b/web/src/hash_parser.ts
index 2a4ad27e84f..5bc832190e1 100644
--- a/web/src/hash_parser.ts
+++ b/web/src/hash_parser.ts
@@ -91,6 +91,20 @@ export function is_create_new_stream_narrow(): boolean {
return window.location.hash === "#streams/new";
}
+// This checks whether the user is in the stream settings menu
+// and is opening the 'Subscribers' tab on the right panel.
+export function is_subscribers_section_opened_for_stream(): boolean {
+ const hash_components = window.location.hash.slice(1).split(/\//);
+
+ if (hash_components[0] !== "streams") {
+ return false;
+ }
+ if (!hash_components[3]) {
+ return false;
+ }
+ return hash_components[3] === "subscribers";
+}
+
export const allowed_web_public_narrows = [
"channels",
"channel",
diff --git a/web/src/stream_settings_ui.js b/web/src/stream_settings_ui.js
index 0f20a5d3b49..405e6dc11b7 100644
--- a/web/src/stream_settings_ui.js
+++ b/web/src/stream_settings_ui.js
@@ -794,10 +794,17 @@ export function launch(section, left_side_tab, right_side_tab) {
export function switch_rows(event) {
const active_data = stream_settings_components.get_active_data();
+ const $add_subscriber_pill_input = $(".add_subscribers_container .input");
let $switch_row;
if (hash_parser.is_create_new_stream_narrow()) {
// Prevent switching stream rows when creating a new stream
return false;
+ } else if (
+ hash_parser.is_subscribers_section_opened_for_stream() &&
+ $add_subscriber_pill_input.is(":focus")
+ ) {
+ // Prevent switching stream rows when adding a subscriber
+ return false;
} else if (!active_data.id || active_data.$row.hasClass("notdisplayed")) {
$switch_row = $("div.stream-row:not(.notdisplayed)").first();
if ($("#search_stream_name").is(":focus")) {
diff --git a/web/tests/hash_util.test.js b/web/tests/hash_util.test.js
index 4e657ec7b76..231f72560f4 100644
--- a/web/tests/hash_util.test.js
+++ b/web/tests/hash_util.test.js
@@ -161,6 +161,23 @@ run_test("test_is_create_new_stream_narrow", () => {
assert.equal(hash_parser.is_create_new_stream_narrow(), false);
});
+run_test("test_is_subscribers_section_opened_for_stream", () => {
+ window.location.hash = "#streams/1/Design/subscribers";
+ assert.equal(hash_parser.is_subscribers_section_opened_for_stream(), true);
+
+ window.location.hash = "#streams/99/.EC.A1.B0.EB.A6.AC.EB.B2.95.20.F0.9F.98.8E/subscribers";
+ assert.equal(hash_parser.is_subscribers_section_opened_for_stream(), true);
+
+ window.location.hash = "#streams/random/subscribers";
+ assert.equal(hash_parser.is_subscribers_section_opened_for_stream(), false);
+
+ window.location.hash = "#some/random/place/subscribers";
+ assert.equal(hash_parser.is_subscribers_section_opened_for_stream(), false);
+
+ window.location.hash = "#";
+ assert.equal(hash_parser.is_subscribers_section_opened_for_stream(), false);
+});
+
run_test("test_parse_narrow", () => {
assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "99-frontend"]), [
{negated: false, operator: "stream", operand: "frontend"},