From bb2771539d588d22190fec8983469d30ae152583 Mon Sep 17 00:00:00 2001 From: Allen Wight Date: Wed, 23 Aug 2017 10:09:50 -0400 Subject: [PATCH] fix(pfFilter): Ensures complete alias support for select/complex-select --- src/filters/examples/filter.js | 18 +++++++++++---- src/filters/simple-filter/filter-component.js | 14 ++++------- .../simple-filter/filter-fields-component.js | 8 +++++-- src/filters/simple-filter/filter-fields.html | 23 ++++++++++--------- src/filters/simple-filter/filter-results.html | 2 +- 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/filters/examples/filter.js b/src/filters/examples/filter.js index 743c6e84e..aca2a8cf3 100644 --- a/src/filters/examples/filter.js +++ b/src/filters/examples/filter.js @@ -14,7 +14,7 @@ *
  • .id - (String) Optional unique Id for the filter field, useful for comparisons *
  • .title - (String) The title to display for the filter field *
  • .placeholder - (String) Text to display when no filter value has been entered - *
  • .filterMultiselect - (Boolean) In `complex-select`, allow selection of multiple values per category. Optional, default is `false` + *
  • .filterMultiselect - (Boolean) In `complex-select`, allow selection of multiple categories and values. Optional, default is `false` *
  • .filterType - (String) The filter input field type (any html input type, or 'select' for a single select box or 'complex-select' for a category select box) *
  • .filterValues - (Array) List of valid select values used when filterType is 'select' or 'complex-select' (in where these values serve as case insensitve keys for .filterCategories objects) *
  • .filterCategories - (Array of (Objects)) For 'complex-select' only, array of objects whoes keys (case insensitive) match the .filterValues, these objects include each of the filter fields above (sans .placeholder) @@ -114,9 +114,10 @@ } else if (filter.id === 'address') { match = item.address.match(re) !== null; } else if (filter.id === 'birthMonth') { - match = item.birthMonth === filter.value; + match = item.birthMonth === filter.value.id || item.birthMonth === filter.value; } else if (filter.id === 'car') { - match = item.car === filter.value; + match = item.car === ((filter.value.filterCategory.id || filter.value.filterCategory) + + filter.value.filterDelimiter + (filter.value.filterValue.id || filter.value.filterValue)); } return match; }; @@ -150,7 +151,16 @@ var filterChange = function (filters) { $scope.filtersText = ""; filters.forEach(function (filter) { - $scope.filtersText += filter.title + " : " + filter.value + "\n"; + $scope.filtersText += filter.title + " : "; + if (filter.value.filterCategory) { + $scope.filtersText += ((filter.value.filterCategory.title || filter.value.filterCategory) + + filter.value.filterDelimiter + (filter.value.filterValue.title || filter.value.filterValue)); + } else if (filter.value.title){ + $scope.filtersText += filter.value.title; + } else { + $scope.filtersText += filter.value; + } + $scope.filtersText += "\n"; }); applyFilters(filters); }; diff --git a/src/filters/simple-filter/filter-component.js b/src/filters/simple-filter/filter-component.js index 647ba18d6..e460dcfc9 100644 --- a/src/filters/simple-filter/filter-component.js +++ b/src/filters/simple-filter/filter-component.js @@ -21,14 +21,8 @@ angular.module('patternfly.filters').component('pfFilter', { return angular.isDefined(_.find(ctrl.config.appliedFilters, {title: filter.title, value: filter.value})); } - function findDuplicateCategory (field, value) { - var duplicateValue; - - function searchAppliedFilters (item) { - return _.includes(item.value, _.split(value, field.filterDelimiter, 1)) ? duplicateValue = item : null; - } - - return _.some(ctrl.config.appliedFilters, searchAppliedFilters) ? duplicateValue : null; + function findDuplicateComplexSelect (item) { + return item.value.filterCategory; } function enforceSingleSelect (filter) { @@ -49,8 +43,8 @@ angular.module('patternfly.filters').component('pfFilter', { enforceSingleSelect(newFilter); } - if (field.filterType === 'complex-select' && !field.filterMultiselect && findDuplicateCategory(field, value)) { - _.remove(ctrl.config.appliedFilters, findDuplicateCategory(field, value)); + if (field.filterType === 'complex-select' && !field.filterMultiselect) { + _.remove(ctrl.config.appliedFilters, findDuplicateComplexSelect); } ctrl.config.appliedFilters.push(newFilter); diff --git a/src/filters/simple-filter/filter-fields-component.js b/src/filters/simple-filter/filter-fields-component.js index 5a5c3bde6..25f1f78c1 100644 --- a/src/filters/simple-filter/filter-fields-component.js +++ b/src/filters/simple-filter/filter-fields-component.js @@ -14,7 +14,7 @@ *
  • .id - (String) Optional unique Id for the filter field, useful for comparisons *
  • .title - (String) The title to display for the filter field *
  • .placeholder - (String) Text to display when no filter value has been entered - *
  • .filterMultiselect - (Boolean) In `complex-select`, allow selection of multiple values per category. Optional, default is `false` + *
  • .filterMultiselect - (Boolean) In `complex-select`, allow selection of multiple categories and values. Optional, default is `false` *
  • .filterType - (String) The filter input field type (any html input type, or 'select' for a single select box or 'complex-select' for a category select box) *
  • .filterValues - (Array) List of valid select values used when filterType is 'select' or 'complex-select' (in where these values serve as case insensitve keys for .filterCategories objects) *
  • .filterCategories - (Array of (Objects)) For 'complex-select' only, array of objects whoes keys (case insensitive) match the .filterValues, these objects include each of the filter fields above (sans .placeholder) @@ -75,7 +75,11 @@ angular.module('patternfly.filters').component('pfFilterFields', { break; } if (ctrl.filterCategory && ctrl.filterValue) { - ctrl.addFilterFn(ctrl.currentField, ctrl.filterCategory + ctrl.currentField.filterDelimiter + ctrl.filterValue); + ctrl.addFilterFn(ctrl.currentField, { + filterCategory: ctrl.filterCategory, + filterDelimiter: ctrl.currentField.filterDelimiter, + filterValue: ctrl.filterValue + }); } } else { ctrl.addFilterFn(ctrl.currentField, filterValue); diff --git a/src/filters/simple-filter/filter-fields.html b/src/filters/simple-filter/filter-fields.html index 471c9df98..7e9dd9860 100644 --- a/src/filters/simple-filter/filter-fields.html +++ b/src/filters/simple-filter/filter-fields.html @@ -7,7 +7,8 @@