Files
zulip/static/js/search_pill.js
Ryan Rehman 21cdc26193 search: Support multiple search pills creation.
This reverts part of b0d632577f.
The problem was that multiple queries were combined as a single
search pill. And since we create the pills then narrow / search,
we added a comma seperator between them for the typeahead lookups
as required by the logic in `input_pill.js`.

This however introduced a new bug where the search suggestions
were incorrect as the typeahead lookup table wasn't updated, so
every time an item from the type ahead was selected it updated
the input string with an invalid operator.

Thus to resolve the first problem, we follow a simpler approach
by extracting all operators from the search string using our
`Filter.parse` logic and next add the pills, one by one.
2020-06-19 16:18:52 -07:00

41 lines
1.2 KiB
JavaScript

exports.create_item_from_search_string = function (search_string) {
const operator = Filter.parse(search_string);
const description = Filter.describe(operator);
return {
display_value: search_string,
description: description,
};
};
exports.get_search_string_from_item = function (item) {
return item.display_value;
};
exports.create_pills = function (pill_container) {
const pills = input_pill.create({
container: pill_container,
create_item_from_text: exports.create_item_from_search_string,
get_text_from_item: exports.get_search_string_from_item,
});
return pills;
};
exports.append_search_string = function (search_string, pill_widget) {
const operators = Filter.parse(search_string);
for (const operator of operators) {
const input = Filter.unparse([operator]);
pill_widget.appendValue(input);
}
if (pill_widget.clear_text !== undefined) {
pill_widget.clear_text();
}
};
exports.get_search_string_for_current_filter = function (pill_widget) {
const items = pill_widget.items();
const search_strings = items.map(item => item.display_value);
return search_strings.join(' ');
};
window.search_pill = exports;