]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Fix error when filtering table without data 34867/head
authorTiago Melo <tmelo@suse.com>
Thu, 30 Apr 2020 16:39:48 +0000 (16:39 +0000)
committerTiago Melo <tmelo@suse.com>
Thu, 30 Apr 2020 17:18:20 +0000 (17:18 +0000)
Fixes: https://tracker.ceph.com/issues/45351
Signed-off-by: Tiago Melo <tmelo@suse.com>
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 7484b227409e4aa95058a25e629d1fe3f34bd67e..a3ac199a4ba16f23502fb2dce0de90785b9feeb1 100644 (file)
@@ -424,6 +424,13 @@ describe('TableComponent', () => {
       component.onClearSearch();
       expect(component.rows.length).toBe(10);
     });
+
+    it('should work with undefined data', () => {
+      component.data = undefined;
+      component.search = '3';
+      component.updateFilter();
+      expect(component.rows).toBeUndefined();
+    });
   });
 
   describe('after ngInit', () => {
index 7d9fb28a708011aede2fa905867ebaf2e874d1a1..83e4050970d1911aa99a2793b36392a9a7c133f7 100644 (file)
@@ -732,7 +732,7 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
   updateFilter() {
     let rows = this.columnFilters.length !== 0 ? this.doColumnFiltering() : this.data;
 
-    if (this.search.length > 0) {
+    if (this.search.length > 0 && rows) {
       const columns = this.columns.filter((c) => c.cellTransformation !== CellTemplate.sparkline);
       // update the rows
       rows = this.subSearch(rows, TableComponent.prepareSearch(this.search), columns);