From 7c5adbe0118ec9d1a1effdc2451dd44ef4f8d795 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Fri, 22 Dec 2023 11:15:00 -0500 Subject: [PATCH 1/2] Show alerts in UI --- ui/app/api/mirrors/alerts/route.ts | 16 +++++++ ui/app/mirrors/mirror-error.tsx | 74 ++++++++++++++++++++++++++++++ ui/app/mirrors/tables.tsx | 7 ++- ui/prisma/schema.prisma | 44 ++++++++++++++++++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 ui/app/api/mirrors/alerts/route.ts create mode 100644 ui/app/mirrors/mirror-error.tsx diff --git a/ui/app/api/mirrors/alerts/route.ts b/ui/app/api/mirrors/alerts/route.ts new file mode 100644 index 0000000000..1870ef89af --- /dev/null +++ b/ui/app/api/mirrors/alerts/route.ts @@ -0,0 +1,16 @@ +import prisma from '@/app/utils/prisma'; + +export const dynamic = 'force-dynamic'; + +export async function POST(request: Request) { + const { flowName } = await request.json(); + const errs = await prisma.flow_errors.findMany({ + where: { + flow_name: flowName, + }, + }); + + return new Response( + JSON.stringify(errs, (_, v) => (typeof v === 'bigint' ? v.toString() : v)) + ); +} diff --git a/ui/app/mirrors/mirror-error.tsx b/ui/app/mirrors/mirror-error.tsx new file mode 100644 index 0000000000..950ef6d500 --- /dev/null +++ b/ui/app/mirrors/mirror-error.tsx @@ -0,0 +1,74 @@ +'use client'; + +import { Icon } from "@/lib/Icon"; +import { Prisma } from "@prisma/client"; +import React, { useState, useEffect } from "react"; +import * as Popover from '@radix-ui/react-popover'; +import { ProgressCircle } from "@/lib/ProgressCircle"; +import styled, { css } from 'styled-components'; + + +// const NoErrorMirror = styled.div` +// color: ${({ theme }) => theme.colors.positive.fill.normal}; +// `; + +// const ErroredMirror = styled.div` +// color: ${({ theme }) => theme.colors.destructive.fill.normal}; +// `; + + +export const ErrorModal = ({ flowErrors }: { flowErrors: Prisma.flow_errorsSelect[] }) => { + return ( + + ); +}; + + +export const MirrorError = ({ flowName }: { flowName: string }) => { + const [flowErrors, setFlowErrors] = useState(); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + const fetchData = async () => { + setIsLoading(true); + try { + const response = await fetch(`/api/mirrors/alerts`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ flowName }), + }); + + if (!response.ok) { + throw new Error('Network response was not ok'); + } + + const data = await response.json(); + setFlowErrors(data.errors); + } catch (err: any) { + setError(err.message); + } finally { + setIsLoading(false); + } + }; + + fetchData(); + }, [flowName]); + + if (isLoading) { + return
; + } + + if (error) { + console.log(error); + return
; + } + + if (!flowErrors || flowErrors.length === 0) { + return ; + } + + return ; +}; diff --git a/ui/app/mirrors/tables.tsx b/ui/app/mirrors/tables.tsx index 743bbc28a4..133427ff43 100644 --- a/ui/app/mirrors/tables.tsx +++ b/ui/app/mirrors/tables.tsx @@ -5,8 +5,10 @@ import TimeLabel from '@/components/TimeComponent'; import { Label } from '@/lib/Label'; import { SearchField } from '@/lib/SearchField'; import { Table, TableCell, TableRow } from '@/lib/Table'; +import { Tab } from '@tremor/react'; import Link from 'next/link'; import { useMemo, useState } from 'react'; +import { MirrorError } from './mirror-error'; export function CDCFlows({ cdcFlows }: { cdcFlows: any }) { const [searchQuery, setSearchQuery] = useState(''); @@ -43,7 +45,7 @@ export function CDCFlows({ cdcFlows }: { cdcFlows: any }) { }} header={ - {['Name', 'Source', 'Destination', 'Start Time', ''].map( + {['Name', 'Source', 'Destination', 'Start Time', 'Errors', ''].map( (heading, index) => (