Skip to content

Commit

Permalink
add endpoints to alert on home
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay288 committed Aug 4, 2022
1 parent 85bd6b8 commit 784fe57
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 59 deletions.
150 changes: 97 additions & 53 deletions frontend/src/components/Endpoint/AlertList.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,108 @@
import React from "react";
import { useColorMode, Badge } from "@chakra-ui/react";
import { useColorMode, Badge, HStack, Code, Text } from "@chakra-ui/react";
import DataTable, { TableColumn } from "react-data-table-component";
import { getCustomStyles, rowStyles } from "../utils/TableUtils";
import { Alert } from "@common/types";
import { RISK_TO_COLOR } from "../../constants";
import { METHOD_TO_COLOR, RISK_TO_COLOR } from "../../constants";

interface AlertListProps {
alerts: Alert[];
showEndpoint?: boolean;
}

const AlertList: React.FC<AlertListProps> = React.memo(({ alerts }) => {
const colorMode = useColorMode();
const columns: TableColumn<Alert>[] = [
{
name: "Risk",
sortable: true,
selector: (row: Alert) => row.risk || "",
cell: (row: Alert) => (
<Badge
p="1"
fontSize="sm"
colorScheme={RISK_TO_COLOR[row.risk]}
pointerEvents="none"
>
{row.risk}
</Badge>
),
id: "risk",
grow: 0,
},
{
name: "Type",
sortable: true,
selector: (row: Alert) => row.type || "",
id: "type",
grow: 1,
},
{
name: "Description",
sortable: true,
selector: (row: Alert) => row.description || "",
id: "title",
grow: 2,
},
{
name: "Time",
sortable: true,
selector: (row: Alert) => row.createdAt.toISOString(),
id: "time",
grow: 1,
},
];
return (
<DataTable
style={rowStyles}
columns={columns}
data={alerts}
customStyles={getCustomStyles(colorMode.colorMode)}
/>
);
});
const AlertList: React.FC<AlertListProps> = React.memo(
({ alerts, showEndpoint }) => {
const colorMode = useColorMode();
let columns: TableColumn<Alert>[] = [
{
name: "Risk",
sortable: true,
selector: (row: Alert) => row.risk || "",
cell: (row: Alert) => (
<Badge
p="1"
fontSize="sm"
colorScheme={RISK_TO_COLOR[row.risk]}
pointerEvents="none"
>
{row.risk}
</Badge>
),
id: "risk",
grow: 0,
},
];
if (showEndpoint) {
columns.push({
name: "Endpoint",
sortable: true,
selector: (row: Alert) => `${row.endpoint.method}_${row.endpoint.path}`,
cell: (row: Alert) => (
<HStack>
<Badge
fontSize="sm"
px="2"
py="1"
colorScheme={METHOD_TO_COLOR[row.endpoint.method] || "gray"}
>
{row.endpoint.method.toUpperCase()}
</Badge>
<Code p="1" pointerEvents="none">
{row.endpoint.path}
</Code>
</HStack>
),
id: "endpoint",
grow: 1,
});
}
columns.push(
{
name: "Type",
sortable: true,
selector: (row: Alert) => row.type || "",
cell: (row: Alert) => (
<Text fontSize="sm" fontWeight="semibold">
{row.type}
</Text>
),
id: "type",
grow: 1,
},
{
name: "Description",
sortable: true,
selector: (row: Alert) => row.description || "",
cell: (row: Alert) => (
<Text fontSize="sm" fontWeight="semibold">
{row.description}
</Text>
),
id: "title",
grow: 1,
},
{
name: "Time",
sortable: true,
selector: (row: Alert) => row.createdAt.toISOString(),
cell: (row: Alert) => (
<Text fontSize="sm" fontWeight="semibold">
{row.createdAt.toISOString()}
</Text>
),
id: "time",
grow: 1,
}
);
return (
<DataTable
style={rowStyles}
columns={columns}
data={alerts}
customStyles={getCustomStyles(colorMode.colorMode)}
/>
);
}
);

export default AlertList;
4 changes: 2 additions & 2 deletions frontend/src/components/Home/SummaryStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const SummaryStatValue: React.FC<{ value: number; title: string }> = React.memo(
({ value, title }) => (
<VStack
bg="cellBG"
w="60"
py="8"
w="56"
py="6"
rounded="md"
spacing="2"
borderWidth="1px"
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/components/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Heading, VStack } from "@chakra-ui/react";
import { Box, Heading, VStack } from "@chakra-ui/react";
import SummaryStats from "./SummaryStats";
import AlertList from "components/Endpoint/AlertList";
import { Alert } from "@common/types";
Expand All @@ -14,14 +14,18 @@ interface HomePageProps {
const HomePage: React.FC<HomePageProps> = React.memo(
({ numAlerts, numEndpoints, numPIIDataDetected, alerts }) => {
return (
<VStack w="full" alignItems="flex-start">
<VStack w="full" alignItems="flex-start" spacing="10">
<SummaryStats
numAlerts={numAlerts}
numEndpoints={numEndpoints}
numPIIDataDetected={numPIIDataDetected}
/>
<Heading fontSize="xl">Alerts</Heading>
<AlertList alerts={alerts} />
<VStack w="full" alignItems="flex-start" spacing="4">
<Heading fontSize="xl">Alerts</Heading>
<Box w="full" borderWidth="1px">
<AlertList alerts={alerts} showEndpoint />
</Box>
</VStack>
</VStack>
);
}
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ export const testConnections: Connection[] = [
export const testAlerts: Alert[] = [
{
apiEndpointUuid: "5239bcfe-bf24-40e6-b952-b9811210108e",
endpoint: {
uuid: "5239bcfe-bf24-40e6-b952-b9811210108e",
environment: "production",
host: "AWS Gateway 1",
path: "/foo/bar/{test}",
method: RestMethod.POST,
riskScore: RiskScore.HIGH,
firstDetected: "2022-07-31T00:52:10.586",
lastActive: "2022-07-31T00:52:10.586Z",
piiData: [],
traces: [],
alerts: [],
},
createdAt: new Date("2021-12-17T03:24:00"),
type: AlertType.OPEN_API_SPEC_DIFF,
risk: RiskScore.LOW,
Expand Down

0 comments on commit 784fe57

Please sign in to comment.