-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates job run page to show schema initialization errors (#3177)
- Loading branch information
1 parent
8be389e
commit 7710aa2
Showing
3 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
frontend/apps/web/app/(mgmt)/[account]/runs/[id]/components/JobRunActivityErrors.tsx
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,134 @@ | ||
import { TanstackQueryProviderIgnore404Errors } from '@/components/providers/query-provider'; | ||
import { | ||
Accordion, | ||
AccordionContent, | ||
AccordionItem, | ||
AccordionTrigger, | ||
} from '@/components/ui/accordion'; | ||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; | ||
import { ScrollArea } from '@/components/ui/scroll-area'; | ||
import { useQuery } from '@connectrpc/connect-query'; | ||
import { Code, Connection, ConnectionService, JobService } from '@neosync/sdk'; | ||
import { ReactElement } from 'react'; | ||
import { IoAlertCircleOutline } from 'react-icons/io5'; | ||
|
||
interface JobRunActivityErrorsProps { | ||
jobRunId: string; | ||
jobId: string; | ||
accountId: string; | ||
} | ||
|
||
interface InitSchemaReport { | ||
ConnectionId: string; | ||
Errors: { Statement: string; Error: string }[]; | ||
} | ||
|
||
function parseUint8ArrayToInitSchemaReport( | ||
data: Uint8Array | ||
): InitSchemaReport[] | null { | ||
try { | ||
const jsonString = new TextDecoder().decode(data); | ||
const parsedData: InitSchemaReport[] = JSON.parse(jsonString); | ||
return parsedData; | ||
} catch (error) { | ||
console.error('Error parsing JSON:', error); | ||
return null; | ||
} | ||
} | ||
export default function JobRunActivityErrors( | ||
props: JobRunActivityErrorsProps | ||
): ReactElement { | ||
return ( | ||
<TanstackQueryProviderIgnore404Errors> | ||
<JobRunErrorViewer {...props} /> | ||
</TanstackQueryProviderIgnore404Errors> | ||
); | ||
} | ||
|
||
function JobRunErrorViewer(props: JobRunActivityErrorsProps): ReactElement { | ||
const { jobRunId, accountId } = props; | ||
|
||
const { data: runContextData, error: runContextError } = useQuery( | ||
JobService.method.getRunContext, | ||
{ | ||
id: { jobRunId, externalId: 'init-schema-report', accountId: accountId }, | ||
}, | ||
{ enabled: !!jobRunId && !!accountId, retry: false } | ||
); | ||
|
||
const { data: connectionsData } = useQuery( | ||
ConnectionService.method.getConnections, | ||
{ accountId }, | ||
{ enabled: !!accountId } | ||
); | ||
|
||
if (runContextError && runContextError.code === Code.NotFound) { | ||
return <div></div>; | ||
} | ||
|
||
const runContext = runContextData?.value | ||
? parseUint8ArrayToInitSchemaReport(runContextData.value) | ||
: null; | ||
|
||
const filteredRunContext = runContext?.filter( | ||
(item) => item.Errors && item.Errors.length > 0 | ||
); | ||
|
||
const connectionsMap = | ||
connectionsData?.connections?.reduce( | ||
(acc, connection) => { | ||
acc[connection.id] = connection; | ||
return acc; | ||
}, | ||
{} as Record<string, Connection> | ||
) ?? {}; | ||
|
||
return ( | ||
<div> | ||
{filteredRunContext && filteredRunContext.length > 0 && ( | ||
<ScrollArea className="h-[400px] w-full rounded-md border"> | ||
{filteredRunContext.map((connectionError) => ( | ||
<div key={connectionError.ConnectionId} className="p-4"> | ||
<Alert className="border-red-500"> | ||
<div className="flex flex-row items-center gap-2"> | ||
<IoAlertCircleOutline className="h-6 w-6" /> | ||
<AlertTitle className="text-lg"> | ||
Connection:{' '} | ||
{connectionsMap[connectionError.ConnectionId]?.name} | ||
<span className="text-muted-foreground text-sm pl-4"> | ||
{connectionError.ConnectionId} | ||
</span> | ||
</AlertTitle> | ||
</div> | ||
<AlertDescription> | ||
<h2 className="text-md font-semibold text-muted-foreground mt-2"> | ||
Schema Initialization Errors | ||
</h2> | ||
<Accordion type="single" collapsible className="w-full"> | ||
{connectionError.Errors.map((error, errorIdx) => ( | ||
<AccordionItem value={`item-${errorIdx}`} key={errorIdx}> | ||
<AccordionTrigger className="text-left"> | ||
<div className="font-medium">{error.Error}</div> | ||
</AccordionTrigger> | ||
<AccordionContent> | ||
<div className="space-y-2"> | ||
<div className="rounded-md bg-muted p-3"> | ||
<p className="font-medium">Statement:</p> | ||
<pre className="mt-2 whitespace-pre-wrap text-sm"> | ||
{error.Statement} | ||
</pre> | ||
</div> | ||
</div> | ||
</AccordionContent> | ||
</AccordionItem> | ||
))} | ||
</Accordion> | ||
</AlertDescription> | ||
</Alert> | ||
</div> | ||
))} | ||
</ScrollArea> | ||
)} | ||
</div> | ||
); | ||
} |
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