]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Progress bar does not stop in TableKeyValueComponent 24016/head
authorVolker Theile <vtheile@suse.com>
Mon, 10 Sep 2018 15:27:58 +0000 (17:27 +0200)
committerVolker Theile <vtheile@suse.com>
Mon, 10 Sep 2018 16:29:05 +0000 (18:29 +0200)
Fixes: https://tracker.ceph.com/issues/35907
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.ts

index 276f9e07f1e617b6e2f1588d132717ea4878afb6..707b7990c406c63e0df71d1ec35a7e3b58048c39 100644 (file)
@@ -1,4 +1,5 @@
-<cd-table [data]="tableData"
+<cd-table #table
+          [data]="tableData"
           [columns]="columns"
           columnMode="flex"
           [toolHeader]="false"
@@ -6,6 +7,5 @@
           [autoSave]="false"
           [header]="false"
           [footer]="false"
-          [limit]="0"
-          (fetchData)="reloadData()">
+          [limit]="0">
 </cd-table>
index 030445a1615760858c6933a757846b200bc44703..9e7e2a8e56dcb0ffb395534fe0152ec38f18713a 100644 (file)
@@ -210,4 +210,22 @@ describe('TableKeyValueComponent', () => {
       ]);
     });
   });
+
+  describe('subscribe fetchData', () => {
+    it('should not subscribe fetchData of table', () => {
+      component.ngOnInit();
+      expect(component.table.fetchData.observers.length).toBe(0);
+    });
+
+    it('should call fetchData', () => {
+      let called = false;
+      component.fetchData.subscribe(() => {
+        called = true;
+      });
+      component.ngOnInit();
+      expect(component.table.fetchData.observers.length).toBe(1);
+      component.table.fetchData.emit();
+      expect(called).toBeTruthy();
+    });
+  });
 });
index 23c2e46d5e2507d04fecc3f922be0568aadf3ba1..5b8dee8e5352a5076ed13e3536ed4a0233d08245 100644 (file)
@@ -1,9 +1,18 @@
-import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
+import {
+  Component,
+  EventEmitter,
+  Input,
+  OnChanges,
+  OnInit,
+  Output,
+  ViewChild
+} from '@angular/core';
 
 import * as _ from 'lodash';
 
 import { CellTemplate } from '../../enum/cell-template.enum';
 import { CdTableColumn } from '../../models/cd-table-column';
+import { TableComponent } from '../table/table.component';
 
 /**
  * Display the given data in a 2 column data table. The left column
@@ -19,19 +28,20 @@ import { CdTableColumn } from '../../models/cd-table-column';
   styleUrls: ['./table-key-value.component.scss']
 })
 export class TableKeyValueComponent implements OnInit, OnChanges {
-  columns: Array<CdTableColumn> = [];
+  @ViewChild(TableComponent)
+  table: TableComponent;
 
   @Input()
   data: any;
   @Input()
   autoReload: any = 5000;
-
   @Input()
   renderObjects = false;
   // Only used if objects are rendered
   @Input()
   appendParentKey = true;
 
+  columns: Array<CdTableColumn> = [];
   tableData: {
     key: string;
     value: any;
@@ -57,6 +67,16 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
         flexGrow: 3
       }
     ];
+    // We need to subscribe the 'fetchData' event here and not in the
+    // HTML template, otherwise the data table will display the loading
+    // indicator infinitely if data is only bound via '[data]="xyz"'.
+    // See for 'loadingIndicator' in 'TableComponent::ngOnInit()'.
+    if (this.fetchData.observers.length > 0) {
+      this.table.fetchData.subscribe(() => {
+        // Forward event triggered by the 'cd-table' data table.
+        this.fetchData.emit();
+      });
+    }
     this.useData();
   }
 
@@ -143,9 +163,4 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
     }
     return v;
   }
-
-  reloadData() {
-    // Forward event triggered by the 'cd-table' datatable.
-    this.fetchData.emit();
-  }
 }