From 784fe578a95b6e0e32d6b097361ca4dac4715597 Mon Sep 17 00:00:00 2001 From: Akshay Shekhawat Date: Thu, 4 Aug 2022 00:22:18 -0700 Subject: [PATCH] add endpoints to alert on home --- .../src/components/Endpoint/AlertList.tsx | 150 +++++++++++------- frontend/src/components/Home/SummaryStats.tsx | 4 +- frontend/src/components/Home/index.tsx | 12 +- frontend/src/testData.ts | 13 ++ 4 files changed, 120 insertions(+), 59 deletions(-) diff --git a/frontend/src/components/Endpoint/AlertList.tsx b/frontend/src/components/Endpoint/AlertList.tsx index 26e215ad..3e7a4a29 100644 --- a/frontend/src/components/Endpoint/AlertList.tsx +++ b/frontend/src/components/Endpoint/AlertList.tsx @@ -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 = React.memo(({ alerts }) => { - const colorMode = useColorMode(); - const columns: TableColumn[] = [ - { - name: "Risk", - sortable: true, - selector: (row: Alert) => row.risk || "", - cell: (row: Alert) => ( - - {row.risk} - - ), - 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 ( - - ); -}); +const AlertList: React.FC = React.memo( + ({ alerts, showEndpoint }) => { + const colorMode = useColorMode(); + let columns: TableColumn[] = [ + { + name: "Risk", + sortable: true, + selector: (row: Alert) => row.risk || "", + cell: (row: Alert) => ( + + {row.risk} + + ), + id: "risk", + grow: 0, + }, + ]; + if (showEndpoint) { + columns.push({ + name: "Endpoint", + sortable: true, + selector: (row: Alert) => `${row.endpoint.method}_${row.endpoint.path}`, + cell: (row: Alert) => ( + + + {row.endpoint.method.toUpperCase()} + + + {row.endpoint.path} + + + ), + id: "endpoint", + grow: 1, + }); + } + columns.push( + { + name: "Type", + sortable: true, + selector: (row: Alert) => row.type || "", + cell: (row: Alert) => ( + + {row.type} + + ), + id: "type", + grow: 1, + }, + { + name: "Description", + sortable: true, + selector: (row: Alert) => row.description || "", + cell: (row: Alert) => ( + + {row.description} + + ), + id: "title", + grow: 1, + }, + { + name: "Time", + sortable: true, + selector: (row: Alert) => row.createdAt.toISOString(), + cell: (row: Alert) => ( + + {row.createdAt.toISOString()} + + ), + id: "time", + grow: 1, + } + ); + return ( + + ); + } +); export default AlertList; diff --git a/frontend/src/components/Home/SummaryStats.tsx b/frontend/src/components/Home/SummaryStats.tsx index 90eeab04..bd2ea759 100644 --- a/frontend/src/components/Home/SummaryStats.tsx +++ b/frontend/src/components/Home/SummaryStats.tsx @@ -11,8 +11,8 @@ const SummaryStatValue: React.FC<{ value: number; title: string }> = React.memo( ({ value, title }) => ( = React.memo( ({ numAlerts, numEndpoints, numPIIDataDetected, alerts }) => { return ( - + - Alerts - + + Alerts + + + + ); } diff --git a/frontend/src/testData.ts b/frontend/src/testData.ts index 27c5aecb..bd166809 100644 --- a/frontend/src/testData.ts +++ b/frontend/src/testData.ts @@ -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,