-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bc9840
commit 39bf933
Showing
7 changed files
with
145 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from "react"; | ||
import { useRouter } from "next/router"; | ||
import { Badge, Text, useColorMode, VStack } from "@chakra-ui/react"; | ||
import DataTable, { TableColumn } from "react-data-table-component"; | ||
import { getCustomStyles, rowStyles } from "components/utils/TableUtils"; | ||
import { TestDetailed } from "@common/testing/types"; | ||
import { RISK_TO_COLOR } from "~/constants"; | ||
|
||
interface TestListProps { | ||
tests: TestDetailed[]; | ||
} | ||
|
||
const TestList: React.FC<TestListProps> = React.memo(({ tests }) => { | ||
const router = useRouter(); | ||
const colorMode = useColorMode(); | ||
const onRowClicked = ( | ||
row: TestDetailed, | ||
e: React.MouseEvent<Element, MouseEvent> | ||
) => { | ||
router.push(`/test/${row.uuid}`); | ||
}; | ||
const columns: TableColumn<TestDetailed>[] = [ | ||
{ | ||
name: "Name", | ||
sortable: true, | ||
selector: (row: TestDetailed) => row.name || "", | ||
id: "name", | ||
}, | ||
{ | ||
name: "Tags", | ||
sortable: true, | ||
selector: (row: TestDetailed) => row.tags?.join(", ") || "", | ||
cell: (row: TestDetailed) => ( | ||
<VStack alignItems="flex-start" py="2"> | ||
{row.tags?.map((tag, idx) => ( | ||
<Badge key={idx}>{tag}</Badge> | ||
))} | ||
</VStack> | ||
), | ||
id: "hosts", | ||
}, | ||
{ | ||
name: "Requests", | ||
sortable: true, | ||
selector: (row: TestDetailed) => row.tags?.join(", ") || "", | ||
cell: (row: TestDetailed) => ( | ||
<VStack | ||
alignItems="flex-start" | ||
py="2" | ||
overflow={"hidden"} | ||
textOverflow={"ellipsis"} | ||
> | ||
{row.requests?.map((req, idx) => ( | ||
<Badge key={idx}>{req.url}</Badge> | ||
))} | ||
</VStack> | ||
), | ||
id: "requests", | ||
}, | ||
{ | ||
name: "Endpoint Risk", | ||
sortable: true, | ||
selector: (row: TestDetailed) => row.apiEndpoint.riskScore || "", | ||
cell: (row: TestDetailed) => ( | ||
<Badge | ||
p="1" | ||
fontSize="sm" | ||
colorScheme={RISK_TO_COLOR[row.apiEndpoint.riskScore]} | ||
pointerEvents="none" | ||
> | ||
{row.apiEndpoint.riskScore} | ||
</Badge> | ||
), | ||
id: "endpointRisk", | ||
}, | ||
]; | ||
return ( | ||
<DataTable | ||
style={rowStyles} | ||
columns={columns} | ||
data={tests} | ||
onRowClicked={onRowClicked} | ||
customStyles={getCustomStyles(colorMode.colorMode)} | ||
/> | ||
); | ||
}); | ||
|
||
export default TestList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
import { Box, VStack } from "@chakra-ui/react"; | ||
import List from "./List"; | ||
import { Test, TestDetailed } from "@common/testing/types"; | ||
|
||
const ListTests: React.FC<{ tests: Array<TestDetailed> }> = React.memo( | ||
({ tests }) => ( | ||
<VStack | ||
w="full" | ||
alignItems="flex-start" | ||
borderWidth="1px" | ||
rounded="md" | ||
spacing="0" | ||
overflow="hidden" | ||
> | ||
<Box w="full"> | ||
<List tests={tests} /> | ||
</Box> | ||
</VStack> | ||
) | ||
); | ||
|
||
export default ListTests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
import { Heading, VStack } from "@chakra-ui/react"; | ||
import { SideNavLinkDestination } from "components/Sidebar/NavLinkUtils"; | ||
import { GetServerSideProps } from "next"; | ||
import { listTests } from "~/api/tests"; | ||
import { SidebarLayoutShell } from "~/components/SidebarLayoutShell"; | ||
import ListTests from "~/components/TestList"; | ||
import { ContentContainer } from "~/components/utils/ContentContainer"; | ||
import superjson from "superjson"; | ||
|
||
const Tests = () => ( | ||
<SidebarLayoutShell | ||
title="Tests" | ||
currentTab={SideNavLinkDestination.Tests} | ||
> | ||
export const getServerSideProps: GetServerSideProps = async (context) => { | ||
const tests = await listTests(); | ||
return { | ||
props: { | ||
tests: superjson.stringify(tests.data), | ||
}, | ||
}; | ||
}; | ||
|
||
const Tests = ({ tests }) => ( | ||
<SidebarLayoutShell title="Tests" currentTab={SideNavLinkDestination.Tests}> | ||
<ContentContainer> | ||
<VStack w="full" alignItems="flex-start"> | ||
<Heading fontWeight="medium" size="xl" mb="8"> | ||
Tests | ||
</Heading> | ||
<ListTests tests={superjson.parse(tests)} /> | ||
</VStack> | ||
</ContentContainer> | ||
</SidebarLayoutShell> | ||
); | ||
|
||
export default Tests; |