From 7243d9b67dc8c15283e30f889eb4d3fd00a5701a Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Mon, 10 Sep 2018 17:27:58 +0200 Subject: [PATCH] mgr/dashboard: Progress bar does not stop in TableKeyValueComponent Fixes: https://tracker.ceph.com/issues/35907 Signed-off-by: Volker Theile --- .../table-key-value.component.html | 6 ++-- .../table-key-value.component.spec.ts | 18 +++++++++++ .../table-key-value.component.ts | 31 ++++++++++++++----- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.html index 276f9e07f1e61..707b7990c406c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.html @@ -1,4 +1,5 @@ - + [limit]="0"> diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.spec.ts index 030445a161576..9e7e2a8e56dcb 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.spec.ts @@ -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(); + }); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.ts index 23c2e46d5e250..5b8dee8e5352a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.ts @@ -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 = []; + @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 = []; 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(); - } } -- 2.39.5