]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Use table actions component for OSDs
authorStephan Müller <smueller@suse.com>
Wed, 22 Aug 2018 06:45:08 +0000 (08:45 +0200)
committerStephan Müller <smueller@suse.com>
Wed, 19 Sep 2018 15:16:56 +0000 (17:16 +0200)
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html
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/osd/osd-list/osd-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.spec.ts

index 4bcec53b256c4c0824e7c6032faad1545763cfaf..b0148ccb796eaaa86ec900f1b47ba35e97f9434e 100644 (file)
@@ -6,34 +6,12 @@
           [updateSelectionOnRefresh]="'never'">
   <div class="table-actions btn-toolbar"
        *ngIf="permission.update">
-    <div class="btn-group"
-         dropdown>
-      <button dropdownToggle
-              type="button"
-              class="btn btn-sm btn-primary dropdown-toggle tc_scrub_toggle"
-              [ngClass]="{disabled: !tableComponent.selection.hasSelection}">
-        <ng-container i18n>Perform Task </ng-container>
-        <span class="caret"></span>
-      </button>
-      <ul *dropdownMenu
-          class="dropdown-menu"
-          role="menu">
-        <li role="menuitem"
-            (click)="scrubAction(false)">
-          <a>
-            <i class="fa fa-fw fa-stethoscope"></i>
-            <ng-container i18n>Scrub</ng-container>
-          </a>
-        </li>
-        <li role="menuitem"
-            (click)="scrubAction(true)">
-          <a>
-            <i class="fa fa-fw fa-stethoscope"></i>
-            <ng-container i18n>Deep Scrub</ng-container>
-          </a>
-        </li>
-      </ul>
-    </div>
+    <cd-table-actions [permission]="permission"
+                      [selection]="selection"
+                      onlyDropDown="Perform Task"
+                      class="btn-group"
+                      [tableActions]="tableActions">
+    </cd-table-actions>
 
     <button class="btn btn-sm btn-default btn-label tc_configureCluster"
             type="button"
index f5f5ce3e2d780b0f23f8f42d7725a58affddb6f9..30dba9a77beb2ddeeaedd905b299b1c5e31ceebc 100644 (file)
@@ -1,11 +1,13 @@
 import { HttpClientModule } from '@angular/common/http';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
 
 import { TabsModule } from 'ngx-bootstrap/tabs';
 
-import { configureTestBed } from '../../../../../testing/unit-test-helper';
+import { configureTestBed, PermissionHelper } from '../../../../../testing/unit-test-helper';
 import { ComponentsModule } from '../../../../shared/components/components.module';
 import { DataTableModule } from '../../../../shared/datatable/datatable.module';
+import { TableActionsComponent } from '../../../../shared/datatable/table-actions/table-actions.component';
 import { Permissions } from '../../../../shared/models/permissions';
 import { DimlessPipe } from '../../../../shared/pipes/dimless.pipe';
 import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
@@ -49,6 +51,44 @@ describe('OsdListComponent', () => {
   });
 
   it('should create', () => {
+    fixture.detectChanges();
     expect(component).toBeTruthy();
   });
+
+  describe('show table actions as defined', () => {
+    let tableActions: TableActionsComponent;
+    let scenario: { fn; empty; single };
+    let permissionHelper: PermissionHelper;
+
+    const getTableActionComponent = () => {
+      fixture.detectChanges();
+      return fixture.debugElement.query(By.directive(TableActionsComponent)).componentInstance;
+    };
+
+    beforeEach(() => {
+      permissionHelper = new PermissionHelper(component.permission, () =>
+        getTableActionComponent()
+      );
+      scenario = {
+        fn: () => tableActions.getCurrentButton(),
+        single: undefined,
+        empty: undefined
+      };
+      tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
+    });
+
+    it('shows no action button', () => permissionHelper.testScenarios(scenario));
+
+    it('shows all actions', () => {
+      expect(tableActions.tableActions.length).toBe(2);
+      expect(tableActions.tableActions).toEqual(component.tableActions);
+    });
+
+    it(`shows 'Perform task' as drop down`, () => {
+      expect(
+        fixture.debugElement.query(By.directive(TableActionsComponent)).query(By.css('button'))
+          .nativeElement.textContent
+      ).toBe('Perform Task');
+    });
+  });
 });
index 51876fdbdd4c099f56c3f6ea0ff2a0005f800d2d..41eeca1b292bd81b8bac52d0b63f6154157ca9ba 100644 (file)
@@ -5,6 +5,7 @@ import { BsModalRef, BsModalService } from 'ngx-bootstrap';
 import { OsdService } from '../../../../shared/api/osd.service';
 import { TableComponent } from '../../../../shared/datatable/table/table.component';
 import { CellTemplate } from '../../../../shared/enum/cell-template.enum';
+import { CdTableAction } from '../../../../shared/models/cd-table-action';
 import { CdTableColumn } from '../../../../shared/models/cd-table-column';
 import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
 import { Permission } from '../../../../shared/models/permissions';
@@ -27,6 +28,7 @@ export class OsdListComponent implements OnInit {
   tableComponent: TableComponent;
 
   permission: Permission;
+  tableActions: CdTableAction[];
   bsModalRef: BsModalRef;
   osds = [];
   columns: CdTableColumn[];
@@ -39,6 +41,19 @@ export class OsdListComponent implements OnInit {
     private modalService: BsModalService
   ) {
     this.permission = this.authStorageService.getPermissions().osd;
+    const scrubAction: CdTableAction = {
+      permission: 'update',
+      icon: 'fa-stethoscope',
+      click: () => this.scrubAction(false),
+      name: 'Scrub'
+    };
+    const deleteAction: CdTableAction = {
+      permission: 'update',
+      icon: 'fa-cog',
+      click: () => this.scrubAction(true),
+      name: 'Deep Scrub'
+    };
+    this.tableActions = [scrubAction, deleteAction];
   }
 
   ngOnInit() {
index 62d0203d007b3bc6395d09accaa497e7b20463b5..39d7dcb3e5e8220b777710683e3666dc7fce43e4 100644 (file)
@@ -12,7 +12,6 @@
   <button type="button"
           dropdownToggle
           *ngIf="showDropDownActions()"
-          [ngClass]="{'disabled': onlyDropDown && disableSelectionAction(onlyDropDown)}"
           class="btn btn-sm btn-primary dropdown-toggle dropdown-toggle-split">
     <ng-container *ngIf="onlyDropDown" i18n>{{ onlyDropDown }}</ng-container>
     <span class="caret"></span>
index 0e8f2d17d98263ac4441781c7a39842b346db914..970bb421ec1a74a7316686655b1043d9e26f0ef0 100644 (file)
@@ -268,4 +268,14 @@ describe('TableActionsComponent', () => {
       });
     });
   });
+
+  describe('with drop down only', () => {
+    beforeEach(() => {
+      component.onlyDropDown = 'displayMe';
+    });
+
+    it('should not return any button with getCurrentButton', () => {
+      expect(component.getCurrentButton()).toBeFalsy();
+    });
+  });
 });