Skip to content

Commit

Permalink
implement search, fix performance
Browse files Browse the repository at this point in the history
Signed-off-by: michaelmumenthaler <[email protected]>
  • Loading branch information
michaelmumenthaler committed Dec 16, 2021
1 parent 1542b96 commit 4de598b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 49 deletions.
33 changes: 26 additions & 7 deletions src/components/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@ import { Stack } from "@fluentui/react";

function Body() {
const [dataList, setDataList]: any[] = useState([]);
const [originalList, setoriginalList]: any[] = useState([]);
const apiAddress: string = process.env.REACT_APP_API_ADDRESS as string;

useEffect(() => {
(async () => {
const res = await fetch("http://" + apiAddress + "/api/v1/reports");
const json = await res.json();
setDataList(json);
})();
});
fetch("http://" + apiAddress + "/api/v1/reports")
.then((res) => {
res.json().then((data) => {
setoriginalList(data);
setDataList(data);
});
})
.catch((err) => {
console.log(err);
});
}, []);

const onSearch = (value: string | undefined) => {
if (!value) {
setDataList([...originalList]);
} else {
setDataList(
originalList.filter((dataItem: any) => {
const itemName = dataItem.serverName.toLowerCase();
return itemName.includes(value);
})
);
}
};

return (
<Stack
Expand All @@ -22,7 +41,7 @@ function Body() {
tokens={{ childrenGap: "l1", padding: "l2" }}
>
<Stack.Item>
<Search />
<Search onSearch={onSearch} />
</Stack.Item>
<Stack.Item>
<DataTable vulnData={dataList} />
Expand Down
51 changes: 29 additions & 22 deletions src/components/DataTable.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
import { DetailsList, IGroup, SelectionMode, Stack } from "@fluentui/react";
import { useEffect, useState } from "react";

interface Props {
vulnData: any[];
}

export const DataTable: React.FC<Props> = (props) => {
const itemsForRender = new Array<any>();
const [groupState, setGroupState] = useState(new Array<IGroup>());
const [itemToRenderState, setItemToRenderState] = useState(Array<any>());

const groups = new Array<IGroup>();
props.vulnData.forEach((server) => {
let index: number = 0;
useEffect(() => {
const itemsForRender = new Array<any>();
const groups = new Array<IGroup>();
props.vulnData.forEach((server) => {
let index: number = 0;

if (itemsForRender.length > 0) {
index = itemsForRender.length - 1;
} else {
index = itemsForRender.length;
}

server.vulnerableFiles.forEach((file: any) => {
itemsForRender.push({ vulnerableFiles: file.fileName });
if (itemsForRender.length > 0) {
index = itemsForRender.length;
} else {
index = itemsForRender.length;
}
server.vulnerableFiles.forEach((file: any) => {
itemsForRender.push({ vulnerableFiles: file.fileName });
});
groups.push({
key: server.serverName,
name: server.serverName,
level: 0,
count: server.vulnerableFiles.length,
startIndex: index,
isCollapsed: true,
});
});

groups.push({
key: server.serverName,
name: server.serverName,
level: 0,
count: server.vulnerableFiles.length,
startIndex: index,
});
});
setGroupState(groups);
setItemToRenderState(itemsForRender);
}, [props.vulnData]);

return (
<Stack
horizontalAlign="center"
style={{ minWidth: "100%", backgroundColor: "white" }}
>
<DetailsList
items={itemsForRender}
groups={groups}
items={itemToRenderState}
groups={groupState}
groupProps={{ isAllGroupsCollapsed: true }}
columns={[
{
Expand Down
34 changes: 16 additions & 18 deletions src/components/Head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@ import Logo from "./Logo";

export default function Head() {
return (
<div>
<Stack
horizontal
horizontalAlign="space-around"
verticalAlign="center"
tokens={{ childrenGap: "m", padding: "m" }}
>
<Stack.Item align="start">
<></>
</Stack.Item>
<Stack
horizontal
horizontalAlign="space-around"
verticalAlign="center"
tokens={{ childrenGap: "m", padding: "m" }}
>
<Stack.Item align="start">
<></>
</Stack.Item>

<Stack.Item align="center">
<Logo />
</Stack.Item>
<Stack.Item align="center">
<Logo />
</Stack.Item>

<Stack.Item align="end">
<></>
</Stack.Item>
</Stack>
</div>
<Stack.Item align="end">
<></>
</Stack.Item>
</Stack>
);
}
8 changes: 6 additions & 2 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { SearchBox } from "@fluentui/react/lib/SearchBox";

const Search = () => {
interface ISearchProps {
onSearch: (value: string | undefined) => void;
}

const Search = (props: ISearchProps) => {
return (
<SearchBox
style={{ minWidth: 800 }}
placeholder="Search"
onSearch={(newValue) => console.log("value is " + newValue)}
onChange={(elem, newValue) => props.onSearch(newValue)}
/>
);
};
Expand Down

0 comments on commit 4de598b

Please sign in to comment.