Stop query from executing if predicate is empty
If user types a query in the search bar with incomplete predicate then we do not execute the query if it is one of the pre-defined ones. Bug: Issue 7083 Change-Id: I5b29caf3a025f8b0282185133e18de1b6f21c859
This commit is contained in:
@@ -96,7 +96,7 @@
|
|||||||
|
|
||||||
// All of the ops, with corresponding negations.
|
// All of the ops, with corresponding negations.
|
||||||
const SEARCH_OPERATORS_WITH_NEGATIONS =
|
const SEARCH_OPERATORS_WITH_NEGATIONS =
|
||||||
SEARCH_OPERATORS.concat(SEARCH_OPERATORS.map(op => `-${op}`));
|
SEARCH_OPERATORS.concat(SEARCH_OPERATORS.map(op => `-${op}`));
|
||||||
|
|
||||||
const MAX_AUTOCOMPLETE_RESULTS = 10;
|
const MAX_AUTOCOMPLETE_RESULTS = 10;
|
||||||
|
|
||||||
@@ -191,7 +191,16 @@
|
|||||||
} else {
|
} else {
|
||||||
target.blur();
|
target.blur();
|
||||||
}
|
}
|
||||||
if (this._inputVal) {
|
const trimmedInput = this._inputVal && this._inputVal.trim();
|
||||||
|
if (trimmedInput) {
|
||||||
|
const predefinedOpOnlyQuery = SEARCH_OPERATORS_WITH_NEGATIONS.some(
|
||||||
|
op => {
|
||||||
|
return op.endsWith(':') && op === trimmedInput;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (predefinedOpOnlyQuery) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.dispatchEvent(new CustomEvent('handle-search', {
|
this.dispatchEvent(new CustomEvent('handle-search', {
|
||||||
detail: {inputVal: this._inputVal},
|
detail: {inputVal: this._inputVal},
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -93,6 +93,42 @@ limitations under the License.
|
|||||||
assert.isFalse(searchSpy.called);
|
assert.isFalse(searchSpy.called);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Predefined query op with no predication doesnt trigger nav', () => {
|
||||||
|
const searchSpy = sandbox.spy();
|
||||||
|
element.addEventListener('handle-search', searchSpy);
|
||||||
|
element.value = 'added:';
|
||||||
|
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
||||||
|
null, 'enter');
|
||||||
|
assert.isFalse(searchSpy.called);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('predefined predicate query triggers nav', () => {
|
||||||
|
const searchSpy = sandbox.spy();
|
||||||
|
element.addEventListener('handle-search', searchSpy);
|
||||||
|
element.value = 'age:1week';
|
||||||
|
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
||||||
|
null, 'enter');
|
||||||
|
assert.isTrue(searchSpy.called);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('undefined predicate query triggers nav', () => {
|
||||||
|
const searchSpy = sandbox.spy();
|
||||||
|
element.addEventListener('handle-search', searchSpy);
|
||||||
|
element.value = 'random:1week';
|
||||||
|
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
||||||
|
null, 'enter');
|
||||||
|
assert.isTrue(searchSpy.called);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('empty undefined predicate query triggers nav', () => {
|
||||||
|
const searchSpy = sandbox.spy();
|
||||||
|
element.addEventListener('handle-search', searchSpy);
|
||||||
|
element.value = 'random:';
|
||||||
|
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
||||||
|
null, 'enter');
|
||||||
|
assert.isTrue(searchSpy.called);
|
||||||
|
});
|
||||||
|
|
||||||
test('keyboard shortcuts', () => {
|
test('keyboard shortcuts', () => {
|
||||||
const focusSpy = sandbox.spy(element.$.searchInput, 'focus');
|
const focusSpy = sandbox.spy(element.$.searchInput, 'focus');
|
||||||
const selectAllSpy = sandbox.spy(element.$.searchInput, 'selectAll');
|
const selectAllSpy = sandbox.spy(element.$.searchInput, 'selectAll');
|
||||||
|
|||||||
Reference in New Issue
Block a user