]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add a description tooltip for disabled items
authorTatjana Dehler <tdehler@suse.com>
Tue, 28 May 2019 06:33:08 +0000 (08:33 +0200)
committerTatjana Dehler <tdehler@suse.com>
Tue, 2 Jul 2019 08:23:47 +0000 (10:23 +0200)
Add the possibility to show a description tooltip for disabled
menu items. The description is optional. If no description is
given for a specific menu item, no tooltip will be shown.

Signed-off-by: Tatjana Dehler <tdehler@suse.com>
(cherry picked from commit 4a28b52990b6b4fa7e0f9505e4a37a2853ba620c)

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.scss
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-table-action.ts

index 1e93b4aeceb6a7f386cb82cba8938820210455d7..e0d6c209f923c5514a9c4151d0aa66d67acd4f12 100644 (file)
@@ -24,7 +24,8 @@
     <ng-container *ngFor="let action of dropDownActions">
       <li role="menuitem"
           class="{{ toClassName(action['name']) }}"
-          [ngClass]="{'disabled': disableSelectionAction(action)}">
+          [ngClass]="{'disabled': disableSelectionAction(action)}"
+          data-toggle="tooltip" title="{{ useDisableDesc(action) }}">
         <a class="dropdown-item"
            (click)="useClickAction(action)"
            [routerLink]="useRouterLink(action)">
index 35d8ba4933fa75e97d9dc4e8ec8138eda5518907..45fcf511841d6eb5c396c6971bc694a8f7c2d67a 100644 (file)
@@ -284,4 +284,51 @@ describe('TableActionsComponent', () => {
     expect(component.toClassName('Mark x down')).toBe('mark-x-down');
     expect(component.toClassName('?Su*per!')).toBe('super');
   });
+
+  describe('useDisableDesc', () => {
+    it('should return a description if disableDesc is set for action', () => {
+      const deleteWithDescAction: CdTableAction = {
+        permission: 'delete',
+        icon: 'fa-times',
+        canBePrimary: (selection: CdTableSelection) => selection.hasSelection,
+        disableDesc: () => {
+          return 'Delete action disabled description';
+        },
+        name: 'DeleteDesc'
+      };
+
+      expect(component.useDisableDesc(deleteWithDescAction)).toBe(
+        'Delete action disabled description'
+      );
+    });
+
+    it('should return no description if disableDesc is not set for action', () => {
+      expect(component.useDisableDesc(deleteAction)).toBeUndefined();
+    });
+  });
+
+  describe('useClickAction', () => {
+    const editClickAction: CdTableAction = {
+      permission: 'update',
+      icon: 'fa-pencil',
+      name: 'Edit',
+      click: () => {
+        return 'Edit action click';
+      }
+    };
+
+    it('should call click action if action is not disabled', () => {
+      editClickAction.disable = () => {
+        return false;
+      };
+      expect(component.useClickAction(editClickAction)).toBe('Edit action click');
+    });
+
+    it('should not call click action if action is disabled', () => {
+      editClickAction.disable = () => {
+        return true;
+      };
+      expect(component.useClickAction(editClickAction)).toBeFalsy();
+    });
+  });
 });
index 6b4d57eb78af487b29f151cd2e5ddc17eab19e7f..62f33acac186621c976a35fae134054c25491df3 100644 (file)
@@ -132,6 +132,17 @@ export class TableActionsComponent implements OnInit {
   }
 
   useClickAction(action: CdTableAction) {
-    return action.click && action.click();
+    /**
+     * In order to show tooltips for deactivated menu items, the class
+     * 'pointer-events: auto;' has been added to the .scss file which also
+     * re-activates the click-event.
+     * To prevent calling the click-event on deactivated elements we also have
+     * to check here if it's disabled.
+     */
+    return !this.disableSelectionAction(action) && action.click && action.click();
+  }
+
+  useDisableDesc(action: CdTableAction) {
+    return action.disableDesc && action.disableDesc();
   }
 }
index e266a66014cd4cc506f60736db8215bc8ac1bbcc..c5c6fab131e1d530d0de11e4901ff85717ec1b82 100644 (file)
@@ -22,6 +22,13 @@ export class CdTableAction {
   // if one selection is made and no task is running on the selected item.
   disable?: (_: CdTableSelection) => boolean;
 
+  /**
+   * In some cases you might want to give the user a hint why a button is
+   * disabled. The specified message will be shown to the user as a button
+   * tooltip.
+   */
+  disableDesc?: Function;
+
   /**
    * Defines if the button can become 'primary' (displayed as button and not
    * 'hidden' in the menu). Only one button can be primary at a time. By