Skip to content

Commit c64abea

Browse files
enhance: biome cry
1 parent 1cac2c6 commit c64abea

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

crowdsec-docs/src/components/table-render.tsx

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ const TableRender = ({ columns, url, include = [], exclude = [] }): React.JSX.El
2222
});
2323
}, [colorMode]);
2424

25-
// Memoize the include and exclude arrays to prevent unnecessary re-renders
26-
const memoizedInclude = useMemo(() => include, [JSON.stringify(include)]);
27-
const memoizedExclude = useMemo(() => exclude, [JSON.stringify(exclude)]);
28-
25+
// biome-ignore lint/correctness/useExhaustiveDependencies: exclude/include are stable
2926
useEffect(() => {
3027
setIsLoading(true);
3128
fetch(url)
@@ -37,36 +34,35 @@ const TableRender = ({ columns, url, include = [], exclude = [] }): React.JSX.El
3734
})
3835
.then((data) => {
3936
const updatedData = [];
40-
const names = [];
37+
const names = new Set();
4138

42-
Object.keys(data).forEach((key) => {
39+
for (const key of Object.keys(data)) {
4340
// filter duplicate names
4441
const item = data[key];
4542
const name = item.name;
46-
for (const element of memoizedExclude) {
47-
if (name.includes(element)) {
48-
return;
49-
}
43+
44+
if (names.has(name)) {
45+
continue;
5046
}
51-
for (const element of memoizedInclude) {
52-
if (!name.includes(element)) {
53-
return;
54-
}
47+
48+
if (exclude.some((excluded) => name.includes(excluded))) {
49+
continue;
5550
}
56-
if (names.includes(name)) {
57-
return;
51+
52+
if (!include.every((included) => name.includes(included))) {
53+
continue;
5854
}
5955

60-
names.push(name);
56+
names.add(name);
6157
updatedData.push({
6258
...item,
63-
// flattening list of strings into CSV strings allow global filtering on them
64-
// /!\ it requires special handling in the rendering side (see crowdsec-docs/docs/cti_api/taxonomy) /!\
59+
// flattening list of strings into CSV strings to allow global filtering on them
60+
// /!\ requires special handling in the rendering side (see crowdsec-docs/docs/cti_api/taxonomy) /!\
6561
...(item.behaviors ? { behaviors: item.behaviors.join("\n") } : {}),
6662
...(item.mitre_attacks ? { mitre_attacks: item.mitre_attacks.join("\n") } : {}),
6763
...(item.cves ? { cves: item.cves.join("\n") } : {}),
6864
});
69-
});
65+
}
7066

7167
setJsonContent(updatedData);
7268
setIsLoading(false);
@@ -75,8 +71,7 @@ const TableRender = ({ columns, url, include = [], exclude = [] }): React.JSX.El
7571
console.error("Error fetching data:", error);
7672
setIsLoading(false);
7773
});
78-
// Only re-fetch when url, include, or exclude actually change
79-
}, [url, memoizedInclude, memoizedExclude]);
74+
}, [url]);
8075

8176
if (!columns || (!jsonContent && !isLoading)) {
8277
return null;

0 commit comments

Comments
 (0)