]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: remove the need to call `update()` on CdTableSelection
authorPatrick Seidensal <pseidensal@suse.com>
Mon, 23 Sep 2019 19:42:00 +0000 (21:42 +0200)
committerPatrick Seidensal <pseidensal@suse.com>
Thu, 5 Dec 2019 13:15:18 +0000 (14:15 +0100)
Signed-off-by: Patrick Seidensal <pseidensal@suse.com>
16 files changed:
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-tabs/cephfs-tabs.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-details/host-details.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/mgr-modules/mgr-module-list/mgr-module-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/silence-list/silence-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-details/nfs-details.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-details/pool-details.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-list/pool-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-table-selection.ts
src/pybind/mgr/dashboard/frontend/src/testing/unit-test-helper.ts

index 852c7619926784739bee049f223f170d56a3c713..95fb5b9589549d735119cfdf9e2420fbaf3c3e34 100644 (file)
@@ -74,7 +74,6 @@ describe('IscsiTargetDetailsComponent', () => {
         target_controls: { dataout_timeout: 2 }
       }
     ];
-    component.selection.update();
 
     fixture.detectChanges();
   });
index d0e395b3f50d925755550870abfc272c0a3f9337..37b09c6378011d5c728bd2e6330d0bb2be65656a 100644 (file)
@@ -202,7 +202,6 @@ describe('RbdSnapshotListComponent', () => {
 
     it('should display old snapshot name', () => {
       component.selection.selected = [{ name: 'oldname' }];
-      component.selection.update();
       component.openEditSnapshotModal();
       expect(component.modalRef.content.snapName).toBe('oldname');
       expect(component.modalRef.content.editing).toBeTruthy();
index 925d5fcfa7101b14e1f647708b2dcb929502a7c0..136b3aa4443f9143222fca656e04a00324866b8b 100644 (file)
@@ -51,12 +51,8 @@ describe('RbdTrashListComponent', () => {
   });
 
   it('should call updateSelection', () => {
-    const selection = new CdTableSelection();
-    selection.selected = ['foo'];
-    selection.update();
-
     expect(component.selection.hasSelection).toBeFalsy();
-    component.updateSelection(selection);
+    component.updateSelection(new CdTableSelection(['foo']));
     expect(component.selection.hasSelection).toBeTruthy();
   });
 
index 64170da229addf17edb33ae76cbe1807b34b3fbf..bb394e2424115a4caf2b9143a10fd38a68d1cff1 100644 (file)
@@ -51,7 +51,6 @@ describe('CephfsTabsComponent', () => {
 
   const setSelection = (selection: object[]) => {
     component.selection.selected = selection;
-    component.selection.update();
     component.ngOnChanges();
   };
 
index 354b67bc3316623906bc010d52e7eb62cf067339..ebe9f097e7204efdc32682444389854d8f4d86f0 100644 (file)
@@ -58,7 +58,6 @@ describe('HostDetailsComponent', () => {
           hostname: 'localhost'
         }
       ];
-      component.selection.update();
     });
 
     it('should recognize a tabset child', () => {
index 15cc3034909a86072816e7dd9afe15ec8fb94b01..931ef28e92166720f0658d269e18430bcf3e7d66 100644 (file)
@@ -97,12 +97,11 @@ describe('MgrModuleListComponent', () => {
     it('should enable module', fakeAsync(() => {
       spyOn(mgrModuleService, 'enable').and.returnValue(observableThrowError('y'));
       spyOn(mgrModuleService, 'list').and.returnValues(observableThrowError('z'), observableOf([]));
-      component.selection.selected.push({
+      component.selection.add({
         name: 'foo',
         enabled: false,
         always_on: false
       });
-      component.selection.update();
       component.updateModuleState();
       tick(2000);
       tick(2000);
@@ -117,12 +116,11 @@ describe('MgrModuleListComponent', () => {
     it('should disable module', fakeAsync(() => {
       spyOn(mgrModuleService, 'disable').and.returnValue(observableThrowError('x'));
       spyOn(mgrModuleService, 'list').and.returnValue(observableOf([]));
-      component.selection.selected.push({
+      component.selection.add({
         name: 'bar',
         enabled: true,
         always_on: false
       });
-      component.selection.update();
       component.updateModuleState();
       tick(2000);
       expect(mgrModuleService.disable).toHaveBeenCalledWith('bar');
@@ -139,7 +137,6 @@ describe('MgrModuleListComponent', () => {
           name: 'dashboard'
         }
       ];
-      component.selection.update();
       expect(component.isTableActionDisabled('enabled')).toBeTruthy();
     });
 
@@ -150,7 +147,6 @@ describe('MgrModuleListComponent', () => {
           always_on: true
         }
       ];
-      component.selection.update();
       expect(component.isTableActionDisabled('enabled')).toBeTruthy();
     });
   });
index ac6ce511b90bfd2f01c72abab1aeb097776e9d41..d3fb7285c67dbb5e22004b9e9916fc00f87f1103 100644 (file)
@@ -53,7 +53,6 @@ describe('OsdListComponent', () => {
     // Table data and selection
     component.selection = new CdTableSelection();
     component.selection.selected = selection;
-    component.selection.update();
     component.osds = data;
     component.permissions = fakeAuthStorageService.getPermissions();
   };
index ccacfd0fa784fbf6fd3742d7aff6984f5c7f7f21..d063b7309c1a5975265994d2dd8c92edba35b5e5 100644 (file)
@@ -94,10 +94,8 @@ describe('SilenceListComponent', () => {
   });
 
   describe('expire silence', () => {
-    const setSelectedSilence = (silenceName: string) => {
-      component.selection.selected = [{ id: silenceName }];
-      component.selection.update();
-    };
+    const setSelectedSilence = (silenceName: string) =>
+      (component.selection.selected = [{ id: silenceName }]);
 
     const expireSilence = () => {
       component.expireSilence();
index 2e2cb52c02edc94a0f195dee9de11ca4c96d28e8..f3f2829414803ae8777d12de5a00b23dd7b9110c 100644 (file)
@@ -51,7 +51,6 @@ describe('NfsDetailsComponent', () => {
         state: 'LOADING'
       }
     ];
-    component.selection.update();
     component.ngOnChanges();
     fixture.detectChanges();
   });
@@ -85,7 +84,6 @@ describe('NfsDetailsComponent', () => {
       }
     });
     component.selection.selected = [newData];
-    component.selection.update();
     component.ngOnChanges();
     expect(component.data).toEqual({
       'Access Type': 'RW',
index 4bf43944a140667bd44fb1c884ecf296838c75d8..f649c0d235228edaef598703d8b316e5ae0f4155 100644 (file)
@@ -41,7 +41,6 @@ describe('PoolDetailsComponent', () => {
           pool: 0
         }
       ];
-      poolDetailsComponent.selection.update();
     });
 
     it('should recognize a tabset child', () => {
@@ -64,7 +63,6 @@ describe('PoolDetailsComponent', () => {
           tiers: []
         }
       ];
-      poolDetailsComponent.selection.update();
       fixture.detectChanges();
       const tabs = poolDetailsComponent.tabsetChild.tabs;
       expect(tabs.length).toEqual(2);
index 3a365223ffd90dec8b5bc506d4bd1c01770451a0..e38ca50e881bbbf4b3ea88eec8672a41e60ee77c 100644 (file)
@@ -140,10 +140,8 @@ describe('PoolListComponent', () => {
   describe('pool deletion', () => {
     let taskWrapper: TaskWrapperService;
 
-    const setSelectedPool = (poolName: string) => {
-      component.selection.selected = [{ pool_name: poolName }];
-      component.selection.update();
-    };
+    const setSelectedPool = (poolName: string) =>
+      (component.selection.selected = [{ pool_name: poolName }]);
 
     const callDeletion = () => {
       component.deletePoolModal();
@@ -422,12 +420,7 @@ describe('PoolListComponent', () => {
 
   describe('getSelectionTiers', () => {
     const setSelectionTiers = (tiers: number[]) => {
-      component.selection.selected = [
-        {
-          tiers
-        }
-      ];
-      component.selection.update();
+      component.selection.selected = [{ tiers }];
       component.getSelectionTiers();
     };
 
index e14cbb63e66a5023785b80d12d239a3c3781a270..74f0ff400897329d8ce4619b32f70bbcd405cd57 100644 (file)
@@ -31,8 +31,7 @@ describe('RoleDetailsComponent', () => {
 
   it('should create scopes permissions [1/2]', () => {
     component.scopes = ['log', 'rgw'];
-    component.selection = new CdTableSelection();
-    component.selection.selected = [
+    component.selection = new CdTableSelection([
       {
         description: 'RGW Manager',
         name: 'rgw-manager',
@@ -41,8 +40,7 @@ describe('RoleDetailsComponent', () => {
         },
         system: true
       }
-    ];
-    component.selection.update();
+    ]);
     expect(component.scopes_permissions.length).toBe(0);
     component.ngOnChanges();
     expect(component.scopes_permissions).toEqual([
@@ -53,8 +51,7 @@ describe('RoleDetailsComponent', () => {
 
   it('should create scopes permissions [2/2]', () => {
     component.scopes = ['cephfs', 'log', 'rgw'];
-    component.selection = new CdTableSelection();
-    component.selection.selected = [
+    component.selection = new CdTableSelection([
       {
         description: 'Test',
         name: 'test',
@@ -64,8 +61,7 @@ describe('RoleDetailsComponent', () => {
         },
         system: false
       }
-    ];
-    component.selection.update();
+    ]);
     expect(component.scopes_permissions.length).toBe(0);
     component.ngOnChanges();
     expect(component.scopes_permissions).toEqual([
index 7b3fb44a183bdcd1156d449eae97e57fd9150d29..a596468169abe831ffb715cc9808c9c249cae928 100644 (file)
@@ -98,7 +98,7 @@
                  [cssClasses]="paginationClasses"
                  [selectionType]="selectionType"
                  [selected]="selection.selected"
-                 (select)="onSelect()"
+                 (select)="onSelect($event)"
                  [sorts]="userConfig.sorts"
                  (sort)="changeSorting($event)"
                  [columns]="tableColumns"
index e0053fc4a6003a61901a072b87fff1577de24c61..36d32cf81fdaf8caa15c4aaaaa36ea380d319432 100644 (file)
@@ -479,11 +479,11 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
       return;
     }
     this.selection.selected = newSelected;
-    this.onSelect();
+    this.onSelect(this.selection);
   }
 
-  onSelect() {
-    this.selection.update();
+  onSelect($event) {
+    this.selection.selected = $event['selected'];
     this.updateSelection.emit(_.clone(this.selection));
   }
 
index 9732abc5a032b2694d8f2d04083545100f39f7da..bbe1e5088c3cfc7b0717fa4eb994107d4b56fcfc 100644 (file)
@@ -1,10 +1,13 @@
 export class CdTableSelection {
-  selected: any[] = [];
+  private _selected: any[] = [];
   hasMultiSelection: boolean;
   hasSingleSelection: boolean;
   hasSelection: boolean;
 
-  constructor() {
+  constructor(rows?: any[]) {
+    if (rows) {
+      this._selected = rows;
+    }
     this.update();
   }
 
@@ -12,10 +15,24 @@ export class CdTableSelection {
    * Recalculate the variables based on the current number
    * of selected rows.
    */
-  update() {
-    this.hasSelection = this.selected.length > 0;
-    this.hasSingleSelection = this.selected.length === 1;
-    this.hasMultiSelection = this.selected.length > 1;
+  private update() {
+    this.hasSelection = this._selected.length > 0;
+    this.hasSingleSelection = this._selected.length === 1;
+    this.hasMultiSelection = this._selected.length > 1;
+  }
+
+  set selected(selection: any[]) {
+    this._selected = selection;
+    this.update();
+  }
+
+  get selected() {
+    return this._selected;
+  }
+
+  add(row: any) {
+    this._selected.push(row);
+    this.update();
   }
 
   /**
@@ -23,6 +40,6 @@ export class CdTableSelection {
    * @return {any | null}
    */
   first() {
-    return this.hasSelection ? this.selected[0] : null;
+    return this.hasSelection ? this._selected[0] : null;
   }
 }
index 3d5562d260e8414efb20d9f31a609d737d540292..b21c5a2a8dc4ae3819214d015afe8ddfa3e7c6dd 100644 (file)
@@ -111,7 +111,6 @@ export class PermissionHelper {
 
   setSelection(selection: object[]) {
     this.tac.selection.selected = selection;
-    this.tac.selection.update();
   }
 }