mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	js: Convert static/js/search_suggestion.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							940861fd7e
						
					
				
				
					commit
					9d9c716dd2
				
			@@ -178,7 +178,6 @@
 | 
				
			|||||||
                "reminder": false,
 | 
					                "reminder": false,
 | 
				
			||||||
                "search": false,
 | 
					                "search": false,
 | 
				
			||||||
                "search_pill_widget": false,
 | 
					                "search_pill_widget": false,
 | 
				
			||||||
                "search_suggestion": false,
 | 
					 | 
				
			||||||
                "server_events": false,
 | 
					                "server_events": false,
 | 
				
			||||||
                "settings": false,
 | 
					                "settings": false,
 | 
				
			||||||
                "settings_account": false,
 | 
					                "settings_account": false,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,8 @@ const narrow_state = {
 | 
				
			|||||||
    filter: () => false,
 | 
					    filter: () => false,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
 | 
					rewiremock("../../static/js/narrow_state").with(narrow_state);
 | 
				
			||||||
const search_suggestion = set_global("search_suggestion", {});
 | 
					const search_suggestion = {__esModule: true};
 | 
				
			||||||
 | 
					rewiremock("../../static/js/search_suggestion").with(search_suggestion);
 | 
				
			||||||
rewiremock("../../static/js/ui_util").with({
 | 
					rewiremock("../../static/js/ui_util").with({
 | 
				
			||||||
    change_tab_to: noop,
 | 
					    change_tab_to: noop,
 | 
				
			||||||
    place_caret_at_end: noop,
 | 
					    place_caret_at_end: noop,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,8 @@ const noop = () => {};
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const narrow_state = {__esModule: true};
 | 
					const narrow_state = {__esModule: true};
 | 
				
			||||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
 | 
					rewiremock("../../static/js/narrow_state").with(narrow_state);
 | 
				
			||||||
const search_suggestion = set_global("search_suggestion", {});
 | 
					const search_suggestion = {__esModule: true};
 | 
				
			||||||
 | 
					rewiremock("../../static/js/search_suggestion").with(search_suggestion);
 | 
				
			||||||
rewiremock("../../static/js/ui_util").with({
 | 
					rewiremock("../../static/js/ui_util").with({
 | 
				
			||||||
    change_tab_to: noop,
 | 
					    change_tab_to: noop,
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,7 @@ const people = zrequire("people");
 | 
				
			|||||||
zrequire("unread");
 | 
					zrequire("unread");
 | 
				
			||||||
const search = zrequire("search_suggestion");
 | 
					const search = zrequire("search_suggestion");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
search.max_num_of_search_results = 15;
 | 
					search.__Rewire__("max_num_of_search_results", 15);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const me = {
 | 
					const me = {
 | 
				
			||||||
    email: "myself@zulip.com",
 | 
					    email: "myself@zulip.com",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,7 +26,7 @@ const people = zrequire("people");
 | 
				
			|||||||
zrequire("unread");
 | 
					zrequire("unread");
 | 
				
			||||||
const search = zrequire("search_suggestion");
 | 
					const search = zrequire("search_suggestion");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
search.max_num_of_search_results = 15;
 | 
					search.__Rewire__("max_num_of_search_results", 15);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const me = {
 | 
					const me = {
 | 
				
			||||||
    email: "myself@zulip.com",
 | 
					    email: "myself@zulip.com",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -119,7 +119,6 @@ const upload = zrequire("upload");
 | 
				
			|||||||
const compose = zrequire("compose");
 | 
					const compose = zrequire("compose");
 | 
				
			||||||
zrequire("composebox_typeahead");
 | 
					zrequire("composebox_typeahead");
 | 
				
			||||||
zrequire("narrow");
 | 
					zrequire("narrow");
 | 
				
			||||||
zrequire("search_suggestion");
 | 
					 | 
				
			||||||
zrequire("search");
 | 
					zrequire("search");
 | 
				
			||||||
zrequire("notifications");
 | 
					zrequire("notifications");
 | 
				
			||||||
zrequire("stream_list");
 | 
					zrequire("stream_list");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,6 @@ import "../reload";
 | 
				
			|||||||
import "../compose_actions";
 | 
					import "../compose_actions";
 | 
				
			||||||
import "../subs";
 | 
					import "../subs";
 | 
				
			||||||
import "../ui";
 | 
					import "../ui";
 | 
				
			||||||
import "../search_suggestion";
 | 
					 | 
				
			||||||
import "../search";
 | 
					import "../search";
 | 
				
			||||||
import "../composebox_typeahead";
 | 
					import "../composebox_typeahead";
 | 
				
			||||||
import "../navigate";
 | 
					import "../navigate";
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -51,7 +51,6 @@ declare let recent_topics: any;
 | 
				
			|||||||
declare let reminder: any;
 | 
					declare let reminder: any;
 | 
				
			||||||
declare let search: any;
 | 
					declare let search: any;
 | 
				
			||||||
declare let search_pill_widget: any;
 | 
					declare let search_pill_widget: any;
 | 
				
			||||||
declare let search_suggestion: any;
 | 
					 | 
				
			||||||
declare let server_events: any;
 | 
					declare let server_events: any;
 | 
				
			||||||
declare let settings: any;
 | 
					declare let settings: any;
 | 
				
			||||||
declare let settings_account: any;
 | 
					declare let settings_account: any;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
const {Filter} = require("./filter");
 | 
					const {Filter} = require("./filter");
 | 
				
			||||||
const narrow_state = require("./narrow_state");
 | 
					const narrow_state = require("./narrow_state");
 | 
				
			||||||
const search_pill = require("./search_pill");
 | 
					const search_pill = require("./search_pill");
 | 
				
			||||||
 | 
					const search_suggestion = require("./search_suggestion");
 | 
				
			||||||
const ui_util = require("./ui_util");
 | 
					const ui_util = require("./ui_util");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Exported for unit testing
 | 
					// Exported for unit testing
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +1,16 @@
 | 
				
			|||||||
"use strict";
 | 
					import Handlebars from "handlebars/runtime";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Handlebars = require("handlebars/runtime");
 | 
					import * as common from "./common";
 | 
				
			||||||
 | 
					import {Filter} from "./filter";
 | 
				
			||||||
 | 
					import * as huddle_data from "./huddle_data";
 | 
				
			||||||
 | 
					import * as narrow_state from "./narrow_state";
 | 
				
			||||||
 | 
					import * as people from "./people";
 | 
				
			||||||
 | 
					import * as settings_data from "./settings_data";
 | 
				
			||||||
 | 
					import * as stream_data from "./stream_data";
 | 
				
			||||||
 | 
					import * as stream_topic_history from "./stream_topic_history";
 | 
				
			||||||
 | 
					import * as typeahead_helper from "./typeahead_helper";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const common = require("./common");
 | 
					export const max_num_of_search_results = 12;
 | 
				
			||||||
const {Filter} = require("./filter");
 | 
					 | 
				
			||||||
const huddle_data = require("./huddle_data");
 | 
					 | 
				
			||||||
const narrow_state = require("./narrow_state");
 | 
					 | 
				
			||||||
const people = require("./people");
 | 
					 | 
				
			||||||
const settings_data = require("./settings_data");
 | 
					 | 
				
			||||||
const stream_data = require("./stream_data");
 | 
					 | 
				
			||||||
const stream_topic_history = require("./stream_topic_history");
 | 
					 | 
				
			||||||
const typeahead_helper = require("./typeahead_helper");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
exports.max_num_of_search_results = 12;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function stream_matches_query(stream_name, q) {
 | 
					function stream_matches_query(stream_name, q) {
 | 
				
			||||||
    return common.phrase_match(q, stream_name);
 | 
					    return common.phrase_match(q, stream_name);
 | 
				
			||||||
@@ -603,7 +601,7 @@ class Attacher {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.get_search_result = function (base_query, query) {
 | 
					export function get_search_result(base_query, query) {
 | 
				
			||||||
    let suggestion;
 | 
					    let suggestion;
 | 
				
			||||||
    let all_operators;
 | 
					    let all_operators;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -699,7 +697,7 @@ exports.get_search_result = function (base_query, query) {
 | 
				
			|||||||
        all_operators = search_operators;
 | 
					        all_operators = search_operators;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const base_operators = all_operators.slice(0, -1);
 | 
					    const base_operators = all_operators.slice(0, -1);
 | 
				
			||||||
    const max_items = exports.max_num_of_search_results;
 | 
					    const max_items = max_num_of_search_results;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const filterer of filterers) {
 | 
					    for (const filterer of filterers) {
 | 
				
			||||||
        if (attacher.result.length < max_items) {
 | 
					        if (attacher.result.length < max_items) {
 | 
				
			||||||
@@ -722,14 +720,14 @@ exports.get_search_result = function (base_query, query) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return attacher.result.slice(0, max_items);
 | 
					    return attacher.result.slice(0, max_items);
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.get_suggestions = function (base_query, query) {
 | 
					export function get_suggestions(base_query, query) {
 | 
				
			||||||
    const result = exports.get_search_result(base_query, query);
 | 
					    const result = get_search_result(base_query, query);
 | 
				
			||||||
    return exports.finalize_search_result(result);
 | 
					    return finalize_search_result(result);
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.finalize_search_result = function (result) {
 | 
					export function finalize_search_result(result) {
 | 
				
			||||||
    for (const sug of result) {
 | 
					    for (const sug of result) {
 | 
				
			||||||
        const first = sug.description.charAt(0).toUpperCase();
 | 
					        const first = sug.description.charAt(0).toUpperCase();
 | 
				
			||||||
        sug.description = first + sug.description.slice(1);
 | 
					        sug.description = first + sug.description.slice(1);
 | 
				
			||||||
@@ -748,6 +746,4 @@ exports.finalize_search_result = function (result) {
 | 
				
			|||||||
        strings,
 | 
					        strings,
 | 
				
			||||||
        lookup_table,
 | 
					        lookup_table,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
window.search_suggestion = exports;
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user