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.

compose_banner: Add show_warning_message helper for warning banners.

Pritesh Shetty1ee743471740
diff --git a/web/src/compose_banner.ts b/web/src/compose_banner.ts
index f34cd70346e..c1d4af54e59 100644
--- a/web/src/compose_banner.ts
+++ b/web/src/compose_banner.ts
@@ -216,6 +216,32 @@ export function show_error_message(
}
}
+export function show_warning_message(
+ message: string,
+ classname: string,
+ $container: JQuery,
+ {
+ button_text = null,
+ stream_id = null,
+ topic_name = null,
+ }: {button_text?: string | null; stream_id?: number | null; topic_name?: string | null} = {},
+): boolean {
+ // The warning counterpart of show_error_message: same classname-dedupe,
+ // and like that function it intentionally does not support HTML messages.
+ // Returns whether the banner was appended.
+ $container.find(`.${CSS.escape(classname)}`).remove();
+
+ const new_row_html = render_compose_banner({
+ banner_type: WARNING,
+ stream_id,
+ topic_name,
+ banner_text: message,
+ button_text,
+ classname,
+ });
+ return append_compose_banner_to_banner_list($(new_row_html), $container);
+}
+
export function cannot_send_direct_message_error(error_message: string): void {
// If a banner with this classname already exists, avoid removing
// and re-creating it.
diff --git a/web/src/compose_validate.ts b/web/src/compose_validate.ts
index 8524ee7a03e..c72b7c8d274 100644
--- a/web/src/compose_validate.ts
+++ b/web/src/compose_validate.ts
@@ -2,7 +2,6 @@ import {$} from "jquery";
import _ from "lodash";
import type {ReferenceElement} from "tippy.js";
-import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
import render_compose_mention_group_warning from "../templates/compose_banner/compose_mention_group_warning.hbs";
import render_guest_in_dm_recipient_warning from "../templates/compose_banner/guest_in_dm_recipient_warning.hbs";
import render_not_subscribed_warning from "../templates/compose_banner/not_subscribed_warning.hbs";
@@ -516,22 +515,14 @@ export function warn_if_topic_resolved(topic_changed: boolean): void {
? $t({defaultMessage: "Unresolve topic"})
: null;
- const context = {
- banner_type: compose_banner.WARNING,
- stream_id: sub.stream_id,
- topic_name,
- banner_text: $t({
+ const appended = compose_banner.show_warning_message(
+ $t({
defaultMessage:
"You are sending a message to a resolved topic. You can send as-is or unresolve the topic first.",
}),
- button_text,
- classname: compose_banner.CLASSNAMES.topic_resolved,
- };
-
- const new_row_html = render_compose_banner(context);
- const appended = compose_banner.append_compose_banner_to_banner_list(
- $(new_row_html),
+ compose_banner.CLASSNAMES.topic_resolved,
$("#compose_banners"),
+ {button_text, stream_id: sub.stream_id, topic_name},
);
if (appended) {
compose_state.set_recipient_viewed_topic_resolved_banner(true);
@@ -625,18 +616,15 @@ export function inform_if_topic_is_moved(
export function warn_if_in_search_view(): void {
const filter = narrow_state.filter();
if (filter && !filter.contains_no_partial_conversations()) {
- const context = {
- banner_type: compose_banner.WARNING,
- banner_text: $t({
+ compose_banner.show_warning_message(
+ $t({
defaultMessage:
"This conversation may have additional messages not shown in this view.",
}),
- button_text: $t({defaultMessage: "Go to conversation"}),
- classname: compose_banner.CLASSNAMES.search_view,
- };
-
- const new_row_html = render_compose_banner(context);
- compose_banner.append_compose_banner_to_banner_list($(new_row_html), $("#compose_banners"));
+ compose_banner.CLASSNAMES.search_view,
+ $("#compose_banners"),
+ {button_text: $t({defaultMessage: "Go to conversation"})},
+ );
}
}
diff --git a/web/src/scheduled_messages_ui.ts b/web/src/scheduled_messages_ui.ts
index 21516753564..9d06cd11488 100644
--- a/web/src/scheduled_messages_ui.ts
+++ b/web/src/scheduled_messages_ui.ts
@@ -1,8 +1,6 @@
import {$} from "jquery";
import assert from "minimalistic-assert";
-import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
-
import * as compose_actions from "./compose_actions.ts";
import * as compose_banner from "./compose_banner.ts";
import {$t} from "./i18n.ts";
@@ -92,17 +90,13 @@ function show_message_unscheduled_banner(scheduled_delivery_timestamp: number):
new Date(scheduled_delivery_timestamp * 1000),
"time",
);
- const unscheduled_banner_html = render_compose_banner({
- banner_type: compose_banner.WARNING,
- banner_text: $t({
+ compose_banner.show_warning_message(
+ $t({
defaultMessage: "This message is no longer scheduled to be sent.",
}),
- button_text: $t({defaultMessage: "Schedule for {deliver_at}"}, {deliver_at}),
- classname: compose_banner.CLASSNAMES.unscheduled_message,
- });
- compose_banner.append_compose_banner_to_banner_list(
- $(unscheduled_banner_html),
+ compose_banner.CLASSNAMES.unscheduled_message,
$("#compose_banners"),
+ {button_text: $t({defaultMessage: "Schedule for {deliver_at}"}, {deliver_at})},
);
}
diff --git a/web/tests/lib/compose_banner.cjs b/web/tests/lib/compose_banner.cjs
index cc85db09954..0ace5329a72 100644
--- a/web/tests/lib/compose_banner.cjs
+++ b/web/tests/lib/compose_banner.cjs
@@ -37,4 +37,7 @@ exports.mock_banners = () => {
$cb.set_find_results(".missing_private_message_recipient", $stub);
$cb.set_find_results(".subscription_error", $stub);
$cb.set_find_results(".generic_compose_error", $stub);
+ $cb.set_find_results(".topic_resolved", $stub);
+ $cb.set_find_results(".search_view", $stub);
+ $cb.set_find_results(".unscheduled_message", $stub);
};