mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
search_suggestion: Fix empty topic suggestion topic display name.
Earlier, we removed topic display name for empty topic operand when query was for topic autocomplete. But we should make sure that we only do this for the last search term in the suggestion which corresponds to the typed query and not any previously selected entered search term. Also recently we removed subset suggestions, so can safely check it for last search term for all suggestions. This commit fixes this by checking if the topic suggestion is the last search_term in the suggestion/search_terms. Co-authored-by: Evy Kassirer <evy@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
6ab30fcced
commit
62093ee37d
@@ -121,7 +121,7 @@ function on_pill_exit(
|
||||
// pill. We can probably simplify things by separating out a function
|
||||
// that generates `description_html` from the information in a single
|
||||
// search pill, and remove `description_html` from the `Suggestion` type.
|
||||
export function generate_pills_html(suggestion: Suggestion, query: string): string {
|
||||
export function generate_pills_html(suggestion: Suggestion, text_query: string): string {
|
||||
const search_terms = Filter.parse(suggestion.search_string);
|
||||
|
||||
const pill_render_data = search_terms.map((term, index) => {
|
||||
@@ -136,21 +136,28 @@ export function generate_pills_html(suggestion: Suggestion, query: string): stri
|
||||
};
|
||||
|
||||
if (search_pill.operator === "topic" && search_pill.operand === "") {
|
||||
// There are two variants of this suggestion state: One is the user
|
||||
// has selected a topic operator and operator, and and thus has
|
||||
// exactly `topic:` or `-topic:` written out, and it's be
|
||||
// appropriate to suggest the "general chat" value.
|
||||
// There are three variants of this suggestion state:
|
||||
//
|
||||
// The other variant is where we're suggesting `topic` as a
|
||||
// potential operator to add, say if the user has typed `-to` so
|
||||
// far. For that case, we want to suggest adding a topic operator,
|
||||
// but the user hasn't done anything that would suggest we should
|
||||
// further complete "general chat" as value for that topic operator.
|
||||
// (1) This is an already formed pill, i.e. not in the text input
|
||||
// (`text_query`), or is not the last term in the text input, and
|
||||
// therefore the empty operand represents "general chat".
|
||||
//
|
||||
// We can simply differentiate these cases by checking if `:` is
|
||||
// present in the query. See `set_search_bar_contents` for more
|
||||
// context.
|
||||
if (query.includes(":")) {
|
||||
// (2) The user has selected a topic operator, and and thus has
|
||||
// exactly `topic:` or `-topic:` written out, and it's appropriate
|
||||
// to suggest the "general chat" operand.
|
||||
//
|
||||
// (3) We're suggesting `topic` as a potential operator to add, say
|
||||
// if the user has typed `-to` so far. For that case, we want to
|
||||
// suggest adding a topic operator, but the user hasn't done anything
|
||||
// that would suggest we should further complete "general chat" as an
|
||||
// operand for that topic operator.
|
||||
if (
|
||||
// case 1
|
||||
text_query === "" ||
|
||||
index < search_terms.length - 1 ||
|
||||
// case 2
|
||||
text_query.trim().endsWith("topic:")
|
||||
) {
|
||||
return {
|
||||
...search_pill,
|
||||
is_empty_string_topic: true,
|
||||
@@ -158,6 +165,7 @@ export function generate_pills_html(suggestion: Suggestion, query: string): stri
|
||||
topic_display_name: util.get_final_topic_display_name(""),
|
||||
};
|
||||
}
|
||||
// case 3
|
||||
return {
|
||||
...search_pill,
|
||||
is_empty_string_topic: true,
|
||||
|
Reference in New Issue
Block a user