Skip to content

Commit 4d2c0ac

Browse files
ronlavi2412jeff-phillips-18
authored andcommitted
fix(DualList): Distinguish between default hidden item to hidden by filterItems that were defaultly set to hidden, shouldn't be modified by the components filter. (#1911)
1 parent b409e6d commit 4d2c0ac

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

packages/patternfly-3/patternfly-react/src/components/DualListSelector/DualList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
isItemExistOnList,
1919
filterByHiding,
2020
getFilterredItemsLength,
21-
makeAllItemsVisible,
21+
makeAllHiddenFilteredItemsVisible,
2222
getSelectedFilterredItemsLength,
2323
isItemSelected,
2424
getFilterredItems
@@ -129,7 +129,7 @@ class DualList extends React.Component {
129129
} = this.props;
130130
const filterTerm = value.trim();
131131
if (!value) {
132-
const items = makeAllItemsVisible(originalItems);
132+
const items = makeAllHiddenFilteredItemsVisible(originalItems);
133133
const isMainChecked = isAllItemsChecked(items, selectCount);
134134
this.props.onFilterChange({ side, filterTerm, items, isMainChecked });
135135
return;

packages/patternfly-3/patternfly-react/src/components/DualListSelector/components/DualListItem.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const DualListItem = ({
1818
onChange,
1919
side,
2020
hidden,
21+
hiddenByFilter,
2122
disabled,
2223
tooltipID,
2324
tooltipText
@@ -29,7 +30,7 @@ const DualListItem = ({
2930
</span>
3031
);
3132
const item = (
32-
<label className={cx} hidden={hidden}>
33+
<label className={cx} hidden={hiddenByFilter || hidden}>
3334
<input
3435
type="checkbox"
3536
data-position={position}
@@ -80,6 +81,8 @@ DualListItem.propTypes = {
8081
/** The side of the selector. */
8182
side: PropTypes.string,
8283
/** Sets the item visibillity when filtering. */
84+
hiddenByFilter: PropTypes.bool,
85+
/** Sets the item default visibillity, can't be reverted. */
8386
hidden: PropTypes.bool,
8487
/** Disable the item to move between lists */
8588
disabled: PropTypes.bool,
@@ -99,6 +102,7 @@ DualListItem.defaultProps = {
99102
filterTerm: null,
100103
onChange: noop,
101104
side: null,
105+
hiddenByFilter: false,
102106
hidden: false,
103107
disabled: false,
104108
tooltipID: null,

packages/patternfly-3/patternfly-react/src/components/DualListSelector/helpers.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,33 @@ export const filterByHiding = (list, value) => {
44
const itemLabel = item.label.toLowerCase();
55
const included = itemLabel.includes(filterValue);
66
// if the item label matches the filter value.
7-
item.hidden = !included;
7+
item.hiddenByFilter = !included;
88
// if it is a parent and its label doesn't match the filter value.
99
if (itemHasChildren(item)) {
10-
if (isItemHidden(item)) {
10+
if (isItemHiddenByFilter(item)) {
1111
let childrenIncludedAmount = 0;
1212
item.children.forEach(childItem => {
1313
const childLabel = childItem.label.toLowerCase();
1414
const childIncluded = childLabel.includes(filterValue);
15-
childItem.hidden = !childIncluded;
15+
childItem.hiddenByFilter = !childIncluded;
1616
childrenIncludedAmount += childIncluded ? 1 : 0;
1717
});
18-
item.hidden = childrenIncludedAmount === 0;
18+
item.hiddenByFilter = childrenIncludedAmount === 0;
1919
} else {
20-
item.children = makeAllItemsVisible(item.children);
20+
item.children = makeAllHiddenFilteredItemsVisible(item.children);
2121
}
2222
}
2323
return item;
2424
});
2525
};
2626

27-
export const makeAllItemsVisible = list =>
27+
// We don't want to touch default hidden items that the consumer set to hidden.
28+
export const makeAllHiddenFilteredItemsVisible = list =>
2829
list.map(item => {
29-
item.hidden = false;
30+
item.hiddenByFilter = false;
3031
if (itemHasChildren(item)) {
3132
item.children.forEach(childItem => {
32-
childItem.hidden = false;
33+
childItem.hiddenByFilter = false;
3334
});
3435
}
3536
return item;
@@ -40,7 +41,7 @@ export const sortItems = (items, sortFactor = 'label') =>
4041

4142
export const shouldItemBeChecked = (item, isMainChecked, resetAllSelected) => {
4243
let checked = item.checked || false;
43-
const isItemEditable = !item.disabled || !item.hidden;
44+
const isItemEditable = !item.disabled || !item.hidden || !item.isItemHiddenByFilter;
4445
if (!isItemEditable) {
4546
return checked;
4647
}
@@ -210,12 +211,12 @@ export const isItemExistOnList = (list, itemLabel) => {
210211
export const getFilterredItems = list => {
211212
const filteredItems = [];
212213
list.forEach(item => {
213-
if (!isItemHidden(item)) {
214+
if (!isItemHiddenByFilter(item)) {
214215
filteredItems.push(item);
215216
} else if (itemHasChildren(item)) {
216217
const filteredChildren = [];
217218
item.children.forEach(childItem => {
218-
if (!isItemHidden(childItem)) {
219+
if (!isItemHiddenByFilter(childItem)) {
219220
filteredChildren.push(childItem);
220221
}
221222
});
@@ -254,6 +255,6 @@ export const getSelectedFilterredItemsLength = list => {
254255

255256
export const isItemSelected = item => item.checked;
256257

257-
export const isItemHidden = item => item.hidden;
258+
export const isItemHiddenByFilter = item => item.hiddenByFilter;
258259

259260
export const isItemDisabled = item => item.disabled;

0 commit comments

Comments
 (0)