Skip to content

Commit

Permalink
fix(DualList): refactor helpers functions signatures (patternfly#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronlavi2412 authored and dtaylor113 committed Jan 15, 2019
1 parent 52f2eca commit 378e44e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ class DualList extends React.Component {
[side]: { selectCount: originalSelectCount, items: originalItems, isSortAsc, filterTerm }
} = this.props;
const items = cloneDeep(originalItems);
const item = getItem({ isSortAsc, position, items, parentPosition });
const item = getItem(isSortAsc, items, position, parentPosition);
let selectCount = originalSelectCount;
item.checked = checked;
if (itemHasParent(item)) {
const parent = getItem({ isSortAsc, position: parentPosition, items });
const parent = getItem(isSortAsc, items, parentPosition);
parent.checked = isAllChildrenChecked(parent);
selectCount = getUpdatedSelectCount({ selectCount, checked });
selectCount = getUpdatedSelectCount(selectCount, checked);
} else if (itemHasChildren(item)) {
const { children } = item;
toggleAllItems(children, checked);
selectCount = getUpdatedSelectCount({ selectCount, checked, amount: children.length });
selectCount = getUpdatedSelectCount(selectCount, checked, children.length);
} else {
selectCount = getUpdatedSelectCount({ selectCount, checked });
selectCount = getUpdatedSelectCount(selectCount, checked);
}
let isMainChecked = false;
if (filterTerm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getDefaultProps = () => ({
isMainChecked: false
});

export const getCheckedAmount = ({ items }) => {
export const getCheckedAmount = items => {
let checkedAmount = 0;
items.forEach(item => {
if (isItemSelected(item)) {
Expand Down Expand Up @@ -117,19 +117,19 @@ export const adjustProps = ({ left, right, ...props }) => {
...defaultProps,
...left,
items: leftItems,
selectCount: getCheckedAmount({ ...left })
selectCount: getCheckedAmount(leftItems)
},
right: {
...defaultProps,
...right,
items: rightItems,
selectCount: getCheckedAmount({ ...right })
selectCount: getCheckedAmount(rightItems)
}
};
};

export const isAllChildrenChecked = ({ children }) =>
children.filter(({ checked }) => checked).length === children.length;
children && children.filter(({ checked }) => checked).length === children.length;

export const getItemsLength = items => {
let { length } = items;
Expand All @@ -150,7 +150,7 @@ export const reverseAllItemsOrder = items => {
return reversedItems.map(item => (item.children ? { ...item, children: item.children.reverse() } : item));
};

export const getItem = ({ isSortAsc, items, position, parentPosition }) => {
export const getItem = (isSortAsc, items, position, parentPosition) => {
// if item is a child.
if (parentPosition !== undefined) {
const parent = items[getItemPosition(items, parentPosition, isSortAsc)];
Expand All @@ -159,7 +159,7 @@ export const getItem = ({ isSortAsc, items, position, parentPosition }) => {
return items[getItemPosition(items, position, isSortAsc)];
};

export const getUpdatedSelectCount = ({ selectCount, checked, amount = 1 }) =>
export const getUpdatedSelectCount = (selectCount, checked, amount = 1) =>
selectCount + (checked ? amount : -1 * amount);

export const itemHasParent = item => item.parentPosition !== undefined;
Expand Down

0 comments on commit 378e44e

Please sign in to comment.