Răsfoiți Sursa

HUE-6387 [assist] Add filter to the S3 panel

Johan Ahlen 8 ani în urmă
părinte
comite
8813ca5

+ 6 - 1
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -467,23 +467,28 @@ var ApiHelper = (function () {
    * @param {string[]} options.pathParts
    * @param {number} [options.pageSize] - Default 500
    * @param {number} [options.page] - Default 1
+   * @param {string} [options.filter]
    */
   ApiHelper.prototype.fetchS3Path = function (options) {
     var self = this;
     options.pathParts.shift(); // remove the trailing /
     var url = S3_API_PREFIX + options.pathParts.join("/") + '?format=json&sortby=name&descending=false&pagesize=' + (options.pageSize || 500) + '&pagenum=' + (options.page || 1);
+    if (options.filter) {
+      url += '&filter=' + options.filter;
+    }
     var fetchFunction = function (storeInCache) {
       if (options.timeout === 0) {
         self.assistErrorCallback(options)({ status: -1 });
         return;
       }
+
       $.ajax({
         dataType: "json",
         url: url,
         timeout: options.timeout,
         success: function (data) {
           if (!data.error && !self.successResponseIsError(data) && typeof data.files !== 'undefined' && data.files !== null) {
-            if (data.files.length > 2) {
+            if (data.files.length > 2 && !options.filter) {
               storeInCache(data);
             }
             options.successCallback(data);

+ 15 - 0
desktop/core/src/desktop/static/desktop/js/assist/assistS3Entry.js

@@ -44,6 +44,19 @@ var AssistS3Entry = (function () {
     self.currentPage = 1;
     self.hasMorePages = true;
 
+    self.isFilterVisible = ko.observable(false);
+    self.filter = ko.observable('').extend({ rateLimit: 400 });
+
+    self.isFilterVisible.subscribe(function (newValue) {
+      if (!newValue && self.filter()) {
+        self.filter('');
+      }
+    });
+
+    self.filter.subscribe(function () {
+      self.loadEntries();
+    });
+
     self.entries = ko.observableArray([]);
 
     self.loaded = false;
@@ -106,6 +119,7 @@ var AssistS3Entry = (function () {
     self.apiHelper.fetchS3Path({
       pageSize: PAGE_SIZE,
       page: self.currentPage,
+      filter: self.isFilterVisible() && self.filter().trim() ? self.filter() : undefined,
       pathParts: self.getHierarchy(),
       successCallback: successCallback,
       errorCallback: errorCallback
@@ -177,6 +191,7 @@ var AssistS3Entry = (function () {
     self.apiHelper.fetchS3Path({
       pageSize: PAGE_SIZE,
       page: self.currentPage,
+      filter: self.isFilterVisible() && self.filter().trim() ? self.filter() : undefined,
       pathParts: self.getHierarchy(),
       successCallback: function (data) {
         self.hasMorePages = data.page.next_page_number > self.currentPage;

+ 5 - 1
desktop/core/src/desktop/templates/assist.mako

@@ -292,6 +292,7 @@ from notebook.conf import get_ordered_interpreters
 
   <script type="text/html" id="assist-s3-header-actions">
     <div class="assist-db-header-actions">
+      <a class="inactive-action" href="javascript:void(0)" data-bind="toggle: isFilterVisible, css: { 'blue': isFilterVisible }" title="Filter"><i class="pointer fa fa-filter"></i></a>
       <a class="inactive-action" href="javascript:void(0)" data-bind="click: function () { huePubSub.publish('assist.s3.refresh'); }"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : loading }" title="${_('Manual refresh')}"></i></a>
     </div>
   </script>
@@ -314,6 +315,9 @@ from notebook.conf import get_ordered_interpreters
       <!-- /ko -->
       <!-- ko template: 'assist-s3-header-actions' --><!-- /ko -->
     </div>
+    <div class="assist-flex-file-search" data-bind="visible: isFilterVisible()">
+      <div class="assist-filter"><input class="clearable" type="text" placeholder="${ _('Filter...') }" data-bind="clearable: filter, value: filter, valueUpdate: 'afterkeydown'"/></div>
+    </div>
     <div class="assist-flex-fill assist-s3-scrollable">
       <div data-bind="visible: ! loading() && ! hasErrors()" style="position: relative;">
         <!-- ko hueSpinner: { spin: loadingMore, overlay: true } --><!-- /ko -->
@@ -338,7 +342,7 @@ from notebook.conf import get_ordered_interpreters
         </ul>
         <!-- ko if: !loading() && entries().length === 0 -->
         <ul class="assist-tables">
-          <li class="assist-entry"><span class="assist-no-entries">${_('Empty directory')}</span></li>
+          <li class="assist-entry"><span class="assist-no-entries"><!-- ko if: filter() -->${_('No results found')}<!-- /ko --><!-- ko ifnot: filter() -->${_('Empty directory')}<!-- /ko --></span></li>
         </ul>
         <!-- /ko -->
       </div>