mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	search: Cut dependency on narrow.js module.
				
					
				
			This commit is contained in:
		@@ -5,13 +5,12 @@ import render_search_list_item from "../templates/search_list_item.hbs";
 | 
			
		||||
import {Filter} from "./filter";
 | 
			
		||||
import * as keydown_util from "./keydown_util";
 | 
			
		||||
import * as message_view_header from "./message_view_header";
 | 
			
		||||
import * as narrow from "./narrow";
 | 
			
		||||
import * as search_suggestion from "./search_suggestion";
 | 
			
		||||
 | 
			
		||||
// Exported for unit testing
 | 
			
		||||
export let is_using_input_method = false;
 | 
			
		||||
 | 
			
		||||
export function narrow_or_search_for_term(search_string) {
 | 
			
		||||
export function narrow_or_search_for_term(search_string, {on_narrow_search}) {
 | 
			
		||||
    const $search_query_box = $("#search_query");
 | 
			
		||||
    if (is_using_input_method) {
 | 
			
		||||
        // Neither narrow nor search when using input tools as
 | 
			
		||||
@@ -21,7 +20,7 @@ export function narrow_or_search_for_term(search_string) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const operators = Filter.parse(search_string);
 | 
			
		||||
    narrow.activate(operators, {trigger: "search"});
 | 
			
		||||
    on_narrow_search(operators, {trigger: "search"});
 | 
			
		||||
 | 
			
		||||
    // It's sort of annoying that this is not in a position to
 | 
			
		||||
    // blur the search box, because it means that Esc won't
 | 
			
		||||
@@ -33,7 +32,7 @@ export function narrow_or_search_for_term(search_string) {
 | 
			
		||||
    return $search_query_box.val();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function initialize() {
 | 
			
		||||
export function initialize({on_narrow_search}) {
 | 
			
		||||
    const $search_query_box = $("#search_query");
 | 
			
		||||
    const $searchbox_form = $("#searchbox_form");
 | 
			
		||||
 | 
			
		||||
@@ -64,7 +63,7 @@ export function initialize() {
 | 
			
		||||
            return true;
 | 
			
		||||
        },
 | 
			
		||||
        updater(search_string) {
 | 
			
		||||
            return narrow_or_search_for_term(search_string);
 | 
			
		||||
            return narrow_or_search_for_term(search_string, {on_narrow_search});
 | 
			
		||||
        },
 | 
			
		||||
        sorter(items) {
 | 
			
		||||
            return items;
 | 
			
		||||
@@ -109,7 +108,7 @@ export function initialize() {
 | 
			
		||||
                // indicate that they've done what they need to do)
 | 
			
		||||
 | 
			
		||||
                // Pill is already added during keydown event of input pills.
 | 
			
		||||
                narrow_or_search_for_term($search_query_box.val());
 | 
			
		||||
                narrow_or_search_for_term($search_query_box.val(), {on_narrow_search});
 | 
			
		||||
                $search_query_box.trigger("blur");
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 
 | 
			
		||||
@@ -719,7 +719,9 @@ export function initialize_everything() {
 | 
			
		||||
        on_enter_send: compose.finish,
 | 
			
		||||
    });
 | 
			
		||||
    compose_textarea.initialize();
 | 
			
		||||
    search.initialize();
 | 
			
		||||
    search.initialize({
 | 
			
		||||
        on_narrow_search: narrow.activate,
 | 
			
		||||
    });
 | 
			
		||||
    tutorial.initialize();
 | 
			
		||||
    notifications.initialize({on_click_scroll_to_selected: navigate.scroll_to_selected});
 | 
			
		||||
    unread_ops.initialize();
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,6 @@ const {mock_esm, zrequire} = require("./lib/namespace");
 | 
			
		||||
const {run_test} = require("./lib/test");
 | 
			
		||||
const $ = require("./lib/zjquery");
 | 
			
		||||
 | 
			
		||||
const narrow = mock_esm("../src/narrow");
 | 
			
		||||
const narrow_state = mock_esm("../src/narrow_state");
 | 
			
		||||
const search_suggestion = mock_esm("../src/search_suggestion");
 | 
			
		||||
 | 
			
		||||
@@ -44,6 +43,8 @@ run_test("initialize", ({mock_template}) => {
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    search_suggestion.max_num_of_search_results = 999;
 | 
			
		||||
    let operators;
 | 
			
		||||
 | 
			
		||||
    $search_query_box.typeahead = (opts) => {
 | 
			
		||||
        assert.equal(opts.items, 999);
 | 
			
		||||
        assert.equal(opts.naturalSearch, true);
 | 
			
		||||
@@ -171,7 +172,6 @@ run_test("initialize", ({mock_template}) => {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            let operators;
 | 
			
		||||
            let is_blurred;
 | 
			
		||||
            $search_query_box.on("blur", () => {
 | 
			
		||||
                is_blurred = true;
 | 
			
		||||
@@ -184,10 +184,6 @@ run_test("initialize", ({mock_template}) => {
 | 
			
		||||
                    assert.equal(search_string, search_box_val);
 | 
			
		||||
                    return operators;
 | 
			
		||||
                };
 | 
			
		||||
                narrow.activate = (raw_operators, options) => {
 | 
			
		||||
                    assert.deepEqual(raw_operators, operators);
 | 
			
		||||
                    assert.deepEqual(options, {trigger: "search"});
 | 
			
		||||
                };
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            operators = [
 | 
			
		||||
@@ -221,7 +217,12 @@ run_test("initialize", ({mock_template}) => {
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    search.initialize();
 | 
			
		||||
    search.initialize({
 | 
			
		||||
        on_narrow_search(raw_operators, options) {
 | 
			
		||||
            assert.deepEqual(raw_operators, operators);
 | 
			
		||||
            assert.deepEqual(options, {trigger: "search"});
 | 
			
		||||
        },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $search_query_box.val("test string");
 | 
			
		||||
    narrow_state.search_string = () => "ver";
 | 
			
		||||
@@ -257,7 +258,6 @@ run_test("initialize", ({mock_template}) => {
 | 
			
		||||
    ev = {
 | 
			
		||||
        type: "keyup",
 | 
			
		||||
    };
 | 
			
		||||
    let operators;
 | 
			
		||||
    let is_blurred;
 | 
			
		||||
    $search_query_box.off("blur");
 | 
			
		||||
    $search_query_box.on("blur", () => {
 | 
			
		||||
@@ -271,10 +271,6 @@ run_test("initialize", ({mock_template}) => {
 | 
			
		||||
            assert.equal(search_string, search_box_val);
 | 
			
		||||
            return operators;
 | 
			
		||||
        };
 | 
			
		||||
        narrow.activate = (raw_operators, options) => {
 | 
			
		||||
            assert.deepEqual(raw_operators, operators);
 | 
			
		||||
            assert.deepEqual(options, {trigger: "search"});
 | 
			
		||||
        };
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    operators = [
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user