-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added backlink to dataset in spans #178
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 37 additions & 0 deletions
37
frontend/app/api/projects/[projectId]/spans/[spanId]/datapoints/route.ts
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,37 @@ | ||
import { db } from "@/lib/db/drizzle"; | ||
import { datapointToSpan } from "@/lib/db/migrations/schema"; | ||
import { isCurrentUserMemberOfProject } from "@/lib/db/utils"; | ||
import { eq } from "drizzle-orm"; | ||
|
||
|
||
export async function GET( | ||
request: Request, | ||
{ params }: { params: { projectId: string; spanId: string } } | ||
) { | ||
|
||
const { projectId, spanId } = params; | ||
|
||
if (!(await isCurrentUserMemberOfProject(projectId))) { | ||
return new Response('Unauthorized', { status: 401 }); | ||
} | ||
|
||
const datapoints = await db.query.datapointToSpan.findMany({ | ||
where: eq(datapointToSpan.spanId, spanId), | ||
with: { | ||
datasetDatapoint: { | ||
with: { | ||
dataset: true | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
// Flatten the structure | ||
const flattenedDatapoints = datapoints.map(dp => ({ | ||
datapointId: dp.datasetDatapoint.id, | ||
datasetId: dp.datasetDatapoint.dataset.id, | ||
datasetName: dp.datasetDatapoint.dataset.name | ||
})); | ||
|
||
return Response.json(flattenedDatapoints); | ||
} |
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,93 @@ | ||
import { useProjectContext } from '@/contexts/project-context'; | ||
import { cn, swrFetcher } from '@/lib/utils'; | ||
import useSWR from 'swr'; | ||
import { useEffect } from 'react'; | ||
|
||
import { eventEmitter } from '@/lib/event-emitter'; | ||
import { Table, TableBody, TableCell, TableRow } from '../ui/table'; | ||
import { Skeleton } from '../ui/skeleton'; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger | ||
} from '../ui/tooltip'; | ||
import ClientTimestampFormatter from '../client-timestamp-formatter'; | ||
import { Button } from '../ui/button'; | ||
import { ArrowUpRight, Info, X } from 'lucide-react'; | ||
import Link from 'next/link'; | ||
|
||
interface SpanDatasetsProps { | ||
spanId: string; | ||
} | ||
|
||
interface SpanDataset { | ||
datasetName: string; | ||
datasetId: string; | ||
datapointId: string; | ||
} | ||
|
||
export default function SpanDatasets({ spanId }: SpanDatasetsProps) { | ||
const { projectId } = useProjectContext(); | ||
|
||
const { data, isLoading, mutate } = useSWR<SpanDataset[]>( | ||
`/api/projects/${projectId}/spans/${spanId}/datapoints`, | ||
swrFetcher | ||
); | ||
|
||
useEffect(() => { | ||
const handleDatapointAdded = () => { | ||
mutate(); | ||
}; | ||
eventEmitter.on('mutateSpanDatapoints', handleDatapointAdded); | ||
|
||
return () => { | ||
eventEmitter.off('mutateSpanDatapoints', handleDatapointAdded); | ||
}; | ||
}, [mutate]); | ||
|
||
return ( | ||
<div className="flex flex-col pb-2"> | ||
<div className="pb-2 font-medium text-lg">Datasets</div> | ||
<div className="border rounded bg-card"> | ||
{isLoading ? ( | ||
<div> | ||
<Skeleton className="h-10 w-full" /> | ||
</div> | ||
) : data && data.length > 0 ? ( | ||
<Table className=""> | ||
<TableBody className="text-base"> | ||
{data?.map((dataset: SpanDataset, index: number) => ( | ||
<TableRow | ||
key={dataset.datasetId} | ||
className={cn( | ||
'text-sm', | ||
index === data.length - 1 ? 'border-b-0' : '' | ||
)} | ||
> | ||
<TableCell> | ||
<div className="flex"> | ||
<div className="border-secondary-foreground/30 border p-0.5 px-3 bg-secondary rounded-full"> | ||
{dataset.datasetName} | ||
</div> | ||
</div> | ||
</TableCell> | ||
<TableCell className="font-mono text-secondary-foreground">{dataset.datapointId}</TableCell> | ||
<TableCell> | ||
<Link href={`/project/${projectId}/datasets/${dataset.datasetId}?datapointId=${dataset.datapointId}`} target="_blank"> | ||
<ArrowUpRight className="text-secondary-foreground" size={16} /> | ||
</Link> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
) : ( | ||
<div className="p-2 text-secondary-foreground text-sm"> | ||
No labels | ||
</div> | ||
)} | ||
</div> | ||
</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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check for the user's session to ensure that the user is authenticated before proceeding with the POST request.