Skip to content

Commit

Permalink
Merge 3740bb8 into 2db0eed
Browse files Browse the repository at this point in the history
  • Loading branch information
diogofcunha authored Apr 13, 2020
2 parents 2db0eed + 3740bb8 commit 85846d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface FilteringContainerProps {
selectedGroup?: string;
groupRenderer?: React.StatelessComponent<GroupRendererProps> | React.Component<GroupRendererProps>;
onSelectedGroupChange?: (c: string) => void;
indexSearch: (searchTerm: string, nodes: FlattenedNode[]) => (node: FlattenedNode) => boolean;
}

export class FilteringContainer extends React.Component<FilteringContainerProps> {}
Expand Down
7 changes: 5 additions & 2 deletions src/FilteringContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DefaultGroupRenderer from './filtering/DefaultGroupRenderer';
import {Node} from './shapes/nodeShapes';
import {filterNodes} from './selectors/filtering';

const nameMatchesSearchTerm = searchTerm => ({name}) => {
const indexByName = searchTerm => ({name}) => {
const upperCaseName = name.toUpperCase();
const upperCaseSearchTerm = searchTerm.toUpperCase();

Expand All @@ -31,6 +31,7 @@ export default class FilteringContainer extends React.Component {
static defaultProps = {
debouncer: debounce,
groupRenderer: DefaultGroupRenderer,
indexSearch: indexByName,
};

constructor(props) {
Expand Down Expand Up @@ -60,6 +61,7 @@ export default class FilteringContainer extends React.Component {
selectedGroup,
groupRenderer: GroupRenderer,
onSelectedGroupChange,
indexSearch,
} = this.props;

const relevantNodes =
Expand All @@ -68,7 +70,7 @@ export default class FilteringContainer extends React.Component {
: {nodes, nodeParentMappings: {}};

const {nodes: filteredNodes, nodeParentMappings} = filterTerm
? filterNodes(nameMatchesSearchTerm(filterTerm), relevantNodes.nodes)
? filterNodes(indexSearch(filterTerm, relevantNodes.nodes), relevantNodes.nodes)
: relevantNodes;

return (
Expand All @@ -91,4 +93,5 @@ FilteringContainer.propTypes = {
selectedGroup: PropTypes.string,
groupRenderer: PropTypes.func,
onSelectedGroupChange: PropTypes.func,
indexSearch: PropTypes.func,
};

0 comments on commit 85846d0

Please sign in to comment.