From 1ce7d17eeb22f6e68dd37c6eea4ddf098a8ecb00 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Thu, 26 Sep 2024 14:44:44 -0300 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=9D=20(extraSidebarComponent/index?= =?UTF-8?q?.tsx):=20refactor=20handleSearchInput=20function=20to=20use=20a?= =?UTF-8?q?=20normalizeString=20helper=20function=20for=20better=20code=20?= =?UTF-8?q?readability=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../extraSidebarComponent/index.tsx | 48 ++++--------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 32b1fe7ef04..28a097d3a27 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -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 === "") { @@ -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]; @@ -106,42 +113,7 @@ 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]); + console.log(data); useEffect(() => { if (getFilterEdge?.length > 0) { From ad255aee6490848b42ab966576d450b447e84407 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Thu, 26 Sep 2024 16:18:10 -0300 Subject: [PATCH 2/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(extraSidebarComponent?= =?UTF-8?q?/index.tsx):=20remove=20unnecessary=20console.log=20statement?= =?UTF-8?q?=20from=20the=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/FlowPage/components/extraSidebarComponent/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 28a097d3a27..5d48f1577a0 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -113,8 +113,6 @@ export default function ExtraSidebar(): JSX.Element { handleSearchInput(search); }, [data]); - console.log(data); - useEffect(() => { if (getFilterEdge?.length > 0) { setFilterData((_) => {