Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit e71e09a

Browse files
committed
Merge pull request #7975 from adobe/rlim/empty-filter-set
Don't add empty filter sets to the file filter dropdown list.
2 parents faafbda + a38e514 commit e71e09a

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

src/search/FileFilters.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ define(function (require, exports, module) {
5454
/** @type {DropdownButton} */
5555
var _picker = null;
5656

57+
/**
58+
* Get the condensed form of the filter set by joining the first two in the set with
59+
* a comma separator and appending a short message with the number of filters being clipped.
60+
* @param {Array.<string>} filter
61+
* @return {string} Condensed form of filter set if `filter` is a valid array.
62+
* Otherwise, return an empty string.
63+
*/
64+
function _getCondensedForm(filter) {
65+
if (!_.isArray(filter)) {
66+
return "";
67+
}
68+
69+
// Format filter in condensed form
70+
if (filter.length > 2) {
71+
return filter.slice(0, 2).join(", ") + " " +
72+
StringUtils.format(Strings.FILE_FILTER_CLIPPED_SUFFIX, filter.length - 2);
73+
}
74+
return filter.join(", ");
75+
}
76+
5777
/**
5878
* Populate the list of dropdown menu with two filter commands and
5979
* the list of saved filter sets.
@@ -64,6 +84,12 @@ define(function (require, exports, module) {
6484

6585
if (filterSets.length) {
6686
dropdownItems.push("---");
87+
88+
// Remove all the empty exclusion sets before concatenating to the dropdownItems.
89+
filterSets = filterSets.filter(function (filter) {
90+
return (_getCondensedForm(filter.patterns) !== "");
91+
});
92+
6793
// FIRST_FILTER_INDEX needs to stay in sync with the number of static items (plus separator)
6894
// ie. the number of items populated so far before we concatenate with the actual filter sets.
6995
dropdownItems = dropdownItems.concat(filterSets);
@@ -74,7 +100,7 @@ define(function (require, exports, module) {
74100
/**
75101
* Find the index of a filter set in the list of saved filter sets.
76102
* @param {Array.<{name: string, patterns: Array.<string>}>} filterSets
77-
* @param {{name: string, patterns: Array.<string>}} filter
103+
* @return {{name: string, patterns: Array.<string>}} filter
78104
*/
79105
function _getFilterIndex(filterSets, filter) {
80106
var index = -1,
@@ -116,22 +142,6 @@ define(function (require, exports, module) {
116142
return activeFilter;
117143
}
118144

119-
/**
120-
* Get the condensed form of the filter set by joining the first two in the set with
121-
* a comma separator and appending a short message with the number of filters being clipped.
122-
* @param {Array.<string>} filter
123-
* @param {string} condensed form of filter set
124-
*/
125-
function _getCondensedForm(filter) {
126-
// Format filter in condensed form
127-
if (filter.length > 2) {
128-
return filter.slice(0, 2).join(", ") + " " +
129-
StringUtils.format(Strings.FILE_FILTER_CLIPPED_SUFFIX, filter.length - 2);
130-
} else {
131-
return filter.join(", ");
132-
}
133-
}
134-
135145
/**
136146
* Update the picker button label with the name/patterns of the selected filter or
137147
* No Files Excluded if no filter is selected.

0 commit comments

Comments
 (0)