mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
search: Display invalid operand suggestion for has operator.
`has` operator uses predefined categories. This commit displays an invalid operand message if the operand does not fall in to any of these categories and the `has` operator is not at the last. e.g. `has:abc sender:abc@zulipchat.com` will have `invalid abc operand for has operator, sent by abc@zulipchat.com` as a prefix for all its suggestions.
This commit is contained in:
committed by
Tim Abbott
parent
2945062b79
commit
1b07b32ec1
@@ -665,6 +665,20 @@ run_test('describe', () => {
|
|||||||
string = 'stream devel, exclude messages with one or more image';
|
string = 'stream devel, exclude messages with one or more image';
|
||||||
assert.equal(Filter.describe(narrow), string);
|
assert.equal(Filter.describe(narrow), string);
|
||||||
|
|
||||||
|
narrow = [
|
||||||
|
{operator: 'has', operand: 'abc', negated: true},
|
||||||
|
{operator: 'stream', operand: 'devel'},
|
||||||
|
];
|
||||||
|
string = 'invalid abc operand for has operator, stream devel';
|
||||||
|
assert.equal(Filter.describe(narrow), string);
|
||||||
|
|
||||||
|
narrow = [
|
||||||
|
{operator: 'has', operand: 'image', negated: true},
|
||||||
|
{operator: 'stream', operand: 'devel'},
|
||||||
|
];
|
||||||
|
string = 'exclude messages with one or more image, stream devel';
|
||||||
|
assert.equal(Filter.describe(narrow), string);
|
||||||
|
|
||||||
narrow = [];
|
narrow = [];
|
||||||
string = 'all messages';
|
string = 'all messages';
|
||||||
assert.equal(Filter.describe(narrow), string);
|
assert.equal(Filter.describe(narrow), string);
|
||||||
|
|||||||
@@ -553,6 +553,7 @@ Filter.operator_to_prefix = function (operator, negated) {
|
|||||||
case 'near':
|
case 'near':
|
||||||
return verb + 'messages around';
|
return verb + 'messages around';
|
||||||
|
|
||||||
|
// Note: We hack around using this in "describe" below.
|
||||||
case 'has':
|
case 'has':
|
||||||
return verb + 'messages with one or more';
|
return verb + 'messages with one or more';
|
||||||
|
|
||||||
@@ -623,6 +624,14 @@ function describe_unescaped(operators) {
|
|||||||
}
|
}
|
||||||
return operand + ' messages';
|
return operand + ' messages';
|
||||||
}
|
}
|
||||||
|
if (canonicalized_operator ==='has') {
|
||||||
|
// search_suggestion.get_suggestions takes care that this message will
|
||||||
|
// only be shown if the `has` operator is not at the last.
|
||||||
|
var valid_has_operands = ['image', 'images', 'link', 'links', 'attachment', 'attachments'];
|
||||||
|
if (valid_has_operands.indexOf(operand) === -1) {
|
||||||
|
return 'invalid ' + operand + ' operand for has operator';
|
||||||
|
}
|
||||||
|
}
|
||||||
var prefix_for_operator = Filter.operator_to_prefix(canonicalized_operator,
|
var prefix_for_operator = Filter.operator_to_prefix(canonicalized_operator,
|
||||||
elem.negated);
|
elem.negated);
|
||||||
if (prefix_for_operator !== '') {
|
if (prefix_for_operator !== '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user