Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search for the parent category on sidebar #3940

Merged
merged 3 commits into from
Sep 26, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export default function ExtraSidebar(): JSX.Element {
event.dataTransfer.setData("genericNode", JSON.stringify(data));
}

function normalizeString(str: string): string {
return str.toLowerCase().replace(/_/g, " ").replace(/\s+/g, "");
}

// Handle showing components after use search input
function handleSearchInput(e: string) {
if (e === "") {
Expand All @@ -59,8 +63,11 @@ export default function ExtraSidebar(): JSX.Element {
ret[d] = {};
let keys = Object.keys(data[d]).filter(
(nd) =>
nd.toLowerCase().includes(e.toLowerCase()) ||
data[d][nd].display_name?.toLowerCase().includes(e.toLowerCase()),
normalizeString(nd).includes(normalizeString(e)) ||
normalizeString(data[d][nd].display_name).includes(
normalizeString(e),
) ||
normalizeString(d.toString()).includes(normalizeString(e)),
);
keys.forEach((element) => {
ret[d][element] = data[d][element];
Expand Down Expand Up @@ -106,43 +113,6 @@ export default function ExtraSidebar(): JSX.Element {
handleSearchInput(search);
}, [data]);

useEffect(() => {
if (getFilterEdge?.length > 0) {
setFilterData((_) => {
let dataClone = cloneDeep(data);
let ret = {};
Object.keys(dataClone).forEach((d: keyof APIObjectType, i) => {
ret[d] = {};
if (getFilterEdge.some((x) => x.family === d)) {
ret[d] = dataClone[d];

const filtered = getFilterEdge
.filter((x) => x.family === d)
.pop()
.type.split(",");

for (let i = 0; i < filtered.length; i++) {
filtered[i] = filtered[i].trimStart();
}

if (filtered.some((x) => x !== "")) {
let keys = Object.keys(dataClone[d]).filter((nd) =>
filtered.includes(nd),
);
Object.keys(dataClone[d]).forEach((element) => {
if (!keys.includes(element)) {
delete ret[d][element];
}
});
}
}
});
setSearch("");
return ret;
});
}
}, [getFilterEdge]);

useEffect(() => {
if (getFilterEdge?.length > 0) {
setFilterData((_) => {
Expand Down
Loading