]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Searchable objects for table 31199/head
authorStephan Müller <smueller@suse.com>
Thu, 19 Sep 2019 14:04:34 +0000 (16:04 +0200)
committerStephan Müller <smueller@suse.com>
Mon, 4 Nov 2019 13:06:33 +0000 (14:06 +0100)
The table can now search through objects, by default it won't search
through them, but it won't fail like before.

The RBD list page is now capable of searching through objects, which
only exist on an RBD that was cloned from a snapshot.

Fixes: https://tracker.ceph.com/issues/42480
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts

index af73500de78872cb45cfa800d656743fb2f3c2e9..ccd95925353571c5afdbcada2ef6ad2bd956c43a 100644 (file)
@@ -7,6 +7,7 @@
           columnMode="flex"
           [columns]="columns"
           identifier="id"
+          [searchableObjects]="true"
           forceIdentifier="true"
           selectionType="single"
           (updateSelection)="updateSelection($event)">
index 3d5a8101f9f89f8c7cad6358a734d1f69ecff9df..46baec7e139cfd75e98dcf742fa15450a3f00d3e 100644 (file)
@@ -109,6 +109,33 @@ describe('TableComponent', () => {
       component.updateFilter(true);
     };
 
+    describe('searchableObjects', () => {
+      const testObject = {
+        obj: {
+          min: 8,
+          max: 123
+        }
+      };
+
+      beforeEach(() => {
+        component.data = [testObject];
+        component.columns = [{ prop: 'obj', name: 'Object' }];
+      });
+
+      it('should not search through objects as default case', () => {
+        expect(component.searchableObjects).toBe(false);
+        expectSearch('8', []);
+      });
+
+      it('should search through objects if searchableObjects is set to true', () => {
+        component.searchableObjects = true;
+        expectSearch('28', []);
+        expectSearch('8', [testObject]);
+        expectSearch('123', [testObject]);
+        expectSearch('max', [testObject]);
+      });
+    });
+
     it('should find a particular number', () => {
       expectSearch('5', [{ a: 5, b: 50, c: true }]);
       expectSearch('9', [{ a: 9, b: 90, c: true }]);
index bd00af4e7e69213ac8b6deb2b255406d9ecf698a..feff197838a4270add2ec02bca78b74010aa6261 100644 (file)
@@ -106,6 +106,10 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
   @Input()
   autoSave = true;
 
+  // Enable this in order to search through the JSON of any used object.
+  @Input()
+  searchableObjects = false;
+
   // Only needed to set if the classAddingTpl is used
   @Input()
   customCss?: { [css: string]: number | string | ((any) => boolean) };
@@ -561,6 +565,15 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
           } else if (_.isNumber(cellValue) || _.isBoolean(cellValue)) {
             cellValue = cellValue.toString();
           }
+
+          if (_.isObjectLike(cellValue)) {
+            if (this.searchableObjects) {
+              cellValue = JSON.stringify(cellValue);
+            } else {
+              return false;
+            }
+          }
+
           return cellValue.toLowerCase().indexOf(searchTerm) !== -1;
         }).length > 0
       );