Skip to content

Commit 842ab1c

Browse files
committed
Addressed review issues
1 parent 09a981e commit 842ab1c

File tree

6 files changed

+28
-32
lines changed

6 files changed

+28
-32
lines changed

src/filters/examples/filter-panel.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*
66
* @description
77
* The Filter Panel is opened and closed by clicking on the Filter button. It can contain any HTML desired by
8-
* the end user. As such, the end user is repsonsible for constructing the <code>appliedFilters</code> array which is passed to
8+
* the application developer. As such, the application developer is repsonsible for constructing the <code>appliedFilters</code> array which is passed to
99
* the filter results tags.
10-
* The end user is responsible for filtering items based on the <code>appliedFilters</code> array; both when a
10+
* The application developer is responsible for filtering items based on the <code>appliedFilters</code> array; both when a
1111
* filter is changed on the panel, or when a filter tag is 'cleared' (by user clicking on 'x' in the filter results tag).
1212
* <br>
1313
*
@@ -245,12 +245,12 @@
245245
246246
var applyFilters = function () {
247247
var newAppliedFilters = [];
248-
$scope.filterPanelModel.forEach(function (filter) {
248+
_.forEach($scope.filterPanelModel, function(filter) {
249249
var filterValues = [];
250250
if (angular.isDefined(filter.values) && filter.values.length > 0) {
251251
if(filter.filterType === "checkbox") {
252252
// the values of the selected checkboxes are stored in a single new appliedFilter
253-
filter.values.forEach(function (value) {
253+
_.forEach(filter.values, function(value) {
254254
if(value.selected) {
255255
filterValues.push(value.value)
256256
}
@@ -260,7 +260,7 @@
260260
}
261261
} else {
262262
// each keyword value gets a new appliedFilter
263-
filter.values.forEach(function (value) {
263+
_.forEach(filter.values, function(value) {
264264
filterValues = [value];
265265
newAppliedFilters.push( createAppliedFilter (filter, filterValues) );
266266
});
@@ -294,7 +294,7 @@
294294
};
295295
296296
var resetFilterPanelModel = function () {
297-
$scope.filterPanelModel.forEach(function (filter) {
297+
_.forEach($scope.filterPanelModel, function(filter) {
298298
if (angular.isDefined(filter.values) && filter.values.length > 0) {
299299
if(filter.filterType === "checkbox") {
300300
// unselect all checkboxes
@@ -306,13 +306,13 @@
306306
filter.values = [];
307307
}
308308
}
309-
});
309+
});
310310
};
311311
312312
var filterItems = function (filters) {
313313
$scope.items = [];
314314
if (filters && filters.length > 0) {
315-
$scope.allItems.forEach(function (item) {
315+
_.forEach($scope.allItems, function(item) {
316316
if (matchesFilters(item, filters)) {
317317
$scope.items.push(item);
318318
}

src/filters/filter-panel/filter-panel-results-component.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ angular.module('patternfly.filters').component('pfFilterPanelResults', {
6767
}
6868
}
6969

70-
function clearFilter (filterIndex, valueIndex) {
71-
var changedFilterId = ctrl.config.appliedFilters[filterIndex].id;
70+
function clearFilter (filter, value) {
71+
var changedFilterId = filter.id;
7272

73-
var changedFilterValue = _.pullAt(ctrl.config.appliedFilters[filterIndex].values, valueIndex);
73+
var changedFilterValue = _.pull(filter.values, value)[0];
7474

75-
if (ctrl.config.appliedFilters[filterIndex].values.length === 0) {
76-
_.pullAt(ctrl.config.appliedFilters, filterIndex);
75+
if (filter.values.length === 0) {
76+
_.pull(ctrl.config.appliedFilters, filter);
7777
}
7878

7979
if (ctrl.config.onFilterChange) {

src/filters/filter-panel/filter-panel-results.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
<span class="toolbar-pf-results">
33
<h5>
44
{{$ctrl.config.resultsCount}}
5-
<span ng-if="$ctrl.config.appliedFilters.length > 0"> of {{$ctrl.config.totalCount}}</span>
5+
<span ng-if="$ctrl.config.appliedFilters.length"> of {{$ctrl.config.totalCount}}</span>
66
{{$ctrl.config.resultsLabel === undefined ? "Results" : $ctrl.config.resultsLabel}}
77
</h5>
8-
<p ng-if="$ctrl.config.appliedFilters.length > 0">Active filters:</p>
8+
<p ng-if="$ctrl.config.appliedFilters.length">Active filters:</p>
99
<ul class="list-inline">
1010
<li ng-repeat="filter in $ctrl.config.appliedFilters">
1111
<span ng-if="filter.values.length === 1" class="active-filter label label-info single-label">
12-
<span class="label-category">{{filter.title}}:</span> {{filter.values[0]}}
13-
<a><span ng-click="$ctrl.clearFilter($index, 0)" class="pficon pficon-close"></span></a>
12+
<span class="pf-filter-label-category">{{filter.title}}:</span> {{filter.values[0]}}
13+
<a><span ng-click="$ctrl.clearFilter(filter, filter.values[0])" class="pficon pficon-close"></span></a>
1414
</span>
15-
<span ng-if="filter.values.length > 1" class="active-filter label label-category">
15+
<span ng-if="filter.values.length > 1" class="active-filter label pf-filter-label-category">
1616
{{filter.title}}:
1717
<ul class="list-inline category-values">
1818
<li ng-repeat="value in filter.values">
1919
<span class="active-filter label label-info">{{value}}
20-
<a><span ng-click="$ctrl.clearFilter($parent.$index, $index)" class="pficon pficon-close"></span></a>
20+
<a><span ng-click="$ctrl.clearFilter(filter, value)" class="pficon pficon-close"></span></a>
2121
</span>
2222
</li>
2323
</ul>

src/filters/filters.less

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,25 @@ pf-filter-panel {
5353
font-weight: 400;
5454

5555
.category-option-label {
56-
vertical-align: text-bottom;
5756
font-size: 12px;
57+
vertical-align: text-bottom;
5858
}
5959
}
6060
}
6161
.list-inline > li {
62-
padding-right: 0px;
63-
@media(max-width: @screen-md-min) {
64-
margin-bottom: 3px;
65-
}
62+
padding-right: 0;
6663
}
6764
.toolbar-pf-results {
6865
border-top: none;
6966
margin-left: 10px;
7067
vertical-align: middle;
7168
.single-label {
7269
padding: 6px;
73-
.label-category {
70+
.pf-filter-label-category {
7471
background-color: @color-pf-blue-500;
7572
font-weight: 700;
7673
padding-right: 2px;
77-
padding-left: 0px;
74+
padding-left: 0;
7875
}
7976
.pficon-close {
8077
padding-right: 6px;
@@ -87,7 +84,7 @@ pf-filter-panel {
8784
}
8885
}
8986

90-
.label-category {
87+
.pf-filter-label-category {
9188
background-color: @color-pf-blue-300;
9289
font-weight: 700;
9390
padding: 6px;

styles/angular-patternfly.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@import "../node_modules/patternfly/dist/less/color-variables.less";
2-
@import "../node_modules/patternfly/node_modules/bootstrap/less/variables.less";
32
@import "misc.less";
43
@import "../src/card/card.less";
54
@import "../src/charts/charts.less";

test/filters/filter-panel.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('Directive: pfFilterPanel', function () {
9292
init();
9393

9494
// [cateogry: [value 1 x] [value 2 x] ]
95-
var categoryTags = element.find('.label-category')
95+
var categoryTags = element.find('.pf-filter-label-category')
9696
var tagOne = angular.element(categoryTags[0]).text();
9797
var tagOneValue = angular.element(element.find('.single-label')).text();
9898
var tagTwo = angular.element(categoryTags[1]).text();
@@ -125,7 +125,7 @@ describe('Directive: pfFilterPanel', function () {
125125
init();
126126

127127
// Filter Tag = [cateogry: [value 1 x] [value 2 x] ...]
128-
var categoryTags = element.find('.label-category');
128+
var categoryTags = element.find('.pf-filter-label-category');
129129
expect(categoryTags.length).toBe(2);
130130

131131
var clearFilterLinks = element.find('.pficon-close');
@@ -135,7 +135,7 @@ describe('Directive: pfFilterPanel', function () {
135135
eventFire(clearFilterLinks[0], 'click');
136136
$scope.$digest();
137137

138-
categoryTags = element.find('.active-filter.label.label-category');
138+
categoryTags = element.find('.active-filter.label.pf-filter-label-category');
139139
expect(categoryTags.length).toBe(1);
140140

141141
// Clear one of the Category One filters
@@ -157,7 +157,7 @@ describe('Directive: pfFilterPanel', function () {
157157
eventFire(clearAll[0], 'click');
158158
$scope.$digest();
159159

160-
categoryTags = element.find('.active-filter.label.label-category');
160+
categoryTags = element.find('.active-filter.label.pf-filter-label-category');
161161
expect(categoryTags.length).toBe(0);
162162
});
163163
});

0 commit comments

Comments
 (0)