Skip to content

Commit

Permalink
HUE-5952 [assist] Add error handling to assist search
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanAhlen committed Feb 27, 2017
1 parent 372c133 commit 9694c4d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Expand Up @@ -141,7 +141,13 @@
if (typeof $().hueAutocomplete === 'undefined') {
$.widget('custom.hueAutocomplete', $.ui.autocomplete, {
_renderItemData: function( ul, item ) {
if (item.noMatch && this.options.noMatchTemplate) {
if (item.error && this.options.errorTemplate) {
var $li = $('<li data-bind="template: { name: \'' + this.options.errorTemplate + '\' }">')
.addClass(this.options.classPrefix + 'autocomplete-item')
.appendTo(ul)
.data( "ui-autocomplete-item", item );
ko.applyBindings(item.data, $li[0]);
} else if (item.noMatch && this.options.noMatchTemplate) {
var $li = $('<li data-bind="template: { name: \'' + this.options.noMatchTemplate + '\' }">')
.addClass(this.options.classPrefix + 'autocomplete-item')
.appendTo(ul)
Expand Down
23 changes: 19 additions & 4 deletions desktop/core/src/desktop/templates/assist_search.mako
Expand Up @@ -48,13 +48,20 @@ from notebook.conf import ENABLE_QUERY_BUILDER
</div>
</script>
<script type="text/html" id="nav-search-autocomp-error">
<div class="nav-autocomplete-item-link" style="height: 30px;">
<div class="nav-autocomplete-empty">${ _('Error loading suggestions, see log for details.') }</div>
</div>
</script>
<script type="text/html" id="assist-panel-navigator-search">
<!-- ko if: navigatorSearch.navigatorEnabled() -->
<div class="search-container" data-bind="style: { 'padding-right': tabsEnabled ? null : '20px' }, with: navigatorSearch">
<input placeholder="${ _('Search...') }" type="text" data-bind="autocomplete: {
source: navAutocompleteSource,
itemTemplate: 'nav-search-autocomp-item',
noMatchTemplate: 'nav-search-autocomp-no-match',
errorTemplate: 'nav-search-autocomp-error',
classPrefix: 'nav-',
showOnFocus: false,
onEnter: performSearch,
Expand Down Expand Up @@ -86,8 +93,12 @@ from notebook.conf import ENABLE_QUERY_BUILDER
<div class="assist-flex-fill" data-bind="niceScroll" style="overflow:hidden;">
<!-- ko hueSpinner: { spin: searching, center: true, size: 'large' } --><!-- /ko -->
<!-- ko if: !searching() -->
<!-- ko if: hasErrors() -->
<div class="result-entry">${ _('Error searching, see logs for details.') }</div>
<!-- /ko -->
<!-- ko ifnot: hasErrors() -->
<!-- ko if: searchResult().length == 0 -->
<div class="result-entry">${ _('No result found.') }</div>
<div class="result-entry">${ _('No result found.') }</div>
<!-- /ko -->
<div data-bind="foreach: searchResult">
<div class="result-entry" data-bind="visibleOnHover: { override: statsVisible, selector: '.table-actions' }, event: { mouseover: showNavContextPopoverDelayed, mouseout: clearNavContextPopoverDelay }">
Expand All @@ -106,6 +117,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER
</div>
</div>
<!-- /ko -->
<!-- /ko -->
</div>
</div>
</script>
Expand Down Expand Up @@ -146,6 +158,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER
self.searchInput = ko.observable('').extend({rateLimit: 500});
self.searchResult = ko.observableArray();
self.hasErrors = ko.observable(false);
self.searchHasFocus = ko.observable(false);
self.searching = ko.observable(false);
self.searchActive = ko.observable(false);
Expand Down Expand Up @@ -182,6 +195,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER
}
lastQuery = self.searchInput();
self.searching(true);
self.hasErrors(false);
var showInAssist = function (entry) {
self.searchInput('');
Expand Down Expand Up @@ -240,7 +254,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER
query_s: ko.mapping.toJSON(self.searchInput()),
limit: 25,
sources: ko.mapping.toJSON([self.assistPanel.visiblePanel().type])
}, function (data) {
}).done(function (data) {
data.entities.forEach(function (entity) {
entity.statsVisible = ko.observable(false);
entity.showNavContextPopoverDelayed = showNavContextPopoverDelayed;
Expand Down Expand Up @@ -298,9 +312,10 @@ from notebook.conf import ENABLE_QUERY_BUILDER
entity.hasDescription = typeof entity.originalDescription !== 'undefined' && entity.originalDescription !== null && entity.originalDescription.length > 0;
});
self.searchResult(data.entities);
self.searching(false);
}).fail(function (xhr, textStatus, errorThrown) {
self.hasErrors(true);
$(document).trigger("error", xhr.responseText);
}).always(function () {
self.searching(false);
});
};
Expand Down Expand Up @@ -372,7 +387,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER
},
silenceErrors: true,
errorCallback: function () {
callback([]);
callback([{ error: true }]);
}
});
};
Expand Down

0 comments on commit 9694c4d

Please sign in to comment.