Skip to content

Commit

Permalink
Use tx schema and type in tx detail
Browse files Browse the repository at this point in the history
  • Loading branch information
abefernan committed Sep 30, 2024
1 parent f8b933e commit 09d789f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions components/tx-data.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";

import { sequenceDiagramFromSpans } from "@/lib/mermaid";
import { Tx, TxSchema } from "@/types/txs";
import { useQuery } from "@tanstack/react-query";
import { z } from "zod";
import Mermaid from "./mermaid";

type TxDataProps = {
Expand All @@ -10,11 +12,7 @@ type TxDataProps = {
};

export default function TxData({ txId, spanId }: TxDataProps) {
const {
isPending,
error,
data: spans,
} = useQuery({
const { isPending, error, data } = useQuery({
queryKey: [`tx-${txId}`],
queryFn: () =>
fetch(`http://localhost:4000/api/v1/txs?traceID=${txId}`)
Expand All @@ -26,14 +24,24 @@ export default function TxData({ txId, spanId }: TxDataProps) {

if (error) return "An error has occurred: " + error.message;

const spans: Readonly<Array<Tx>> = z.array(TxSchema).parse(data);

const mermaidChart = sequenceDiagramFromSpans(spans);

const span = spans.find((span: any) => span._source.spanID === spanId);
const span = spans.find((span: Tx) => span.spanId === spanId);

return (
<div>
<Mermaid chart={mermaidChart} />
{span ? <pre>{JSON.stringify(span._source.tags, null, 2)}</pre> : null}
{span ? (
<pre>
{JSON.stringify(
Object.fromEntries(Array.from(span.tags).sort()),
null,
2,
)}
</pre>
) : null}
</div>
);
}

0 comments on commit 09d789f

Please sign in to comment.