Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(component): filter list items by search term
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexpeschel committed Dec 14, 2017
1 parent e8fb279 commit aa08895
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/component/container/pattern_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@ export class PatternList extends React.Component<PatternListProps> {
this.handleDragStart = this.handleDragStart.bind(this);
}

public search(listItem: ListItemProps[], term: string): ListItemProps[] {
const result: ListItemProps[] = [];

listItem.map(item => {
if (item.value.indexOf(term) !== -1 && !item.children) {
result.push(item);
} else if (item.children) {
const folder = { value: item.value, children: [] };
result.push(folder, ...this.search(item.children, term));
}
});
return result;
}

public render(): JSX.Element {
if (this.props.store.getPatternSearchTerm() === '') {
this.items = this.createItemsFromFolder(
this.props.store.getPatternRoot() as PatternFolder
);
} else {
this.items = this.props.store
.searchPatterns(this.props.store.getPatternSearchTerm())
.map(pattern => ({ value: pattern.getId() }));
this.items = this.createItemsFromFolder(this.props.store.getPatternRoot() as PatternFolder);
if (this.props.store.getPatternSearchTerm() !== '') {
this.items = this.search(this.items, this.props.store.getPatternSearchTerm());
}
const list = this.createList(this.items);
return (
Expand Down

0 comments on commit aa08895

Please sign in to comment.