Skip to content

Commit c8c55e2

Browse files
Add ability to set a class or hide menu actions in List View
1 parent 37022d3 commit c8c55e2

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed

misc/examples.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,7 @@ hr {
130130
.example-warning-background {
131131
background-color: #ec7a08 !important;
132132
}
133+
134+
.dropdown-kebab-pf.red .btn-link {
135+
color: red;
136+
}

src/views/listview/list-view-directive.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
* <li>.isDisabled - (Boolean) set to true to disable the action
4444
* <li>.isSeparator - (Boolean) set to true if this is a placeholder for a separator rather than an action
4545
* </ul>
46+
* @param {function (item))} hideMenuForItemFn function(item) Used to hide all menu actions for a particular item
47+
* @param {function (item))} menuClassForItemFn function(item) Used to specify a class for an item's dropdown kebab
4648
* @param {function (action, item))} updateMenuActionForItemFn function(action, item) Used to update a menu action based on the current item
4749
* @param {object} customScope Object containing any variables/functions used by the transcluded html, access via customScope.<xxx>
4850
* @example
@@ -55,7 +57,9 @@
5557
action-buttons="actionButtons"
5658
enable-button-for-item-fn="enableButtonForItemFn"
5759
menu-actions="menuActions"
58-
update-menu-action-for-item-fn="updateMenuActionForItemFn">
60+
update-menu-action-for-item-fn="updateMenuActionForItemFn"
61+
menu-class-for-item-fn="getMenuClass"
62+
hide-menu-for-item-fn="hideMenuActions">
5963
<div class="list-view-pf-description">
6064
<div class="list-group-item-heading">
6165
{{item.name}}
@@ -238,6 +242,18 @@
238242
},
239243
];
240244
245+
$scope.getMenuClass = function (item) {
246+
var menuClass = "";
247+
if (item.name === "Jim Beam") {
248+
menuClass = 'red';
249+
}
250+
return menuClass;
251+
};
252+
253+
$scope.hideMenuActions = function (item) {
254+
return (item.name === "Marie Edwards");
255+
};
256+
241257
var performAction = function (action, item) {
242258
$scope.eventText = item.name + " : " + action.name + "\r\n" + $scope.eventText;
243259
};
@@ -315,6 +331,8 @@ angular.module('patternfly.views').directive('pfListView', function ($timeout, $
315331
actionButtons: '=?',
316332
enableButtonForItemFn: '=?',
317333
menuActions: '=?',
334+
hideMenuForItemFn: '=?',
335+
menuClassForItemFn: '=?',
318336
updateMenuActionForItemFn: '=?',
319337
actions: '=?',
320338
updateActionForItemFn: '=?',
@@ -391,6 +409,24 @@ angular.module('patternfly.views').directive('pfListView', function ($timeout, $
391409
}
392410
};
393411

412+
$scope.getMenuClassForItem = function (item) {
413+
var menuClass = '';
414+
if (angular.isFunction($scope.menuClassForItemFn)) {
415+
menuClass = $scope.menuClassForItemFn(item);
416+
}
417+
418+
return menuClass;
419+
};
420+
421+
$scope.hideMenuForItem = function (item) {
422+
var hideMenu = false;
423+
if (angular.isFunction($scope.hideMenuForItemFn)) {
424+
hideMenu = $scope.hideMenuForItemFn(item);
425+
}
426+
427+
return hideMenu;
428+
};
429+
394430
$scope.setupActions = function (item, event) {
395431
// Ignore disabled items completely
396432
if ($scope.checkDisabled(item)) {

src/views/listview/list-view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div ng-if="actionButton.include" class="actionButton.includeClass" ng-include src="actionButton.include"></div>
1616
<span ng-if="!actionButton.include">{{actionButton.name}}</span>
1717
</button>
18-
<div class="{{dropdownClass}} pull-right dropdown-kebab-pf"
18+
<div class="{{dropdownClass}} pull-right dropdown-kebab-pf {{getMenuClassForItem(item)}} {{hideMenuForItem(item) ? 'invisible' : ''}}"
1919
id="kebab_{{$index}}"
2020
ng-if="menuActions && menuActions.length > 0">
2121
<button class="btn btn-link dropdown-toggle" type="button"

styles/angular-patternfly.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@
342342
margin: 0 5px;
343343
}
344344

345+
.dropdown-kebab-pf.invisible {
346+
opacity: 0;
347+
pointer-events: none;
348+
}
349+
345350
/* Utilization bar chart - Animate load */
346351
.utilization-bar-chart-pf .progress-bar {
347352
-webkit-transition: width .75s ease-in-out;

test/views/listview/list-view.spec.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ describe('Directive: pfDataList', function () {
4949
return (action.name !=='Action 2') || (item.uuid !== '2');
5050
};
5151

52+
$scope.hideMenuForItemFn = function(item) {
53+
return (item.uuid === '2');
54+
};
55+
56+
$scope.getMenuClassForItemFn = function(item) {
57+
var menuClass = '';
58+
if (item.uuid === '3') {
59+
menuClass = 'test-class';
60+
}
61+
return menuClass;
62+
};
63+
5264
performedAction = undefined;
5365
var performAction = function (action) {
5466
performedAction = action;
@@ -107,6 +119,8 @@ describe('Directive: pfDataList', function () {
107119
' action-buttons="actionButtons" ' +
108120
' enable-button-for-item-fn="enableButtonForItemFn" ' +
109121
' menu-actions="menuActions" ' +
122+
' menu-class-for-item-fn="getMenuClassForItemFn" ' +
123+
' hide-menu-for-item-fn="hideMenuForItemFn" ' +
110124
' update-menu-action-for-item-fn="updateActionForItemFn">' +
111125
'<div class="nameLabel1">{{item.name}}</div>' +
112126
'</div>';
@@ -483,4 +497,20 @@ describe('Directive: pfDataList', function () {
483497

484498
expect(actionArea.length).toBe(0);
485499
});
486-
})
500+
501+
it ('should hide kebab menu when specified', function () {
502+
var kebabs = element.find('.dropdown-kebab-pf');
503+
expect(kebabs.length).toBe(5);
504+
505+
var alteredKebab = element.find('.dropdown-kebab-pf.invisible');
506+
expect(alteredKebab.length).toBe(1);
507+
});
508+
509+
it ('should add a class to the kebab menu when specified', function () {
510+
var kebabs = element.find('.dropdown-kebab-pf');
511+
expect(kebabs.length).toBe(5);
512+
513+
var alteredKebab = element.find('.dropdown-kebab-pf.test-class');
514+
expect(alteredKebab.length).toBe(1);
515+
});
516+
});

0 commit comments

Comments
 (0)