mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 16:14:02 +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
|
// pill. We can probably simplify things by separating out a function
|
||||||
// that generates `description_html` from the information in a single
|
// that generates `description_html` from the information in a single
|
||||||
// search pill, and remove `description_html` from the `Suggestion` type.
|
// 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 search_terms = Filter.parse(suggestion.search_string);
|
||||||
|
|
||||||
const pill_render_data = search_terms.map((term, index) => {
|
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 === "") {
|
if (search_pill.operator === "topic" && search_pill.operand === "") {
|
||||||
// There are two variants of this suggestion state: One is the user
|
// There are three variants of this suggestion state:
|
||||||
// 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.
|
|
||||||
//
|
//
|
||||||
// The other variant is where we're suggesting `topic` as a
|
// (1) This is an already formed pill, i.e. not in the text input
|
||||||
// potential operator to add, say if the user has typed `-to` so
|
// (`text_query`), or is not the last term in the text input, and
|
||||||
// far. For that case, we want to suggest adding a topic operator,
|
// therefore the empty operand represents "general chat".
|
||||||
// but the user hasn't done anything that would suggest we should
|
|
||||||
// further complete "general chat" as value for that topic operator.
|
|
||||||
//
|
//
|
||||||
// We can simply differentiate these cases by checking if `:` is
|
// (2) The user has selected a topic operator, and and thus has
|
||||||
// present in the query. See `set_search_bar_contents` for more
|
// exactly `topic:` or `-topic:` written out, and it's appropriate
|
||||||
// context.
|
// to suggest the "general chat" operand.
|
||||||
if (query.includes(":")) {
|
//
|
||||||
|
// (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 {
|
return {
|
||||||
...search_pill,
|
...search_pill,
|
||||||
is_empty_string_topic: true,
|
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(""),
|
topic_display_name: util.get_final_topic_display_name(""),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// case 3
|
||||||
return {
|
return {
|
||||||
...search_pill,
|
...search_pill,
|
||||||
is_empty_string_topic: true,
|
is_empty_string_topic: true,
|
||||||
|
Reference in New Issue
Block a user