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.

popovers: Migrate the topic_menu popover to Tippy.

palashb0128f2124feb03
diff --git a/web/src/popover_menus.js b/web/src/popover_menus.js
index a2b4f8e69d8..67c82892933 100644
--- a/web/src/popover_menus.js
+++ b/web/src/popover_menus.js
@@ -10,23 +10,27 @@ import render_actions_popover_content from "../templates/actions_popover_content
import render_all_messages_sidebar_actions from "../templates/all_messages_sidebar_actions.hbs";
import render_compose_control_buttons_popover from "../templates/compose_control_buttons_popover.hbs";
import render_compose_select_enter_behaviour_popover from "../templates/compose_select_enter_behaviour_popover.hbs";
+import render_delete_topic_modal from "../templates/confirm_dialog/confirm_delete_topic.hbs";
import render_drafts_sidebar_actions from "../templates/drafts_sidebar_action.hbs";
import render_left_sidebar_stream_setting_popover from "../templates/left_sidebar_stream_setting_popover.hbs";
import render_mobile_message_buttons_popover_content from "../templates/mobile_message_buttons_popover_content.hbs";
import render_starred_messages_sidebar_actions from "../templates/starred_messages_sidebar_actions.hbs";
+import render_topic_sidebar_actions from "../templates/topic_sidebar_actions.hbs";
import * as blueslip from "./blueslip";
import * as channel from "./channel";
import * as common from "./common";
import * as compose_actions from "./compose_actions";
import * as condense from "./condense";
+import * as confirm_dialog from "./confirm_dialog";
import * as drafts from "./drafts";
import * as emoji_picker from "./emoji_picker";
import * as giphy from "./giphy";
-import {$t} from "./i18n";
+import {$t, $t_html} from "./i18n";
import * as message_edit from "./message_edit";
import * as message_edit_history from "./message_edit_history";
import * as message_lists from "./message_lists";
+import * as muted_topics_ui from "./muted_topics_ui";
import * as narrow_state from "./narrow_state";
import * as popover_menus_data from "./popover_menus_data";
import * as popovers from "./popovers";
@@ -51,6 +55,7 @@ const popover_instances = {
stream_settings: null,
compose_mobile_button: null,
compose_enter_sends: null,
+ topics_menu: null,
};
export function sidebar_menu_instance_handle_keyboard(instance, key) {
@@ -272,6 +277,97 @@ export function initialize() {
},
});
+ tippy_no_propagation("#stream_filters .topic-sidebar-menu-icon", {
+ ...left_sidebar_tippy_options,
+ onShow(instance) {
+ popover_instances.topics_menu = instance;
+ on_show_prep(instance);
+ const elt = $(instance.reference).closest(".topic-sidebar-menu-icon").expectOne()[0];
+ const $stream_li = $(elt).closest(".narrow-filter").expectOne();
+ const topic_name = $(elt).closest("li").expectOne().attr("data-topic-name");
+ const url = $(elt).closest("li").find(".topic-name").expectOne().prop("href");
+ const stream_id = stream_popover.elem_to_stream_id($stream_li);
+
+ instance.context = popover_menus_data.get_topic_popover_content_context({
+ stream_id,
+ topic_name,
+ url,
+ });
+ instance.setContent(parse_html(render_topic_sidebar_actions(instance.context)));
+ },
+ onMount(instance) {
+ const $popper = $(instance.popper);
+ const {stream_id, topic_name} = instance.context;
+
+ if (!stream_id) {
+ instance.hide();
+ return;
+ }
+
+ $popper.one("click", ".sidebar-popover-mute-topic", () => {
+ muted_topics_ui.mute_topic(stream_id, topic_name);
+ instance.hide();
+ });
+
+ $popper.one("click", ".sidebar-popover-unmute-topic", () => {
+ muted_topics_ui.unmute_topic(stream_id, topic_name);
+ instance.hide();
+ });
+
+ $popper.one("click", ".sidebar-popover-unstar-all-in-topic", () => {
+ starred_messages_ui.confirm_unstar_all_messages_in_topic(
+ Number.parseInt(stream_id, 10),
+ topic_name,
+ );
+ instance.hide();
+ });
+
+ $popper.one("click", ".sidebar-popover-mark-topic-read", () => {
+ unread_ops.mark_topic_as_read(stream_id, topic_name);
+ instance.hide();
+ });
+
+ $popper.one("click", ".sidebar-popover-delete-topic-messages", () => {
+ const html_body = render_delete_topic_modal({topic_name});
+
+ confirm_dialog.launch({
+ html_heading: $t_html({defaultMessage: "Delete topic"}),
+ help_link: "/help/delete-a-topic",
+ html_body,
+ on_click() {
+ message_edit.delete_topic(stream_id, topic_name);
+ },
+ });
+
+ instance.hide();
+ });
+
+ $popper.one("click", ".sidebar-popover-toggle-resolved", () => {
+ message_edit.with_first_message_id(stream_id, topic_name, (message_id) => {
+ message_edit.toggle_resolve_topic(message_id, topic_name);
+ });
+
+ instance.hide();
+ });
+
+ $popper.one("click", ".sidebar-popover-move-topic-messages", () => {
+ stream_popover.build_move_topic_to_stream_popover(stream_id, topic_name);
+ instance.hide();
+ });
+
+ new ClipboardJS($popper.find(".sidebar-popover-copy-link-to-topic")[0]).on(
+ "success",
+ () => {
+ instance.hide();
+ },
+ );
+ },
+ onHidden(instance) {
+ instance.destroy();
+ popover_instances.topics_menu = undefined;
+ },
+ });
+
tippy_no_propagation(".open_enter_sends_dialog", {
placement: "top",
onShow(instance) {
diff --git a/web/src/popover_menus_data.js b/web/src/popover_menus_data.js
index e54d910807d..62b1c97a40f 100644
--- a/web/src/popover_menus_data.js
+++ b/web/src/popover_menus_data.js
@@ -1,6 +1,8 @@
/* This module provides relevant data to render popovers that require multiple args.
This helps keep the popovers code small and keep it focused on rendering side of things. */
+import * as resolved_topic from "../shared/src/resolved_topic";
+
import * as feature_flags from "./feature_flags";
import * as hash_util from "./hash_util";
import {$t} from "./i18n";
@@ -9,7 +11,11 @@ import * as message_lists from "./message_lists";
import * as muted_users from "./muted_users";
import * as narrow_state from "./narrow_state";
import {page_params} from "./page_params";
+import * as settings_data from "./settings_data";
+import * as starred_messages from "./starred_messages";
import * as stream_data from "./stream_data";
+import * as sub_store from "./sub_store";
+import * as user_topics from "./user_topics";
export function get_actions_popover_content_context(message_id) {
const message = message_lists.current.get(message_id);
@@ -118,3 +124,22 @@ export function get_actions_popover_content_context(message_id) {
should_display_quote_and_reply,
};
}
+
+export function get_topic_popover_content_context({stream_id, topic_name, url}) {
+ const sub = sub_store.get(stream_id);
+ const topic_muted = user_topics.is_topic_muted(sub.stream_id, topic_name);
+ const has_starred_messages = starred_messages.get_count_in_topic(sub.stream_id, topic_name) > 0;
+ const can_move_topic = settings_data.user_can_move_messages_between_streams();
+ return {
+ stream_name: sub.name,
+ stream_id: sub.stream_id,
+ topic_name,
+ topic_muted,
+ can_move_topic,
+ is_realm_admin: page_params.is_admin,
+ topic_is_resolved: resolved_topic.is_resolved(topic_name),
+ color: sub.color,
+ has_starred_messages,
+ url,
+ };
+}
diff --git a/web/src/stream_popover.js b/web/src/stream_popover.js
index 3cee336ccc6..4c1dd81cb51 100644
--- a/web/src/stream_popover.js
+++ b/web/src/stream_popover.js
@@ -1,30 +1,21 @@
-import ClipboardJS from "clipboard";
import $ from "jquery";
-import * as resolved_topic from "../shared/src/resolved_topic";
-import render_delete_topic_modal from "../templates/confirm_dialog/confirm_delete_topic.hbs";
import render_move_topic_to_stream from "../templates/move_topic_to_stream.hbs";
import render_stream_sidebar_actions from "../templates/stream_sidebar_actions.hbs";
-import render_topic_sidebar_actions from "../templates/topic_sidebar_actions.hbs";
import * as blueslip from "./blueslip";
import * as browser_history from "./browser_history";
import * as compose_actions from "./compose_actions";
import * as composebox_typeahead from "./composebox_typeahead";
-import * as confirm_dialog from "./confirm_dialog";
import * as dialog_widget from "./dialog_widget";
import {DropdownListWidget} from "./dropdown_list_widget";
import * as hash_util from "./hash_util";
import {$t, $t_html} from "./i18n";
import * as keydown_util from "./keydown_util";
import * as message_edit from "./message_edit";
-import * as muted_topics_ui from "./muted_topics_ui";
-import {page_params} from "./page_params";
import * as popovers from "./popovers";
import * as resize from "./resize";
import * as settings_data from "./settings_data";
-import * as starred_messages from "./starred_messages";
-import * as starred_messages_ui from "./starred_messages_ui";
import * as stream_bar from "./stream_bar";
import * as stream_color from "./stream_color";
import * as stream_data from "./stream_data";
@@ -32,8 +23,6 @@ import * as stream_settings_ui from "./stream_settings_ui";
import * as sub_store from "./sub_store";
import * as ui_report from "./ui_report";
import * as unread_ops from "./unread_ops";
-import * as user_topics from "./user_topics";
-
// We handle stream popovers and topic popovers in this
// module. Both are popped up from the left sidebar.
let current_stream_sidebar_elem;
@@ -85,10 +74,6 @@ export function elem_to_stream_id($elem) {
return stream_id;
}
-function topic_popover_stream_id(e) {
- return elem_to_stream_id($(e.currentTarget));
-}
-
export function stream_popped() {
return current_stream_sidebar_elem !== undefined;
}
@@ -163,25 +148,6 @@ function update_spectrum($popover, update_func) {
$popover_root.css("top", top + "px");
}
-// Builds the `Copy link to topic` topic action.
-function build_topic_link_clipboard(url) {
- if (!url) {
- return;
- }
-
- const copy_event = new ClipboardJS(".sidebar-popover-copy-link-to-topic", {
- text() {
- return url;
- },
- });
-
- // Hide the topic popover once the url is successfully
- // copied to clipboard.
- copy_event.on("success", () => {
- hide_topic_popover();
- });
-}
-
function build_stream_popover(opts) {
const elt = opts.elt;
const stream_id = opts.stream_id;
@@ -217,56 +183,6 @@ function build_stream_popover(opts) {
show_left_sidebar_menu_icon(elt);
}
-function build_topic_popover(opts) {
- const elt = opts.elt;
- const stream_id = opts.stream_id;
- const topic_name = opts.topic_name;
-
- if (topic_popped() && current_topic_sidebar_elem === elt) {
- // If the popover is already shown, clicking again should toggle it.
- hide_topic_popover();
- return;
- }
-
- const sub = sub_store.get(stream_id);
- if (!sub) {
- blueslip.error("cannot build topic popover for stream: " + stream_id);
- return;
- }
-
- popovers.hide_all_except_sidebars();
-
- const topic_muted = user_topics.is_topic_muted(sub.stream_id, topic_name);
- const has_starred_messages = starred_messages.get_count_in_topic(sub.stream_id, topic_name) > 0;
- // Arguably, we could offer the "Move topic" option even if users
- // can only edit the name within a stream.
- const can_move_topic = settings_data.user_can_move_messages_between_streams();
-
- const content = render_topic_sidebar_actions({
- stream_name: sub.name,
- stream_id: sub.stream_id,
- topic_name,
- topic_muted,
- can_move_topic,
- is_realm_admin: page_params.is_admin,
- topic_is_resolved: resolved_topic.is_resolved(topic_name),
- color: sub.color,
- has_starred_messages,
- });
-
- $(elt).popover({
- content,
- html: true,
- trigger: "manual",
- fixed: true,
- });
-
- $(elt).popover("show");
-
- current_topic_sidebar_elem = elt;
- show_left_sidebar_menu_icon(elt);
-}
-
export function build_move_topic_to_stream_popover(current_stream_id, topic_name, message) {
const current_stream_name = stream_data.maybe_get_stream_name(current_stream_id);
const args = {
@@ -469,24 +385,6 @@ export function register_click_handlers() {
});
});
- $("#stream_filters").on("click", ".topic-sidebar-menu-icon", (e) => {
- e.stopPropagation();
-
- const elt = $(e.target).closest(".topic-sidebar-menu-icon").expectOne()[0];
- const $stream_li = $(elt).closest(".narrow-filter").expectOne();
- const stream_id = elem_to_stream_id($stream_li);
- const topic_name = $(elt).closest("li").expectOne().attr("data-topic-name");
- const url = $(elt).closest("li").find(".topic-name").expectOne().prop("href");
-
- build_topic_popover({
- elt,
- stream_id,
- topic_name,
- });
-
- build_topic_link_clipboard(url);
- });
-
$("body").on("click keypress", ".move-topic-dropdown .list_item", (e) => {
// We want the dropdown to collapse once any of the list item is pressed
// and thus don't want to kill the natural bubbling of event.
@@ -503,7 +401,6 @@ export function register_click_handlers() {
});
register_stream_handlers();
- register_topic_handlers();
}
export function register_stream_handlers() {
@@ -531,20 +428,7 @@ export function register_stream_handlers() {
unread_ops.mark_stream_as_read(sub.stream_id);
e.stopPropagation();
});
-
- // Unstar all messages in topic
- $("body").on("click", ".sidebar-popover-unstar-all-in-topic", (e) => {
- e.preventDefault();
- e.stopPropagation();
- const topic_name = $(".sidebar-popover-unstar-all-in-topic").attr("data-topic-name");
- const stream_id = $(".sidebar-popover-unstar-all-in-topic").attr("data-stream-id");
- hide_topic_popover();
- starred_messages_ui.confirm_unstar_all_messages_in_topic(
- Number.parseInt(stream_id, 10),
- topic_name,
- );
- });
-
+
// Mute/unmute
$("body").on("click", ".toggle_stream_muted", (e) => {
const sub = stream_popover_sub(e);
@@ -602,95 +486,3 @@ export function register_stream_handlers() {
}
});
}
-
-export function register_topic_handlers() {
- // Mute the topic
- $("body").on("click", ".sidebar-popover-mute-topic", (e) => {
- const stream_id = topic_popover_stream_id(e);
- if (!stream_id) {
- return;
- }
-
- const topic = $(e.currentTarget).attr("data-topic-name");
- muted_topics_ui.mute_topic(stream_id, topic);
- e.stopPropagation();
- e.preventDefault();
- });
-
- // Unmute the topic
- $("body").on("click", ".sidebar-popover-unmute-topic", (e) => {
- const stream_id = topic_popover_stream_id(e);
- if (!stream_id) {
- return;
- }
-
- const topic = $(e.currentTarget).attr("data-topic-name");
- muted_topics_ui.unmute_topic(stream_id, topic);
- e.stopPropagation();
- e.preventDefault();
- });
-
- // Mark all messages as read
- $("body").on("click", ".sidebar-popover-mark-topic-read", (e) => {
- const stream_id = topic_popover_stream_id(e);
- if (!stream_id) {
- return;
- }
-
- const topic = $(e.currentTarget).attr("data-topic-name");
- hide_topic_popover();
- unread_ops.mark_topic_as_read(stream_id, topic);
- e.stopPropagation();
- });
-
- // Deleting all message in a topic
- $("body").on("click", ".sidebar-popover-delete-topic-messages", (e) => {
- const stream_id = topic_popover_stream_id(e);
- if (!stream_id) {
- return;
- }
-
- const topic = $(e.currentTarget).attr("data-topic-name");
- const args = {
- topic_name: topic,
- };
-
- hide_topic_popover();
-
- const html_body = render_delete_topic_modal(args);
-
- confirm_dialog.launch({
- html_heading: $t_html({defaultMessage: "Delete topic"}),
- help_link: "/help/delete-a-topic",
- html_body,
- on_click() {
- message_edit.delete_topic(stream_id, topic);
- },
- });
-
- e.stopPropagation();
- });
-
- $("body").on("click", ".sidebar-popover-toggle-resolved", (e) => {
- const $topic_row = $(e.currentTarget);
- const stream_id = Number.parseInt($topic_row.attr("data-stream-id"), 10);
- const topic_name = $topic_row.attr("data-topic-name");
- message_edit.with_first_message_id(stream_id, topic_name, (message_id) => {
- message_edit.toggle_resolve_topic(message_id, topic_name);
- });
-
- hide_topic_popover();
- e.stopPropagation();
- e.preventDefault();
- });
-
- $("body").on("click", ".sidebar-popover-move-topic-messages", (e) => {
- const $topic_row = $(e.currentTarget);
- const stream_id = Number.parseInt($topic_row.attr("data-stream-id"), 10);
- const topic_name = $topic_row.attr("data-topic-name");
- hide_topic_popover();
- build_move_topic_to_stream_popover(stream_id, topic_name);
- e.stopPropagation();
- e.preventDefault();
- });
-}
diff --git a/web/templates/topic_sidebar_actions.hbs b/web/templates/topic_sidebar_actions.hbs
index 96c4c591d73..76696d4713f 100644
--- a/web/templates/topic_sidebar_actions.hbs
+++ b/web/templates/topic_sidebar_actions.hbs
@@ -41,7 +41,7 @@
</li>
<li>
- <a tabindex="0" class="sidebar-popover-copy-link-to-topic" data-stream-id="{{ stream_id }}" data-topic-name="{{ topic_name }}">
+ <a tabindex="0" class="sidebar-popover-copy-link-to-topic" data-stream-id="{{ stream_id }}" data-topic-name="{{ topic_name }}" data-clipboard-text="{{ url }}">
<i class="fa fa-link" aria-hidden="true"></i>
{{t "Copy link to topic"}}
</a>