mirror of https://github.com/zulip/zulip.git
narrow: Update browser title when in a narrow search view.
Sets a default value of "Search results" for complicated narrow search views and updates logic to use `filter.get_title` as a helper to generate better titles for some common search views. Does not update the existing behavior for narrow searches that have "pm-with" or "group-pm-with" operators. Note as of this change, the default search title and titles generated from `filter.get_title` will be translated into the user's preferred language. Fixes #22952.
This commit is contained in:
parent
857324a164
commit
8089910dcb
|
@ -36,7 +36,7 @@ async function create_stream_message_draft(page: Page): Promise<void> {
|
|||
await page.keyboard.press("KeyC");
|
||||
await page.waitForSelector("#stream-message", {visible: true});
|
||||
await common.fill_form(page, "form#send_message_form", {
|
||||
stream_message_recipient_stream: "all",
|
||||
stream_message_recipient_stream: "Denmark",
|
||||
stream_message_recipient_topic: "tests",
|
||||
content: "Test stream message.",
|
||||
});
|
||||
|
@ -78,7 +78,7 @@ async function test_previously_created_drafts_rendered(page: Page): Promise<void
|
|||
page,
|
||||
".draft-row .message_header_stream .stream_label",
|
||||
),
|
||||
"all",
|
||||
"Denmark",
|
||||
);
|
||||
assert.strictEqual(
|
||||
await common.get_text_from_selector(
|
||||
|
@ -117,20 +117,20 @@ async function test_restore_message_draft(page: Page): Promise<void> {
|
|||
await page.waitForSelector("#stream-message", {visible: true});
|
||||
await page.waitForSelector("#preview_message_area", {hidden: true});
|
||||
await common.check_form_contents(page, "form#send_message_form", {
|
||||
stream_message_recipient_stream: "all",
|
||||
stream_message_recipient_stream: "Denmark",
|
||||
stream_message_recipient_topic: "tests",
|
||||
content: "Test stream message.",
|
||||
});
|
||||
assert.strictEqual(
|
||||
await common.get_text_from_selector(page, "title"),
|
||||
"#all > tests - Zulip Dev - Zulip",
|
||||
"#Denmark > tests - Zulip Dev - Zulip",
|
||||
"Didn't narrow to the right topic.",
|
||||
);
|
||||
}
|
||||
|
||||
async function edit_stream_message_draft(page: Page): Promise<void> {
|
||||
await common.fill_form(page, "form#send_message_form", {
|
||||
stream_message_recipient_stream: "all",
|
||||
stream_message_recipient_stream: "Denmark",
|
||||
stream_message_recipient_topic: "tests",
|
||||
content: "Updated stream message",
|
||||
});
|
||||
|
@ -147,7 +147,7 @@ async function test_edited_draft_message(page: Page): Promise<void> {
|
|||
page,
|
||||
".draft-row .message_header_stream .stream_label",
|
||||
),
|
||||
"all",
|
||||
"Denmark",
|
||||
);
|
||||
assert.strictEqual(
|
||||
await common.get_text_from_selector(
|
||||
|
@ -159,7 +159,7 @@ async function test_edited_draft_message(page: Page): Promise<void> {
|
|||
assert.strictEqual(
|
||||
await common.get_text_from_selector(
|
||||
page,
|
||||
".draft-row:nth-last-child(2) .rendered_markdown.restore-draft",
|
||||
".draft-row .message_row:not(.private-message) .rendered_markdown.restore-draft",
|
||||
),
|
||||
"Updated stream message",
|
||||
);
|
||||
|
|
|
@ -232,7 +232,7 @@ async function search_tests(page: Page): Promise<void> {
|
|||
"topic:test",
|
||||
"",
|
||||
expect_test_topic,
|
||||
"All messages - Zulip Dev - Zulip",
|
||||
"Search results - Zulip Dev - Zulip",
|
||||
);
|
||||
|
||||
await search_silent_user(page, "sender:emailgateway@zulip.com", "");
|
||||
|
|
|
@ -126,32 +126,37 @@ export function set_narrow_title(title) {
|
|||
}
|
||||
|
||||
function update_narrow_title(filter) {
|
||||
// Take the most detailed part of the narrow to use as the title.
|
||||
// If the operator is something other than "stream", "topic", or
|
||||
// "is", we shouldn't update the narrow title
|
||||
if (filter.has_operator("stream")) {
|
||||
const stream_name = filter.operands("stream")[0];
|
||||
if (filter.has_operator("topic")) {
|
||||
const topic_name = filter.operands("topic")[0];
|
||||
set_narrow_title("#" + stream_name + " > " + topic_name);
|
||||
} else {
|
||||
set_narrow_title("#" + stream_name);
|
||||
}
|
||||
} else if (filter.has_operator("is")) {
|
||||
const title = filter.operands("is")[0];
|
||||
set_narrow_title(title.charAt(0).toUpperCase() + title.slice(1) + " messages");
|
||||
} else if (filter.has_operator("pm-with")) {
|
||||
const emails = filter.operands("pm-with")[0];
|
||||
const user_ids = people.emails_strings_to_user_ids_string(emails);
|
||||
if (user_ids !== undefined) {
|
||||
const names = people.get_recipients(user_ids);
|
||||
set_narrow_title(names);
|
||||
} else {
|
||||
if (emails.includes(",")) {
|
||||
set_narrow_title("Invalid users");
|
||||
const filter_title = filter.get_title();
|
||||
const search_default = $t({defaultMessage: "Search results"});
|
||||
|
||||
if (filter_title !== undefined) {
|
||||
if (filter.has_operator("stream")) {
|
||||
if (!filter._sub) {
|
||||
// The stream is not set because it does not currently
|
||||
// exist (possibly due to a stream name change), or it
|
||||
// is a private stream and the user is not subscribed.
|
||||
set_narrow_title(filter_title);
|
||||
} else if (filter.has_operator("topic")) {
|
||||
const topic_name = filter.operands("topic")[0];
|
||||
set_narrow_title("#" + filter_title + " > " + topic_name);
|
||||
} else {
|
||||
set_narrow_title("Invalid user");
|
||||
set_narrow_title("#" + filter_title);
|
||||
}
|
||||
} else if (filter.has_operator("pm-with")) {
|
||||
const emails = filter.operands("pm-with")[0];
|
||||
const user_ids = people.emails_strings_to_user_ids_string(emails);
|
||||
if (user_ids !== undefined) {
|
||||
const names = people.get_recipients(user_ids);
|
||||
set_narrow_title(names);
|
||||
} else {
|
||||
if (emails.includes(",")) {
|
||||
set_narrow_title("Invalid users");
|
||||
} else {
|
||||
set_narrow_title("Invalid user");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set_narrow_title(filter_title);
|
||||
}
|
||||
} else if (filter.has_operator("group-pm-with")) {
|
||||
const emails = filter.operands("group-pm-with")[0];
|
||||
|
@ -166,6 +171,8 @@ function update_narrow_title(filter) {
|
|||
set_narrow_title("Invalid user");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set_narrow_title(search_default);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue