Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
channel_settings: Split right-panel state from left tab in change_state.
Evy Kassirer227293abe5d8
diff --git a/web/src/channel_folders_popover.ts b/web/src/channel_folders_popover.tsindex 76dfb221d27..699d42f426d 100644--- a/web/src/channel_folders_popover.ts+++ b/web/src/channel_folders_popover.ts@@ -238,11 +238,11 @@ export function initialize(): void {assert(instance.reference instanceof HTMLElement);ui_util.show_left_sidebar_menu_icon(instance.reference);$popper.one("click", "#folder_popover_view_channels", () => {- let section = "all";+ let left_side_tab = "all";if (current_user.is_guest) {- section = "subscribed";+ left_side_tab = "subscribed";}- stream_settings_ui.launch(section, undefined, undefined, folder_id);+ stream_settings_ui.launch(undefined, left_side_tab, undefined, folder_id);});$popper.one("click", "#folder_popover_manage_folder", () => {channel_folders_ui.handle_editing_channel_folder(folder_id);diff --git a/web/src/hashchange.ts b/web/src/hashchange.tsindex 77f8d762a81..f2c1cdcd9d8 100644--- a/web/src/hashchange.ts+++ b/web/src/hashchange.ts@@ -1,4 +1,5 @@import $ from "jquery";+import assert from "minimalistic-assert";import * as z from "zod/mini";import * as about_zulip from "./about_zulip.ts";@@ -72,6 +73,29 @@ function is_somebody_else_profile_open(): boolean {);}+// The first slot of a channels-settings hash is overloaded:+// - "subscribed" / "available" / "all" → left-panel tab+// - "new" → create-channel form+// - a stream-id string → that channel's settings+// Disentangle it into the right-panel state and the left-side tab key+// that stream_settings_ui expects.+function channels_overlay_state_from_hash(): {+ right_panel: "new" | number | undefined;+ left_side_tab: string | undefined;+} {+ const hash_section = hash_parser.get_current_hash_section();+ if (hash_section === "new") {+ return {right_panel: "new", left_side_tab: undefined};+ }+ if (/^\d+$/.test(hash_section)) {+ return {right_panel: Number.parseInt(hash_section, 10), left_side_tab: undefined};+ }+ // validate_channels_settings_hash has already constrained+ // hash_section, so anything else is one of "subscribed" /+ // "available" / "all".+ return {right_panel: undefined, left_side_tab: hash_section};+}+function get_settings_tab(section: string): string | undefined {if (section === "users" || section === "bots") {const current_settings_tab = hash_parser.get_current_nth_hash_section(2);@@ -328,6 +352,7 @@ function do_hashchange_overlay(old_hash: string | undefined): void {if (base === "channels") {if (hash_parser.get_current_nth_hash_section(1) === "folders") {const folder_id = hash_parser.get_current_nth_hash_section(2);+ // Folder-create: show create form; left tab unchanged.stream_settings_ui.change_state("new",undefined,@@ -338,8 +363,9 @@ function do_hashchange_overlay(old_hash: string | undefined): void {}// e.g. #channels/29/social/subscribers+ const {right_panel, left_side_tab} = channels_overlay_state_from_hash();const right_side_tab = hash_parser.get_current_nth_hash_section(3);- stream_settings_ui.change_state(section, undefined, right_side_tab);+ stream_settings_ui.change_state(right_panel, left_side_tab, right_side_tab);return;}@@ -432,18 +458,20 @@ function do_hashchange_overlay(old_hash: string | undefined): void {}// e.g. #channels/29/social/subscribers+ const {right_panel, left_side_tab} = channels_overlay_state_from_hash();const right_side_tab = hash_parser.get_current_nth_hash_section(3);- if (is_somebody_else_profile_open()) {- stream_settings_ui.launch(section, "all", right_side_tab);+ // When somebody else's profile is open and we're navigating to+ // a specific channel, default the left tab to "All" instead of+ // inferring from subscription. URLs with a channel ID never+ // carry an explicit left tab, so this overrides nothing.+ if (is_somebody_else_profile_open() && typeof right_panel === "number") {+ assert(left_side_tab === undefined);+ stream_settings_ui.launch(right_panel, "all", right_side_tab);return;}- // We pass left_side_tab as undefined in change_state to- // select the tab based on user's subscriptions. "Subscribed" is- // selected if user is subscribed to the stream being edited.- // Otherwise "All streams" is selected.- stream_settings_ui.launch(section, undefined, right_side_tab);+ stream_settings_ui.launch(right_panel, left_side_tab, right_side_tab);return;}diff --git a/web/src/stream_settings_ui.ts b/web/src/stream_settings_ui.tsindex b56d7b06c38..e320eb494f6 100644--- a/web/src/stream_settings_ui.ts+++ b/web/src/stream_settings_ui.ts@@ -1120,87 +1120,91 @@ function show_right_section(): void {$("#subscription_overlay .two-pane-settings-header").addClass("slide-left");}+// `right_panel` controls the right panel:+// - "new" → show the create-channel form+// - a channel-ID number → show that channel's settings+// - undefined → empty right panel+// `left_side_tab` controls the left panel ("subscribed" / "available" /+// "all"). URLs that target the right panel instead (e.g.+// #channels/new) don't carry a left tab, so this is undefined in+// those cases.+// `right_side_tab` is the in-channel tab (general / personal /+// subscribers / permissions); meaningful only when right_panel is a+// channel ID.export function change_state(- section: string,+ right_panel: "new" | number | undefined,left_side_tab: string | undefined,right_side_tab: string | undefined,folder_id?: number,): void {assert(toggler !== undefined);- // if in #channels/new form.- if (section === "new") {++ // Right panel: create form.+ if (right_panel === "new") {do_open_create_stream(folder_id);show_right_section();+ // We don't change the left side tab when opening the+ // channel creation flow.+ assert(left_side_tab === undefined);return;}- if (section === "all") {- if (folder_id !== undefined) {+ // Right panel: empty.+ if (right_panel === undefined) {+ assert(left_side_tab !== undefined);+ // For viewing all streams in a particular folder. Must run+ // before toggler.goto so the left-panel redraw it triggers+ // picks up the new folder filter.+ if (left_side_tab === "all" && folder_id !== undefined) {stream_settings_components.set_folder_filter_dropdown_value(folder_id);}- toggler.goto("all");+ toggler.goto(left_side_tab);stream_edit.empty_right_panel();return;}- if (section === "available") {- toggler.goto("available");- stream_edit.empty_right_panel();- return;- }+ // Right panel: stream-edit.+ const stream_id = right_panel;+ show_right_section();+ assert(right_side_tab !== undefined);+ stream_edit_toggler.set_select_tab(right_side_tab);- // if the section is a valid number.- if (/\d+/.test(section)) {- const stream_id = Number.parseInt(section, 10);- show_right_section();- assert(right_side_tab !== undefined);- stream_edit_toggler.set_select_tab(right_side_tab);+ // If undefined, infer the left side tab depending on subscription status.+ left_side_tab ??= stream_data.is_subscribed(stream_id) ? "subscribed" : "all";- if (left_side_tab === undefined) {- left_side_tab = "all";- if (stream_data.is_subscribed(stream_id)) {- left_side_tab = "subscribed";- }- }-- // Callback to .goto() will update browser_history unless a- // stream is being edited. We are always editing a stream here- // so its safe to call- if (left_side_tab !== toggler.key()) {- toggler.goto(left_side_tab);- }- switch_to_stream_row(stream_id);+ // Callback to .goto() will update browser_history unless a+ // stream is being edited. We are always editing a stream here+ // so its safe to call+ if (left_side_tab !== toggler.key()) {+ toggler.goto(left_side_tab);+ }+ switch_to_stream_row(stream_id);- const sub = stream_data.get_sub_by_id(stream_id);- if (sub && !stream_settings_components.archived_status_filter_includes_channel(sub)) {- const FILTERS = stream_settings_data.ARCHIVED_STATUS_FILTERS;- let selected_filter;- if (sub.is_archived) {- selected_filter = FILTERS.ARCHIVED_CHANNELS;- } else {- selected_filter = FILTERS.NON_ARCHIVED_CHANNELS;- }- stream_settings_components.set_archived_status_filter_dropdown_value(selected_filter);+ const sub = stream_data.get_sub_by_id(stream_id);+ if (sub && !stream_settings_components.archived_status_filter_includes_channel(sub)) {+ const FILTERS = stream_settings_data.ARCHIVED_STATUS_FILTERS;+ let selected_filter;+ if (sub.is_archived) {+ selected_filter = FILTERS.ARCHIVED_CHANNELS;+ } else {+ selected_filter = FILTERS.NON_ARCHIVED_CHANNELS;}- if (sub && !stream_settings_components.folder_filter_includes_channel(sub)) {- const folder_filters = folder_filter_dropdown_widget.FOLDER_FILTERS;- let selected_filter;- if (sub.folder_id === null) {- selected_filter = folder_filters.UNCATEGORIZED_DROPDOWN_OPTION;- } else {- selected_filter = sub.folder_id;- }- stream_settings_components.set_folder_filter_dropdown_value(selected_filter);+ stream_settings_components.set_archived_status_filter_dropdown_value(selected_filter);+ }+ if (sub && !stream_settings_components.folder_filter_includes_channel(sub)) {+ const folder_filters = folder_filter_dropdown_widget.FOLDER_FILTERS;+ let selected_filter;+ if (sub.folder_id === null) {+ selected_filter = folder_filters.UNCATEGORIZED_DROPDOWN_OPTION;+ } else {+ selected_filter = sub.folder_id;}- return;+ stream_settings_components.set_folder_filter_dropdown_value(selected_filter);}-- toggler.goto("subscribed");- stream_edit.empty_right_panel();}export function launch(- section: string,+ right_panel: "new" | number | undefined,left_side_tab: string | undefined,right_side_tab: string | undefined,folder_id?: number,@@ -1213,10 +1217,10 @@ export function launch(browser_history.exit_overlay();},});- change_state(section, left_side_tab, right_side_tab, folder_id);+ change_state(right_panel, left_side_tab, right_side_tab, folder_id);setTimeout(() => {if (!stream_settings_components.get_active_data().id) {- if (section === "new") {+ if (right_panel === "new") {$("#create_stream_name").trigger("focus");} else {$("#search_stream_name").trigger("focus");