Skip to content

Commit 3b4df01

Browse files
rhwoodcdcabrera
authored andcommitted
Allow action buttons in empty state for a card/list/table view (#511)
* Add ability to put action buttons into the empty state associated with views. Addresses #510. * Add function to examples to record clicking on empty state action buttons in example lists of events. Also fix one spelling error. * Add missing space. * Remove excess space in comments.
1 parent 08cc924 commit 3b4df01

File tree

9 files changed

+102
-9
lines changed

9 files changed

+102
-9
lines changed

src/table/tableview/examples/table-view-basic.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* <li>.actionFn - (function(action)) Function to invoke when the action selected
4545
* </ul>
4646
* @param {object} emptyStateConfig Optional configuration settings for the empty state component. See the {@link patternfly.views.component:pfEmptyState Empty State} component
47+
* @param {array} emptyStateActionButtons Optional buttons to display under the icon, title, and informational paragraph in the empty state component. See the {@link patternfly.views.component:pfEmptyState Empty State} component
4748
* @example
4849
<example module="patternfly.tableview.demo">
4950
<file name="index.html">
@@ -56,7 +57,8 @@
5657
columns="columns"
5758
items="items"
5859
action-buttons="actionButtons"
59-
menu-actions="menuActions">
60+
menu-actions="menuActions"
61+
empty-state-action-buttons="emptyStateActionButtons">
6062
</pf-table-view>
6163
</div>
6264
<div class="col-md-12" style="padding-top: 12px;">
@@ -121,6 +123,10 @@
121123
showCheckboxes: true
122124
};
123125
126+
var performEmptyStateAction = function (action) {
127+
$scope.eventText = action.name + "\r\n" + $scope.eventText;
128+
};
129+
124130
$scope.emptyStateConfig = {
125131
icon: 'pficon-warning-triangle-o',
126132
title: 'No Items Available',
@@ -132,6 +138,30 @@
132138
}
133139
};
134140
141+
$scope.emptyStateActionButtons = [
142+
{
143+
name: 'Main Action',
144+
title: 'Perform an action',
145+
actionFn: performEmptyStateAction,
146+
type: 'main'
147+
},
148+
{
149+
name: 'Secondary Action 1',
150+
title: 'Perform an action',
151+
actionFn: performEmptyStateAction
152+
},
153+
{
154+
name: 'Secondary Action 2',
155+
title: 'Perform an action',
156+
actionFn: performEmptyStateAction
157+
},
158+
{
159+
name: 'Secondary Action 3',
160+
title: 'Perform an action',
161+
actionFn: performEmptyStateAction
162+
}
163+
];
164+
135165
function handleCheckBoxChange (item) {
136166
$scope.eventText = item.name + ' checked: ' + item.selected + '\r\n' + $scope.eventText;
137167
};

src/table/tableview/examples/table-view-with-toolbar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* <li>.actionFn - (function(action)) Function to invoke when the action selected
4444
* </ul>
4545
* @param {object} emptyStateConfig Optional configuration settings for the empty state component. See the {@link patternfly.views.component:pfEmptyState Empty State} component
46+
* @param {array} emptyStateActionButtons Optional buttons to display under the icon, title, and informational paragraph. See the {@link patternfly.views.component:pfEmptyState Empty State} component
4647
* @example
4748
<example module="patternfly.tableview.demo">
4849
<file name="index.html">

src/table/tableview/table-view.component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ angular.module('patternfly.table').component('pfTableView', {
77
items: '<',
88
actionButtons: '<?',
99
menuActions: '<?',
10-
emptyStateConfig: '=?'
10+
emptyStateConfig: '=?',
11+
emptyStateActionButtons: '=?'
1112
},
1213
templateUrl: 'table/tableview/table-view.html',
1314
controller: function (DTOptionsBuilder, DTColumnDefBuilder, $element, pfUtils, $log, $filter, $timeout) {

src/table/tableview/table-view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@
5454
</tr>
5555
</tbody>
5656
</table>
57-
<pf-empty-state ng-if="$ctrl.config.itemsAvailable === false" config="$ctrl.emptyStateConfig"></pf-empty-state>
57+
<pf-empty-state ng-if="$ctrl.config.itemsAvailable === false" config="$ctrl.emptyStateConfig" action-buttons="$ctrl.emptyStateActionButtons"></pf-empty-state>
5858
</div>

src/views/cardview/card-view.component.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* <li>.itemsAvailable - (boolean) If 'false', displays the {@link patternfly.views.component:pfEmptyState Empty State} component.
2525
* </ul>
2626
* @param {object} emptyStateConfig Optional configuration settings for the empty state component. See the {@link patternfly.views.component:pfEmptyState Empty State} component
27+
* @param {array} emptyStateActionButtons Optional buttons to display under the icon, title, and informational paragraph in the empty state component. See the {@link patternfly.views.component:pfEmptyState Empty State} component
2728
* @param {Array} items the data to be shown in the cards<br/>
2829
*
2930
* @example
@@ -41,7 +42,7 @@
4142
</style>
4243
<div ng-controller="ViewCtrl" class="row" style="display:inline-block; width: 100%;">
4344
<div class="col-md-12">
44-
<pf-card-view id="exampleCardView" config="config" empty-state-config="emptyStateConfig" items="items">
45+
<pf-card-view id="exampleCardView" config="config" empty-state-config="emptyStateConfig" items="items" empty-state-action-buttons="emptyStateActionButtons">
4546
<div class="col-md-12">
4647
<span>{{item.name}}</span>
4748
</div>
@@ -193,6 +194,10 @@
193194
},
194195
]
195196
197+
var performEmptyStateAction = function (action) {
198+
$scope.eventText = action.name + "\r\n" + $scope.eventText;
199+
};
200+
196201
$scope.emptyStateConfig = {
197202
icon: 'pficon-warning-triangle-o',
198203
title: 'No Items Available',
@@ -203,6 +208,30 @@
203208
url : '#/api/patternfly.views.component:pfEmptyState'
204209
}
205210
};
211+
212+
$scope.emptyStateActionButtons = [
213+
{
214+
name: 'Main Action',
215+
title: 'Perform an action',
216+
actionFn: performEmptyStateAction,
217+
type: 'main'
218+
},
219+
{
220+
name: 'Secondary Action 1',
221+
title: 'Perform an action',
222+
actionFn: performEmptyStateAction
223+
},
224+
{
225+
name: 'Secondary Action 2',
226+
title: 'Perform an action',
227+
actionFn: performEmptyStateAction
228+
},
229+
{
230+
name: 'Secondary Action 3',
231+
title: 'Perform an action',
232+
actionFn: performEmptyStateAction
233+
}
234+
];
206235
}
207236
]);
208237
</file>
@@ -212,6 +241,7 @@ angular.module('patternfly.views').component('pfCardView', {
212241
bindings: {
213242
config: '=?',
214243
emptyStateConfig: '=?',
244+
emptyStateActionButtons: '=?',
215245
items: '=',
216246
eventId: '@id'
217247
},

src/views/cardview/card-view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
</div>
1313
</div>
1414
</div>
15-
<pf-empty-state ng-if="$ctrl.config.itemsAvailable === false" config="$ctrl.emptyStateConfig"></pf-empty-state>
15+
<pf-empty-state ng-if="$ctrl.config.itemsAvailable === false" config="$ctrl.emptyStateConfig" action-buttons="$ctrl.emptyStateActionButtons"></pf-empty-state>
1616
</span>

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
* @param {function (action, item))} updateMenuActionForItemFn function(action, item) Used to update a menu action based on the current item
5959
* @param {object} customScope Object containing any variables/functions used by the transcluded html, access via $ctrl.customScope.<xxx>
6060
* @param {object} emptyStateConfig Optional configuration settings for the empty state component. See the {@link patternfly.views.component:pfEmptyState Empty State} component
61+
* @param {array} emptyStateActionButtons Optional buttons to display under the icon, title, and informational paragraph in the empty state component. See the {@link patternfly.views.component:pfEmptyState Empty State} component
6162
* @example
6263
<example module="patternfly.views" deps="patternfly.utils">
6364
<file name="index.html">
@@ -93,7 +94,8 @@
9394
menu-actions="menuActions"
9495
update-menu-action-for-item-fn="updateMenuActionForItemFn"
9596
menu-class-for-item-fn="getMenuClass"
96-
hide-menu-for-item-fn="hideMenuActions">
97+
hide-menu-for-item-fn="hideMenuActions"
98+
empty-state-action-buttons="emptyStateActionButtons">
9799
<div class="list-view-pf-description">
98100
<div class="list-group-item-heading">
99101
{{item.name}}
@@ -307,6 +309,10 @@
307309
onDblClick: handleDblClick
308310
};
309311
312+
var performEmptyStateAction = function (action) {
313+
$scope.eventText = action.name + "\r\n" + $scope.eventText;
314+
};
315+
310316
$scope.emptyStateConfig = {
311317
icon: 'pficon-warning-triangle-o',
312318
title: 'No Items Available',
@@ -318,6 +324,30 @@
318324
}
319325
};
320326
327+
$scope.emptyStateActionButtons = [
328+
{
329+
name: 'Main Action',
330+
title: 'Perform an action',
331+
actionFn: performEmptyStateAction,
332+
type: 'main'
333+
},
334+
{
335+
name: 'Secondary Action 1',
336+
title: 'Perform an action',
337+
actionFn: performEmptyStateAction
338+
},
339+
{
340+
name: 'Secondary Action 2',
341+
title: 'Perform an action',
342+
actionFn: performEmptyStateAction
343+
},
344+
{
345+
name: 'Secondary Action 3',
346+
title: 'Perform an action',
347+
actionFn: performEmptyStateAction
348+
}
349+
];
350+
321351
$scope.items = [
322352
{
323353
name: "Fred Flintstone",
@@ -534,7 +564,7 @@
534564
</div>
535565
</div>
536566
</file>
537-
<file name="counpund.js">
567+
<file name="compound.js">
538568
angular.module('patternfly.views').controller('CompoundExanspansionCtrl', ['$scope', '$templateCache',
539569
function ($scope, $templateCache) {
540570
$scope.eventText = '';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ angular.module('patternfly.views').component('pfListView', {
1111
actions: '=?',
1212
updateActionForItemFn: '=?',
1313
customScope: '=?',
14-
emptyStateConfig: '=?'
14+
emptyStateConfig: '=?',
15+
emptyStateActionButtons: '=?'
1516
},
1617
transclude: {
1718
expandedContent: '?listExpandedContent'

src/views/listview/list-view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@
6666
</div>
6767
</div>
6868
</div>
69-
<pf-empty-state ng-if="$ctrl.config.itemsAvailable === false" config="$ctrl.emptyStateConfig"></pf-empty-state>
69+
<pf-empty-state ng-if="$ctrl.config.itemsAvailable === false" config="$ctrl.emptyStateConfig" action-buttons="$ctrl.emptyStateActionButtons"></pf-empty-state>
7070
</span>

0 commit comments

Comments
 (0)