mirror of
https://github.com/zulip/zulip.git
synced 2026-06-30 21:11:04 +08:00
search: Exclude with operator terms from search terms.
This commit excludes terms containing the `with` operator from the search terms, since `with` operator is not a search operator.
This commit is contained in:
parent
725d0e2d47
commit
ca2394495e
@ -18,11 +18,15 @@ export function filter(): Filter | undefined {
|
||||
export function search_terms(current_filter: Filter | undefined = filter()): NarrowTerm[] {
|
||||
if (current_filter === undefined) {
|
||||
if (page_params.narrow !== undefined) {
|
||||
return new Filter(page_params.narrow).terms();
|
||||
current_filter = new Filter(page_params.narrow);
|
||||
} else {
|
||||
current_filter = new Filter([]);
|
||||
}
|
||||
return new Filter([]).terms();
|
||||
}
|
||||
return current_filter.terms();
|
||||
|
||||
const non_search_operators = new Set(["with"]);
|
||||
|
||||
return current_filter.terms().filter((term) => !non_search_operators.has(term.operator));
|
||||
}
|
||||
|
||||
export function is_search_view(current_filter: Filter | undefined = filter()): boolean {
|
||||
|
||||
@ -151,6 +151,17 @@ test("terms", () => {
|
||||
assert.equal(result.length, 1);
|
||||
assert.equal(result[0].operator, "channel");
|
||||
assert.equal(result[0].operand, foo_stream_id.toString());
|
||||
|
||||
// `with` terms are excluded from search terms.
|
||||
page_params.narrow = [
|
||||
{operator: "stream", operand: foo_stream_id.toString()},
|
||||
{operator: "topic", operand: "Bar"},
|
||||
{operator: "with", operand: "12"},
|
||||
];
|
||||
result = narrow_state.search_terms();
|
||||
assert.equal(result.length, 2);
|
||||
assert.equal(result[0].operator, "channel");
|
||||
assert.equal(result[1].operator, "topic");
|
||||
});
|
||||
|
||||
test("excludes_muted_topics", () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user