Skip to content

Commit

Permalink
feat: 馃幐 added search indexing (#123)
Browse files Browse the repository at this point in the history
this will allow consumers to specify a custom indexer that will allow
them to be in full control over the rendering pipeline
  • Loading branch information
diogofcunha committed Apr 13, 2020
1 parent 2db0eed commit 798c873
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 798c873

Please sign in to comment.