Skip to content

Commit

Permalink
fix: clone the resources and re-assign children to found values (#3337)
Browse files Browse the repository at this point in the history
* Clone the resources and re-assign children to found values

* Remove unnecessary logs

* Update the object cloning for resources child

* Fix linting issues

* Fixup to search all levels

* Prettier fixes

Co-authored-by: Nickii Miaro <[email protected]>

---------

Co-authored-by: Nickii Miaro <[email protected]>
  • Loading branch information
musale and Mnickii authored Sep 27, 2024
1 parent ab63ca0 commit 974c3bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/app/utils/resources/resources-filter.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { IResource } from '../../../types/resources';
import { hasPlaceHolders } from '../sample-url-generation';

function searchResources(haystack: IResource[], needle: string): IResource[] {
function searchResources(resources: IResource[], needle: string): IResource[] {
const foundResources: IResource[] = [];
haystack.forEach((resource: IResource) => {
resources.forEach((resource: IResource) => {
if (resource.segment.contains(needle)) {
foundResources.push(resource);
return;
}
if (resource.children) {
const foundChildResources = searchResources(resource.children, needle);
if (foundChildResources.length > 0) {
resource.children = foundChildResources;
foundResources.push(resource);
const res = Object.assign({}, resource)
res.children = foundChildResources;
foundResources.push(res);
}
}
});
Expand Down

0 comments on commit 974c3bc

Please sign in to comment.