Skip to content

Commit

Permalink
fix: cleanup, changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
jonno85 committed Jun 30, 2022
1 parent b8d4660 commit 682b283
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Added
- Selected entries shows associtated icons

## 0.9.1 - 2022-01-09

### Fixed
Expand Down
2 changes: 0 additions & 2 deletions lib/components/ItemIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const ItemIcon = ({ iconRenderer: Icon, icon, iconKey, itemIconStyle }) => {
source={icon}
style={[
{
// width: 32,
// height: 32,
marginHorizontal: 10
},
itemIconStyle
Expand Down
84 changes: 46 additions & 38 deletions lib/sectioned-multi-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -967,7 +973,8 @@ class SectionedMultiSelect extends PureComponent {
styles.chipContainer,
isParent && styles.parentChipContainer
]}
key={item[uniqueKey]}>
key={item[uniqueKey]}
>
<ItemIcon
iconRenderer={Icon}
iconKey={iconKey}
Expand Down Expand Up @@ -1090,8 +1097,8 @@ class SectionedMultiSelect extends PureComponent {
<View {...props} />
</Wrapper>
) : (
<View {...props} />
)
<View {...props} />
)
}

// _renderSubItemFlatList = ({ item }) => (
Expand Down Expand Up @@ -1228,30 +1235,30 @@ class SectionedMultiSelect extends PureComponent {
{loading ? (
callIfFunction(loadingComponent)
) : (
<View>
{!renderItems || (!renderItems.length && !searchTerm)
? callIfFunction(noItemsComponent)
: null}
{items && renderItems && renderItems.length ? (
<View>
<FlatList
keyboardShouldPersistTaps="always"
removeClippedSubviews
initialNumToRender={15}
data={renderItems}
extraData={selectedItems}
keyExtractor={(item) => `${item[uniqueKey]}`}
ItemSeparatorComponent={this._renderSeparator}
ListFooterComponent={this._renderFooter}
renderItem={this._renderItemFlatList}
{...itemsFlatListProps}
/>
</View>
) : searchTerm ? (
callIfFunction(noResultsComponent)
) : null}
</View>
)}
<View>
{!renderItems || (!renderItems.length && !searchTerm)
? callIfFunction(noItemsComponent)
: null}
{items && renderItems && renderItems.length ? (
<View>
<FlatList
keyboardShouldPersistTaps="always"
removeClippedSubviews
initialNumToRender={15}
data={renderItems}
extraData={selectedItems}
keyExtractor={(item) => `${item[uniqueKey]}`}
ItemSeparatorComponent={this._renderSeparator}
ListFooterComponent={this._renderFooter}
renderItem={this._renderItemFlatList}
{...itemsFlatListProps}
/>
</View>
) : searchTerm ? (
callIfFunction(noResultsComponent)
) : null}
</View>
)}
</View>
</View>
<View style={{ flexDirection: 'row' }}>
Expand Down Expand Up @@ -1338,7 +1345,8 @@ class SectionedMultiSelect extends PureComponent {
alignItems: 'center'
},
styles.selectToggle
]}>
]}
>
{this._getSelectIcon()}
{this._getSelectLabel()}
{callIfFunction(selectToggleIconComponent) || (
Expand Down

0 comments on commit 682b283

Please sign in to comment.