From 682b283720acfaed3e8808be70df86fe8b76ef9f Mon Sep 17 00:00:00 2001 From: Jonathan Filippini Date: Thu, 30 Jun 2022 12:21:31 +0200 Subject: [PATCH] fix: cleanup, changelog --- CHANGELOG.md | 3 ++ lib/components/ItemIcon.js | 2 - lib/sectioned-multi-select.js | 84 +++++++++++++++++++---------------- 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2d6f25..ee609c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### Added +- Selected entries shows associtated icons + ## 0.9.1 - 2022-01-09 ### Fixed diff --git a/lib/components/ItemIcon.js b/lib/components/ItemIcon.js index c94c9ad..2d6ff2b 100644 --- a/lib/components/ItemIcon.js +++ b/lib/components/ItemIcon.js @@ -9,8 +9,6 @@ const ItemIcon = ({ iconRenderer: Icon, icon, iconKey, itemIconStyle }) => { source={icon} style={[ { - // width: 32, - // height: 32, marginHorizontal: 10 }, itemIconStyle diff --git a/lib/sectioned-multi-select.js b/lib/sectioned-multi-select.js index b0ccae7..776e707 100644 --- a/lib/sectioned-multi-select.js +++ b/lib/sectioned-multi-select.js @@ -16,7 +16,6 @@ import { } from 'react-native' import isEqual from 'lodash.isequal' import memoize from 'memoize-one' -import { isEqual } from 'lodash' import { RowItem, ItemIcon } from './components' import { callIfFunction } from './helpers' @@ -376,22 +375,29 @@ class SectionedMultiSelect extends PureComponent { } _getSelectIcon = () => { - const { selectedItems, items, iconKey, iconRenderer: Icon, styles } = this.props + const { + selectedItems, + items, + iconKey, + iconRenderer: Icon, + styles + } = this.props - if (!selectedItems || selectedItems.length === 0) - return null + if (!selectedItems || selectedItems.length === 0) return null if (selectedItems.length === 1) { - const element = items.filter(e => e.id === selectedItems[0]) + const element = items.filter((e) => e.id === selectedItems[0]) let icon if (element.length === 1) { icon = element[0].icon } else { - const subElement = items.map(e => e.children).flat().filter(g => g !== undefined).filter(e2 => e2.id === selectedItems[0]) - if (subElement && subElement.length === 1) - icon = subElement[0].icon - else - return null + const subElement = items + .map((subElement1) => subElement1.children) + .flat() + .filter((entity) => entity !== undefined) + .filter((entity2) => entity2.id === selectedItems[0]) + if (subElement && subElement.length === 1) icon = subElement[0].icon + else return null } return ( @@ -967,7 +973,8 @@ class SectionedMultiSelect extends PureComponent { styles.chipContainer, isParent && styles.parentChipContainer ]} - key={item[uniqueKey]}> + key={item[uniqueKey]} + > ) : ( - - ) + + ) } // _renderSubItemFlatList = ({ item }) => ( @@ -1228,30 +1235,30 @@ class SectionedMultiSelect extends PureComponent { {loading ? ( callIfFunction(loadingComponent) ) : ( - - {!renderItems || (!renderItems.length && !searchTerm) - ? callIfFunction(noItemsComponent) - : null} - {items && renderItems && renderItems.length ? ( - - `${item[uniqueKey]}`} - ItemSeparatorComponent={this._renderSeparator} - ListFooterComponent={this._renderFooter} - renderItem={this._renderItemFlatList} - {...itemsFlatListProps} - /> - - ) : searchTerm ? ( - callIfFunction(noResultsComponent) - ) : null} - - )} + + {!renderItems || (!renderItems.length && !searchTerm) + ? callIfFunction(noItemsComponent) + : null} + {items && renderItems && renderItems.length ? ( + + `${item[uniqueKey]}`} + ItemSeparatorComponent={this._renderSeparator} + ListFooterComponent={this._renderFooter} + renderItem={this._renderItemFlatList} + {...itemsFlatListProps} + /> + + ) : searchTerm ? ( + callIfFunction(noResultsComponent) + ) : null} + + )} @@ -1338,7 +1345,8 @@ class SectionedMultiSelect extends PureComponent { alignItems: 'center' }, styles.selectToggle - ]}> + ]} + > {this._getSelectIcon()} {this._getSelectLabel()} {callIfFunction(selectToggleIconComponent) || (