Skip to content

Commit

Permalink
Merge pull request #7 from iliyat/namespace-search
Browse files Browse the repository at this point in the history
search by namespace
  • Loading branch information
mikhail-eremin authored May 26, 2020
2 parents f6cfb08 + fa6bf08 commit b9da731
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ class Sidebar extends React.Component {
search: '',
};

filter(methods) {
filter(methods, namespace) {
const searchString = this.state.search.toLowerCase();
if (namespace && namespace.toLowerCase().indexOf(searchString) !== -1) {
return methods;
}
return reduce(methods, (res, value, key) => {
if (key.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) { res[key] = value; }
const combinedKey = [namespace, key].filter(Boolean).join('.').toLowerCase();
if (combinedKey.indexOf(searchString) !== -1) { res[key] = value; }
return res;
}, {});
}
Expand All @@ -57,7 +62,7 @@ class Sidebar extends React.Component {
</div>
{ map(this.props.namespacedMethods, (namespace, namespaceKey) => (
<Namespace namespaceName={namespaceKey} key={namespaceKey}>
{ map(this.filter(namespace), (method, methodKey) => (
{ map(this.filter(namespace, namespaceKey), (method, methodKey) => (
<Method
methodName={methodKey}
key={methodKey}
Expand Down

0 comments on commit b9da731

Please sign in to comment.