From c354646c822c3b57a151d58907a50a51e40ae96e Mon Sep 17 00:00:00 2001 From: Tal Borenstein Date: Mon, 19 Feb 2024 15:50:13 +0200 Subject: [PATCH] feat: working --- keep-ui/app/mapping/mapping.tsx | 34 ++++- keep-ui/app/mapping/models.tsx | 6 +- keep-ui/app/mapping/rules-table.tsx | 150 +++++++++++++++++++ keep-ui/components/navbar/ConfigureLinks.tsx | 7 +- keep-ui/utils/hooks/useMappingRules.ts | 6 +- keep/api/models/db/mapping.py | 12 +- keep/api/routes/mapping.py | 24 ++- 7 files changed, 224 insertions(+), 15 deletions(-) create mode 100644 keep-ui/app/mapping/rules-table.tsx diff --git a/keep-ui/app/mapping/mapping.tsx b/keep-ui/app/mapping/mapping.tsx index 1b9cba743..296883e9d 100644 --- a/keep-ui/app/mapping/mapping.tsx +++ b/keep-ui/app/mapping/mapping.tsx @@ -1,13 +1,23 @@ "use client"; -import { Badge, Card } from "@tremor/react"; +import { Badge, Callout, Card } from "@tremor/react"; import CreateNewMapping from "./create-new-mapping"; import { useMappings } from "utils/hooks/useMappingRules"; +import RulesTable from "./rules-table"; +import { MdWarning } from "react-icons/md"; +import Loading from "app/loading"; export default function Mapping() { - const { data: mappings, mutate } = useMappings(); + const { data: mappings, isLoading } = useMappings(); return ( - Beta + + Beta +

Configure

@@ -18,8 +28,22 @@ export default function Mapping() {
-

Rules

- {mappings && mappings.length > 0 ? <>Rules! : <>No Rules!} + {isLoading ? ( + + ) : mappings && mappings.length > 0 ? ( + + ) : ( + +

No mapping rules found

+

+ Configure new mapping rule using the mapping rules wizard. +

+
+ )}
diff --git a/keep-ui/app/mapping/models.tsx b/keep-ui/app/mapping/models.tsx index e0e2bbebb..7eb3a1c2e 100644 --- a/keep-ui/app/mapping/models.tsx +++ b/keep-ui/app/mapping/models.tsx @@ -1,7 +1,10 @@ export interface MappingRule { - id?: number; + id: number; tenant_id: string; priority: number; + name: string; + description?: string; + file_name?: string; created_by?: string; created_at: Date; disabled: boolean; @@ -9,4 +12,5 @@ export interface MappingRule { condition?: string; matchers: string[]; rows: { [key: string]: any }[]; + attributes?: string[]; } diff --git a/keep-ui/app/mapping/rules-table.tsx b/keep-ui/app/mapping/rules-table.tsx new file mode 100644 index 000000000..c0a2ea1d8 --- /dev/null +++ b/keep-ui/app/mapping/rules-table.tsx @@ -0,0 +1,150 @@ +import { + Badge, + Button, + Table, + TableBody, + TableCell, + TableHead, + TableHeaderCell, + TableRow, +} from "@tremor/react"; +import { MappingRule } from "./models"; +import { + DisplayColumnDef, + createColumnHelper, + flexRender, + getCoreRowModel, + useReactTable, +} from "@tanstack/react-table"; +import { MdRemoveCircle } from "react-icons/md"; +import { useSession } from "next-auth/react"; +import { getApiURL } from "utils/apiUrl"; +import { useMappings } from "utils/hooks/useMappingRules"; +import { toast } from "react-toastify"; + +const columnHelper = createColumnHelper(); + +export default function RulesTable({ mappings }: { mappings: MappingRule[] }) { + const { data: session } = useSession(); + const { mutate } = useMappings(); + + const columns = [ + columnHelper.display({ + id: "id", + header: "#", + cell: (context) => context.row.original.id, + }), + columnHelper.display({ + id: "name", + header: "Name", + cell: (context) => context.row.original.name, + }), + columnHelper.display({ + id: "description", + header: "Description", + cell: (context) => context.row.original.description, + }), + columnHelper.display({ + id: "fileName", + header: "Original File Name", + cell: (context) => context.row.original.file_name, + }), + columnHelper.display({ + id: "matchers", + header: "Matchers", + cell: (context) => context.row.original.matchers.join(","), + }), + columnHelper.display({ + id: "attributes", + header: "Attributes", + cell: (context) => ( +
+ {context.row.original.attributes?.map((attr) => ( + + {attr} + + ))} +
+ ), + }), + columnHelper.display({ + id: "delete", + header: "", + cell: (context) => ( +