Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
narrow_banner: Add search shared history button to empty narrows.
Pratik Chanda1ca93b9d22a5
diff --git a/web/e2e-tests/message-basics.test.ts b/web/e2e-tests/message-basics.test.tsindex 0f18d62ee98..01f92688078 100644--- a/web/e2e-tests/message-basics.test.ts+++ b/web/e2e-tests/message-basics.test.ts@@ -197,7 +197,7 @@ async function search_silent_user(page: Page, str: string, item: string): Promisawait page.waitForSelector(".empty_feed_notice", {visible: true});const expect_message = "You haven't received any messages sent by Email Gateway yet.";assert.strictEqual(- await common.get_text_from_selector(page, ".empty_feed_notice"),+ await common.get_text_from_selector(page, ".empty-feed-notice-title"),expect_message,);await common.get_current_msg_list_id(page, true);diff --git a/web/src/click_handlers.ts b/web/src/click_handlers.tsindex b7047df994e..75041f14452 100644--- a/web/src/click_handlers.ts+++ b/web/src/click_handlers.ts@@ -528,6 +528,15 @@ export function initialize(): void {open_scroll_to_time_popover(this, message_id);});+ $("body").on("click", ".search-shared-history", function (this: HTMLElement, e) {+ e.preventDefault();+ e.stopPropagation();+ const url = $(this).attr("data-url");+ if (url) {+ browser_history.go_to_location(url);+ }+ });+// RESOLVED TOPICS$("body").on("click", ".message_header .on_hover_topic_resolve", (e) => {e.stopPropagation();diff --git a/web/src/message_fetch.ts b/web/src/message_fetch.tsindex fa70a6803e5..6f6c276d0b8 100644--- a/web/src/message_fetch.ts+++ b/web/src/message_fetch.ts@@ -479,7 +479,11 @@ export function load_messages(opts: MessageFetchOptions, attempt = 1): void {!opts.msg_list.is_combined_feed_view &&opts.msg_list.visibly_empty()) {- narrow_banner.show_empty_narrow_message(opts.msg_list.data.filter);+ const invalid_narrow = true;+ narrow_banner.show_empty_narrow_message(+ opts.msg_list.data.filter,+ invalid_narrow,+ );}// TODO: This should probably do something explicit withdiff --git a/web/src/narrow_banner.ts b/web/src/narrow_banner.tsindex e29c15e98b0..8903ecf6224 100644--- a/web/src/narrow_banner.ts+++ b/web/src/narrow_banner.ts@@ -4,7 +4,9 @@ import assert from "minimalistic-assert";import * as compose_validate from "./compose_validate.ts";import type {Filter} from "./filter.ts";+import * as hash_util from "./hash_util.ts";import {$t, $t_html} from "./i18n.ts";+import * as message_feed_top_notices from "./message_feed_top_notices.ts";import * as message_lists from "./message_lists.ts";import type {NarrowBannerData, SearchData} from "./narrow_error.ts";import {narrow_error} from "./narrow_error.ts";@@ -92,7 +94,32 @@ const NO_SEARCH_RESULTS_TITLE_HTML = $t_html(},);-function empty_search_query_banner(current_filter: Filter): NarrowBannerData {+function should_show_search_shared_history_action(+ current_filter: Filter,+ invalid_narrow: boolean,+): boolean {+ return current_filter.may_have_incomplete_message_history() && !invalid_narrow;+}++// When we're offering the search shared history in banner, the title+// links to the relevant help center page; otherwise it's plain text.+function get_no_search_results_title(+ show_search_shared_history: boolean,+): {title: string} | {title_html: string} {+ if (show_search_shared_history) {+ return {+ title_html: NO_SEARCH_RESULTS_TITLE_HTML,+ };+ }++ return {title: NO_SEARCH_RESULTS_TITLE};+}++function empty_search_query_banner(+ current_filter: Filter,+ show_search_shared_history: boolean,+): NarrowBannerData {+ const no_search_results = get_no_search_results_title(show_search_shared_history);const search_query = current_filter.terms_with_operator("search")[0]!.operand;const query_words = search_query.split(" ");@@ -121,11 +148,12 @@ function empty_search_query_banner(current_filter: Filter): NarrowBannerData {// when there are excluded stop words.if (search_string_result.has_stop_word) {return {- title: NO_SEARCH_RESULTS_TITLE,+ ...no_search_results,+ show_action: show_search_shared_history,search_data: search_string_result,};}- return {title: NO_SEARCH_RESULTS_TITLE};+ return {...no_search_results, show_action: show_search_shared_history};}// Returns a banner describing why direct messages to these users are@@ -150,7 +178,20 @@ function dm_permission_error_banner(user_ids_string: string): NarrowBannerData |};}-export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerData {+export function pick_empty_narrow_banner(+ current_filter: Filter,+ invalid_narrow = false,+): NarrowBannerData {+ // Show the "search shared history" help link and action button only for+ // banners where the user's message history may be incomplete in a valid+ // narrow. Some compatible banners do not show them because the user lacks+ // permission to search shared history or the corresponding view is not+ // available.+ const show_search_shared_history = should_show_search_shared_history_action(+ current_filter,+ invalid_narrow,+ );+ const no_search_results = get_no_search_results_title(show_search_shared_history);const default_banner = {title: $t({defaultMessage: "There are no messages here."}),// Spectators cannot start a conversation.@@ -230,7 +271,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa// For empty search queries, we display excluded stop wordsif (current_filter.terms_with_operator("search").length > 0) {- return empty_search_query_banner(current_filter);+ return empty_search_query_banner(current_filter, show_search_shared_history);}if (@@ -284,7 +325,8 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa// For other multi-operator narrows, we just use the default bannerreturn {- title: NO_SEARCH_RESULTS_TITLE,+ ...no_search_results,+ show_action: show_search_shared_history,};}@@ -332,6 +374,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa)}</a>`,},),+ show_action: show_search_shared_history,};case "followed":return {@@ -347,6 +390,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDacase "alerted":return {title_html: NO_SEARCH_RESULTS_TITLE_HTML,+ show_action: show_search_shared_history,};}// fallthrough to default case if no match is found@@ -400,7 +444,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa}case "search": {// You are narrowed to empty search results.- return empty_search_query_banner(current_filter);+ return empty_search_query_banner(current_filter, show_search_shared_history);}case "dm": {if (!people.is_valid_bulk_user_ids_for_compose(first_term.operand, true)) {@@ -496,6 +540,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa},{person: sender.full_name},),+ show_action: show_search_shared_history,};}return {@@ -576,22 +621,40 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDaperson: mentioned_user.full_name,},),+ show_action: show_search_shared_history,};}case "has": {return {title_html: NO_SEARCH_RESULTS_TITLE_HTML,+ show_action: show_search_shared_history,};}}return default_banner;}-export function show_empty_narrow_message(current_filter: Filter): void {+export function show_empty_narrow_message(current_filter: Filter, invalid_narrow = false): void {$(".empty_feed_notice_main").empty();- const rendered_narrow_banner = narrow_error(pick_empty_narrow_banner(current_filter));+ const rendered_narrow_banner = narrow_error(+ pick_empty_narrow_banner(current_filter, invalid_narrow),+ );$(".empty_feed_notice_main").html(rendered_narrow_banner);++ // Removing messages from the current narrow can leave a stale+ // top-of-feed notice visible, so hide all of them before showing+ // the empty-narrow banner.+ message_feed_top_notices.hide_top_of_narrow_notices();++ if (current_filter.may_have_incomplete_message_history()) {+ $(".empty_feed_notice .empty-feed-notice-action").show();++ const terms = current_filter.terms();+ const update_hash = hash_util.search_public_streams_notice_url(terms);++ $(".empty_feed_notice .search-shared-history").attr("data-url", update_hash);+ }}export function hide_empty_narrow_message(): void {diff --git a/web/src/narrow_error.ts b/web/src/narrow_error.tsindex eba06a67aac..02a38e48c48 100644--- a/web/src/narrow_error.ts+++ b/web/src/narrow_error.ts@@ -12,6 +12,7 @@ export type SearchData = {export type NarrowBannerData = {html?: string;+ show_action?: boolean;search_data?: SearchData;} & ({title: string} | {title_html: string});diff --git a/web/styles/zulip.css b/web/styles/zulip.cssindex a58168e9802..c9a50cc84cb 100644--- a/web/styles/zulip.css+++ b/web/styles/zulip.css@@ -1422,6 +1422,16 @@ div.topic_edit_spinner .loading_indicator_spinner {}}+.empty-feed-notice-action {+ display: none;+ font-size: 1.1em;++ .search-shared-history {+ display: inline-block;+ margin-top: 10px;+ }+}+.message-fade,.user_sidebar_entry.user-fade {opacity: 0.4;diff --git a/web/templates/empty_feed_notice.hbs b/web/templates/empty_feed_notice.hbsindex db9e8c1273b..3e2f7504501 100644--- a/web/templates/empty_feed_notice.hbs+++ b/web/templates/empty_feed_notice.hbs@@ -18,4 +18,13 @@{{{ notice_html }}}</div>{{/if}}+ {{#if show_action}}+ <div class="empty-feed-notice-action">+ <button+ class="search-shared-history hidden-for-spectators action-button action-button-subtle-neutral"+ type="button">+ {{t 'Search all public channels'}}+ </button>+ </div>+ {{/if}}</div>diff --git a/web/tests/message_view.test.cjs b/web/tests/message_view.test.cjsindex 3382a726519..35440a627dd 100644--- a/web/tests/message_view.test.cjs+++ b/web/tests/message_view.test.cjs@@ -61,12 +61,13 @@ mock_esm("../src/spectators", {login_to_access() {},});-function empty_narrow_html(title, title_html, notice_html, search_data) {+function empty_narrow_html(title, title_html, notice_html, search_data, show_action) {const opts = {title,title_html,notice_html,search_data,+ show_action,};return require("../templates/empty_feed_notice.hbs")(opts);}@@ -151,6 +152,42 @@ run_test("empty_narrow_html", ({mock_template}) => {`,);+ // Title, html and action+ actual_html = empty_narrow_html(+ "This is a title",+ undefined,+ "<h1> This is the html </h1>",+ undefined,+ true,+ );+ assert.equal(+ actual_html,+ `<div class="empty_feed_notice">+ <h4 class="empty-feed-notice-title"> This is a title </h4>+ <div class="empty-feed-notice-description">+ <h1> This is the html </h1>+ </div>+ <div class="empty-feed-notice-action">+ <button+ class="search-shared-history hidden-for-spectators action-button action-button-subtle-neutral"+ type="button">+ translated: Search all public channels+ </button>+ </div>+</div>+`,+ );++ // title_html+ actual_html = empty_narrow_html("Plain text title", "<h1> This is the title html </h1>");+ assert.equal(+ actual_html,+ `<div class="empty_feed_notice">+ <h4 class="empty-feed-notice-title"> <h1> This is the title html </h1> </h4>+</div>+`,+ );+// Title and search dataconst search_data_with_stop_word = {has_stop_word: true,@@ -406,6 +443,9 @@ run_test("show_empty_narrow_message", ({mock_template, override, override_rewireempty_narrow_html(undefined,`translated: No topics in <a href="/help/search-for-messages#search-shared-history" target="_blank" rel="noopener noreferrer">your history</a> are marked as resolved.`,+ undefined,+ undefined,+ true,),);@@ -605,7 +645,13 @@ run_test("show_empty_narrow_message", ({mock_template, override, override_rewirenarrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),- empty_narrow_html("translated: You haven't received any messages sent by Raymond yet."),+ empty_narrow_html(+ "translated: You haven't received any messages sent by Raymond yet.",+ undefined,+ undefined,+ undefined,+ true,+ ),);current_filter = set_filter([["sender", 9999]]);@@ -634,6 +680,9 @@ run_test("show_empty_narrow_message", ({mock_template, override, override_rewireempty_narrow_html("translated: No messages in your message history mention Alice Smith yet.",'translated: No messages in <a href="/help/search-for-messages#search-shared-history" target="_blank" rel="noopener noreferrer">your message history</a> mention Alice Smith yet.',+ undefined,+ undefined,+ true,),);@@ -712,6 +761,9 @@ run_test("show_empty_narrow_message", ({mock_template, override, override_rewireempty_narrow_html(undefined,`translated: No search results from <a href="/help/search-for-messages#search-shared-history" target="_blank" rel="noopener noreferrer">your message history</a>.`,+ undefined,+ undefined,+ true,),);current_filter = set_filter([@@ -766,7 +818,13 @@ run_test("show_empty_narrow_message_with_search", ({mock_template, override}) =>narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),- empty_narrow_html("translated: No search results."),+ empty_narrow_html(+ undefined,+ `translated: No search results from <a href="/help/search-for-messages#search-shared-history" target="_blank" rel="noopener noreferrer">your message history</a>.`,+ undefined,+ undefined,+ true,+ ),);});@@ -793,10 +851,11 @@ run_test("show_search_stopwords", ({mock_template, override}) => {assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html(- "translated: No search results.",undefined,+ `translated: No search results from <a href="/help/search-for-messages#search-shared-history" target="_blank" rel="noopener noreferrer">your message history</a>.`,undefined,expected_search_data,+ true,),);