settings: Move init disable button function.

This commit moves the function
initialize_disable_btn_hint_popover from
stream_ui_updates.js to settings_components.js
due to circular dependencies.
Added opts parameter to append to the options for
the tippy instance.

Fixes #27511.

Co-authored-by: Angelica Ferlin <angelica.ferlin@gmail.com>
Co-authored-by: Peterson Linn <linn@pajp.net>
Co-authored-by: Kislay Verma <kislayuv27@gmail.com>
This commit is contained in:
Kislay Verma 2024-04-03 19:44:34 +05:30 committed by Tim Abbott
parent d82f33a3c8
commit 5f35384c80
4 changed files with 32 additions and 23 deletions

View File

@ -1,5 +1,7 @@
import $ from "jquery"; import $ from "jquery";
import assert from "minimalistic-assert"; import assert from "minimalistic-assert";
import type {Props} from "tippy.js";
import tippy from "tippy.js";
import render_compose_banner from "../templates/compose_banner/compose_banner.hbs"; import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
@ -918,3 +920,23 @@ function enable_or_disable_save_button($subsection_elem: JQuery): void {
$subsection_elem.find(".subsection-changes-save button").prop("disabled", disable_save_btn); $subsection_elem.find(".subsection-changes-save button").prop("disabled", disable_save_btn);
} }
export function initialize_disable_btn_hint_popover(
$btn_wrapper: JQuery,
hint_text: string | undefined,
opts: Partial<Props>,
): void {
const tippy_opts: Partial<Props> = {
animation: false,
hideOnClick: false,
placement: "bottom",
...opts,
};
// If hint_text is undefined, we use the HTML content of a
// <template> whose id is given by data-tooltip-template-id
if (hint_text !== undefined) {
tippy_opts.content = hint_text;
}
tippy($btn_wrapper[0], tippy_opts);
}

View File

@ -1,5 +1,4 @@
import $ from "jquery"; import $ from "jquery";
import tippy from "tippy.js";
import render_announce_stream_checkbox from "../templates/stream_settings/announce_stream_checkbox.hbs"; import render_announce_stream_checkbox from "../templates/stream_settings/announce_stream_checkbox.hbs";
import render_stream_privacy_icon from "../templates/stream_settings/stream_privacy_icon.hbs"; import render_stream_privacy_icon from "../templates/stream_settings/stream_privacy_icon.hbs";
@ -7,6 +6,7 @@ import render_stream_settings_tip from "../templates/stream_settings/stream_sett
import * as hash_parser from "./hash_parser"; import * as hash_parser from "./hash_parser";
import {$t} from "./i18n"; import {$t} from "./i18n";
import * as settings_components from "./settings_components";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
@ -114,24 +114,9 @@ export function update_private_stream_privacy_option_state($container, is_defaul
.toggleClass("default_stream_private_tooltip", is_default_stream); .toggleClass("default_stream_private_tooltip", is_default_stream);
} }
export function initialize_disable_btn_hint_popover($btn_wrapper, hint_text) {
const opts = {
animation: false,
hideOnClick: false,
placement: "bottom",
};
// If hint_text is undefined, we use the HTML content of a
// <template> whose id is given by data-tooltip-template-id
if (hint_text !== undefined) {
opts.content = hint_text;
}
tippy($btn_wrapper[0], opts);
}
export function initialize_cant_subscribe_popover() { export function initialize_cant_subscribe_popover() {
const $button_wrapper = $(".settings .stream_settings_header .sub_unsub_button_wrapper"); const $button_wrapper = $(".settings .stream_settings_header .sub_unsub_button_wrapper");
initialize_disable_btn_hint_popover($button_wrapper); settings_components.initialize_disable_btn_hint_popover($button_wrapper);
} }
export function set_up_right_panel_section(sub) { export function set_up_right_panel_section(sub) {
@ -384,7 +369,10 @@ export function update_add_subscriptions_elements(sub) {
defaultMessage: "Only stream members can add users to a private stream.", defaultMessage: "Only stream members can add users to a private stream.",
}); });
} }
initialize_disable_btn_hint_popover($add_subscribers_container, tooltip_message); settings_components.initialize_disable_btn_hint_popover(
$add_subscribers_container,
tooltip_message,
);
} }
} }

View File

@ -23,7 +23,6 @@ import * as settings_components from "./settings_components";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import {current_user, realm} from "./state_data"; import {current_user, realm} from "./state_data";
import * as stream_ui_updates from "./stream_ui_updates";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as user_group_components from "./user_group_components"; import * as user_group_components from "./user_group_components";
import * as user_group_create from "./user_group_create"; import * as user_group_create from "./user_group_create";
@ -96,7 +95,7 @@ function update_add_members_elements(group) {
$button_element.prop("disabled", true); $button_element.prop("disabled", true);
$add_members_container.addClass("add_members_disabled"); $add_members_container.addClass("add_members_disabled");
stream_ui_updates.initialize_disable_btn_hint_popover( settings_components.initialize_disable_btn_hint_popover(
$add_members_container, $add_members_container,
$t({defaultMessage: "Only group members can add users to a group."}), $t({defaultMessage: "Only group members can add users to a group."}),
); );
@ -149,7 +148,7 @@ function initialize_tooltip_for_membership_button(group_id) {
} else { } else {
tooltip_message = $t({defaultMessage: "You do not have permission to join this group."}); tooltip_message = $t({defaultMessage: "You do not have permission to join this group."});
} }
stream_ui_updates.initialize_disable_btn_hint_popover($tooltip_wrapper, tooltip_message); settings_components.initialize_disable_btn_hint_popover($tooltip_wrapper, tooltip_message);
} }
function update_group_membership_button(group_id) { function update_group_membership_button(group_id) {

View File

@ -30,12 +30,12 @@ import * as loading from "./loading";
import * as modals from "./modals"; import * as modals from "./modals";
import * as peer_data from "./peer_data"; import * as peer_data from "./peer_data";
import * as people from "./people"; import * as people from "./people";
import * as settings_components from "./settings_components";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_profile_fields from "./settings_profile_fields"; import * as settings_profile_fields from "./settings_profile_fields";
import {current_user, realm} from "./state_data"; import {current_user, realm} from "./state_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_ui_updates from "./stream_ui_updates";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import * as subscriber_api from "./subscriber_api"; import * as subscriber_api from "./subscriber_api";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
@ -142,7 +142,7 @@ function change_state_of_subscribe_button(event, dropdown) {
function reset_subscribe_widget() { function reset_subscribe_widget() {
$("#user-profile-modal .add-subscription-button").prop("disabled", true); $("#user-profile-modal .add-subscription-button").prop("disabled", true);
stream_ui_updates.initialize_disable_btn_hint_popover( settings_components.initialize_disable_btn_hint_popover(
$("#user-profile-modal .add-subscription-button-wrapper"), $("#user-profile-modal .add-subscription-button-wrapper"),
$t({defaultMessage: "Select a stream to subscribe"}), $t({defaultMessage: "Select a stream to subscribe"}),
); );