From 3f36c85e9741e51c4e97379f19de5c23940be7b7 Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Mon, 10 Sep 2018 16:34:12 +0100 Subject: [PATCH] mgr/dashboard: More configs for table `updateSelectionOnRefresh` Fixes: https://tracker.ceph.com/issues/35904 Signed-off-by: Ricardo Marques --- .../osd/osd-list/osd-list.component.html | 2 +- .../datatable/table/table.component.spec.ts | 37 +++++++++++++++++++ .../shared/datatable/table/table.component.ts | 17 ++++++--- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html index 1381ad56033dc..056b7a39a135b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html @@ -3,7 +3,7 @@ [columns]="columns" selectionType="single" (updateSelection)="updateSelection($event)" - [updateSelectionOnRefresh]="false"> + [updateSelectionOnRefresh]="'never'">
{ component.reloadData(); }); + it('should update selection on refresh - "onChange"', () => { + spyOn(component, 'onSelect').and.callThrough(); + component.data = createFakeData(10); + component.selection.selected = [_.clone(component.data[1])]; + component.updateSelectionOnRefresh = 'onChange'; + component.updateSelected(); + expect(component.onSelect).toHaveBeenCalledTimes(0); + component.data[1].d = !component.data[1].d; + component.updateSelected(); + expect(component.onSelect).toHaveBeenCalled(); + }); + + it('should update selection on refresh - "always"', () => { + spyOn(component, 'onSelect').and.callThrough(); + component.data = createFakeData(10); + component.selection.selected = [_.clone(component.data[1])]; + component.updateSelectionOnRefresh = 'always'; + component.updateSelected(); + expect(component.onSelect).toHaveBeenCalled(); + component.data[1].d = !component.data[1].d; + component.updateSelected(); + expect(component.onSelect).toHaveBeenCalled(); + }); + + it('should update selection on refresh - "never"', () => { + spyOn(component, 'onSelect').and.callThrough(); + component.data = createFakeData(10); + component.selection.selected = [_.clone(component.data[1])]; + component.updateSelectionOnRefresh = 'never'; + component.updateSelected(); + expect(component.onSelect).toHaveBeenCalledTimes(0); + component.data[1].d = !component.data[1].d; + component.updateSelected(); + expect(component.onSelect).toHaveBeenCalledTimes(0); + }); + afterEach(() => { clearLocalStorage(); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts index fddc65e6086e6..bf577adf1545f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts @@ -93,9 +93,9 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O // e.g. 'single' or 'multi'. @Input() selectionType: string = undefined; - // If `true` selected item details will be updated on table refresh + // By default selected item details will be updated on table refresh, if data has changed @Input() - updateSelectionOnRefresh = true; + updateSelectionOnRefresh: 'always' | 'never' | 'onChange' = 'onChange'; @Input() autoSave = true; @@ -367,9 +367,7 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O this.updateFilter(true); } this.reset(); - if (this.updateSelectionOnRefresh) { - this.updateSelected(); - } + this.updateSelected(); } /** @@ -388,6 +386,9 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O * or some selected items may have been removed. */ updateSelected() { + if (this.updateSelectionOnRefresh === 'never') { + return; + } const newSelected = []; this.selection.selected.forEach((selectedItem) => { for (const row of this.data) { @@ -396,6 +397,12 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O } } }); + if ( + this.updateSelectionOnRefresh === 'onChange' && + _.isEqual(this.selection.selected, newSelected) + ) { + return; + } this.selection.selected = newSelected; this.onSelect(); } -- 2.39.5