Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_header: Update topic visibility button to use icon button.
Sayam Samale091e1903130
diff --git a/web/src/message_list_tooltips.ts b/web/src/message_list_tooltips.tsindex 2eab1cd48b8..766c5c85365 100644--- a/web/src/message_list_tooltips.ts+++ b/web/src/message_list_tooltips.ts@@ -310,9 +310,12 @@ export function initialize(): void {},);- message_list_tooltip("#message_feed_container .change_visibility_policy > i", {- ...topic_visibility_policy_tooltip_props,- });+ message_list_tooltip(+ "#message_feed_container .change_visibility_policy > .recipient-bar-control-icon",+ {+ ...topic_visibility_policy_tooltip_props,+ },+ );message_list_tooltip("#message_feed_container .recipient-bar-control-icon:not(.toggle_resolve_topic_spinner)", {delay: LONG_HOVER_DELAY,diff --git a/web/src/tippyjs.ts b/web/src/tippyjs.tsindex 78fbf874052..55abfce8182 100644--- a/web/src/tippyjs.ts+++ b/web/src/tippyjs.ts@@ -87,21 +87,27 @@ export const topic_visibility_policy_tooltip_props = {delay: LONG_HOVER_DELAY,appendTo: () => document.body,onShow(instance: tippy.Instance) {- const $elem = $(instance.reference);let should_render_privacy_icon;- let current_visibility_policy_str;- if ($elem.hasClass("zulip-icon-inherit")) {- should_render_privacy_icon = true;- } else {- should_render_privacy_icon = false;- current_visibility_policy_str = $elem.attr("data-tippy-content");- }let current_stream_obj;- if (should_render_privacy_icon) {+ const $elem = $(instance.reference);+ if ($elem.hasClass("recipient-bar-control-icon")) {+ // The topic visibility policy button located in the recipient bar+ // uses the icon button component, and extracts the stream id from+ // the message header instead of the button itself. This results in+ // the need for a different logic to extract the required data.+ should_render_privacy_icon = $elem+ .children(".zulip-icon")+ .hasClass("zulip-icon-inherit");+ current_stream_obj = stream_data.get_sub_by_id(+ Number($elem.closest(".message_header").attr("data-stream-id")),+ );+ } else {+ should_render_privacy_icon = $elem.hasClass("zulip-icon-inherit");current_stream_obj = stream_data.get_sub_by_id(Number($elem.parent().attr("data-stream-id")),);}+ const current_visibility_policy_str = $elem.attr("data-tippy-content");const tooltip_context = {...current_stream_obj,current_visibility_policy_str,diff --git a/web/src/user_topic_popover.ts b/web/src/user_topic_popover.tsindex 4bfce23f202..a25446f1ba2 100644--- a/web/src/user_topic_popover.ts+++ b/web/src/user_topic_popover.ts@@ -9,6 +9,21 @@ import {parse_html} from "./ui_util.ts";import * as user_topics from "./user_topics.ts";import * as util from "./util.ts";+const extract_visibility_policy_popover_context = (+ $element: JQuery,+): {+ stream_id: number;+ topic_name: string;+} => {+ const stream_id_str = $element.attr("data-stream-id");+ assert(stream_id_str !== undefined);+ const stream_id = Number.parseInt(stream_id_str, 10);+ const topic_name = $element.attr("data-topic-name")!;+ assert(stream_id !== undefined);+ assert(topic_name !== undefined);+ return {stream_id, topic_name};+};+export function initialize(): void {popover_menus.register_popover_menu(".change_visibility_policy", {theme: "popover-menu",@@ -28,14 +43,24 @@ export function initialize(): void {onShow(instance) {popover_menus.popover_instances.change_visibility_policy = instance;popover_menus.on_show_prep(instance);- const $elt = $(instance.reference).closest(".change_visibility_policy").expectOne();- const stream_id_str = $elt.attr("data-stream-id");- $elt.addClass("visibility-policy-popover-visible");- assert(stream_id_str !== undefined);+ const $reference = $(instance.reference);+ const $change_visibility_policy_button = $reference+ .closest(".change_visibility_policy")+ .expectOne();- const stream_id = Number.parseInt(stream_id_str, 10);- const topic_name = $elt.attr("data-topic-name")!;+ // The topic visibility policy popover logic is shared between+ // the recipient bar and other parts of the app. However, the+ // relevant data attributes are located in different elements —+ // specifically, within the message header when triggered from+ // the recipient bar, instead of the button itself. Hence, we+ // need to conditionally extract the data attributes below.+ const $data_element = $reference.hasClass("recipient-bar-control")+ ? $reference.closest(".message_header").expectOne()+ : $change_visibility_policy_button;+ const {stream_id, topic_name} =+ extract_visibility_policy_popover_context($data_element);+ $change_visibility_policy_button.addClass("visibility-policy-popover-visible");instance.setContent(parse_html(render_change_visibility_policy_popover(@@ -49,12 +74,16 @@ export function initialize(): void {},onMount(instance) {const $popper = $(instance.popper);- const $elt = $(instance.reference).closest(".change_visibility_policy").expectOne();- const stream_id_str = $elt.attr("data-stream-id");- assert(stream_id_str !== undefined);+ const $reference = $(instance.reference);+ const $change_visibility_policy_button = $reference+ .closest(".change_visibility_policy")+ .expectOne();- const stream_id = Number.parseInt(stream_id_str, 10);- const topic_name = $elt.attr("data-topic-name")!;+ const $data_element = $reference.hasClass("recipient-bar-control")+ ? $reference.closest(".message_header").expectOne()+ : $change_visibility_policy_button;+ const {stream_id, topic_name} =+ extract_visibility_policy_popover_context($data_element);if (!stream_id) {popover_menus.hide_current_popover_if_visible(instance);diff --git a/web/styles/message_header.css b/web/styles/message_header.cssindex 711985eca23..7c0343f512e 100644--- a/web/styles/message_header.css+++ b/web/styles/message_header.css@@ -257,14 +257,6 @@display: flex;flex-grow: 1;align-items: center;-- .change_visibility_policy {- cursor: pointer;-- i {- display: block;- }- }}.on_hover_topic_read {diff --git a/web/templates/recipient_row.hbs b/web/templates/recipient_row.hbsindex b4c188b0c14..c08d8a4bf4b 100644--- a/web/templates/recipient_row.hbs+++ b/web/templates/recipient_row.hbs@@ -63,22 +63,22 @@<div class="toggle_resolve_topic_spinner recipient_bar_icon" style="display: none"></div>{{/if}}+ {{! visibility policy menu }}{{#if (and is_subscribed (not is_archived))}}- <span class="change_visibility_policy recipient-bar-control hidden-for-spectators" data-stream-id="{{stream_id}}" data-topic-name="{{topic}}">- {{#if (eq visibility_policy all_visibility_policies.FOLLOWED)}}- <i class="zulip-icon zulip-icon-follow recipient_bar_icon" data-tippy-content="{{t 'You follow this topic.'}}"- role="button" tabindex="0" aria-haspopup="true" aria-label="{{t 'You follow this topic.' }}"></i>- {{else if (eq visibility_policy all_visibility_policies.UNMUTED)}}- <i class="zulip-icon zulip-icon-unmute recipient_bar_icon" data-tippy-content="{{t 'You have unmuted this topic.'}}"- role="button" tabindex="0" aria-haspopup="true" aria-label="{{t 'You have unmuted this topic.' }}"></i>- {{else if (eq visibility_policy all_visibility_policies.MUTED)}}- <i class="zulip-icon zulip-icon-mute recipient_bar_icon" data-tippy-content="{{t 'You have muted this topic.'}}"- role="button" tabindex="0" aria-haspopup="true" aria-label="{{t 'You have muted this topic.' }}"></i>- {{else}}- <i class="zulip-icon zulip-icon-inherit recipient_bar_icon"- role="button" tabindex="0" aria-haspopup="true" aria-label="{{t 'Notifications are based on your configuration for this channel.' }}"></i>- {{/if}}- </span>+ {{!-- We define the change_visibility_policy class in a wrapper span+ since the icon button component already has a tippy tooltip attached+ to it and Tippy does not support multiple tooltips on a single element. --}}+ <span class="change_visibility_policy recipient-bar-control hidden-for-spectators" aria-haspopup="true">+ {{#if (eq visibility_policy all_visibility_policies.FOLLOWED)}}+ {{> components/icon_button icon="follow" intent="neutral" custom_classes="recipient-bar-control-icon" data-tippy-content=(t "You follow this topic.") aria-label=(t "You follow this topic.") }}+ {{else if (eq visibility_policy all_visibility_policies.UNMUTED)}}+ {{> components/icon_button icon="unmute" intent="neutral" custom_classes="recipient-bar-control recipient-bar-control-icon" data-tippy-content=(t "You have unmuted this topic.") aria-label=(t "You have unmuted this topic.") }}+ {{else if (eq visibility_policy all_visibility_policies.MUTED)}}+ {{> components/icon_button icon="mute" intent="neutral" custom_classes="recipient-bar-control-icon" data-tippy-content=(t "You have muted this topic.") aria-label=(t "You have muted this topic.") }}+ {{else}}+ {{> components/icon_button icon="inherit" intent="neutral" custom_classes="recipient-bar-control-icon" data-tippy-content=(t "Notifications are based on your configuration for this channel.") aria-label=(t "Notifications are based on your configuration for this channel.") }}+ {{/if}}+ </span>{{/if}}{{! Topic menu }}