Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ export const filterEntityGroupsBySearchTerm = <
return groups;
}

return groups.reduce((result: Array<Group<G, T>>, group) => {
const { items, ...rest } = group;
const searchResults = new Fuse(items, FUSE_OPTIONS).search(searchTerm);
const result: Array<Group<G, T>> = [];
const len = groups.length;
for (let i = 0; i < len; i++) {
const group = groups[i];
// Create a Fuse instance for this group's items and perform the search
const searchResults = new Fuse(group.items, FUSE_OPTIONS).search(
searchTerm,
);

if (searchResults.length) {
result.push({ ...rest, items: searchResults } as Group<G, T>);
// Preserve other group properties, replacing items with the search results
result.push({ ...group, items: searchResults } as Group<G, T>);
}
}

return result;
}, []);
return result;
};