Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(comments): Refactor annotation queue item page comments (#9908)

Michael Fröhlich7cfc33697048
diff --git a/web/src/components/trace/ObservationPreview.tsx b/web/src/components/trace/ObservationPreview.tsx
index 8698c8e8ff..d5699e98e3 100644
--- a/web/src/components/trace/ObservationPreview.tsx
+++ b/web/src/components/trace/ObservationPreview.tsx
@@ -49,6 +49,7 @@ export const ObservationPreview = ({
commentCounts,
viewType = "detailed",
isTimeline,
+ showCommentButton = false,
}: {
observations: Array<ObservationReturnType>;
projectId: string;
@@ -58,6 +59,7 @@ export const ObservationPreview = ({
commentCounts?: Map<string, number>;
viewType?: "focused" | "detailed";
isTimeline?: boolean;
+ showCommentButton?: boolean;
}) => {
const [selectedTab, setSelectedTab] = useQueryParam(
"view",
@@ -199,6 +201,14 @@ export const ObservationPreview = ({
/>
</>
)}
+ {viewType === "focused" && showCommentButton && (
+ <CommentDrawerButton
+ projectId={preloadedObservation.projectId}
+ objectId={preloadedObservation.id}
+ objectType="OBSERVATION"
+ count={commentCounts?.get(preloadedObservation.id)}
+ />
+ )}
</div>
</div>
<div className="grid w-full min-w-0 items-center justify-between">
diff --git a/web/src/components/trace/TracePreview.tsx b/web/src/components/trace/TracePreview.tsx
index 18807cc30c..efc53dd80d 100644
--- a/web/src/components/trace/TracePreview.tsx
+++ b/web/src/components/trace/TracePreview.tsx
@@ -52,6 +52,7 @@ export const TracePreview = ({
serverScores: scores,
commentCounts,
viewType = "detailed",
+ showCommentButton = false,
}: {
trace: Omit<TraceDomain, "input" | "output" | "metadata"> & {
latency?: number;
@@ -63,6 +64,7 @@ export const TracePreview = ({
serverScores: APIScoreV2[];
commentCounts?: Map<string, number>;
viewType?: "detailed" | "focused";
+ showCommentButton?: boolean;
}) => {
const [selectedTab, setSelectedTab] = useQueryParam(
"view",
@@ -173,6 +175,14 @@ export const TracePreview = ({
/>
</>
)}
+ {viewType === "focused" && showCommentButton && (
+ <CommentDrawerButton
+ projectId={trace.projectId}
+ objectId={trace.id}
+ objectType="TRACE"
+ count={commentCounts?.get(trace.id)}
+ />
+ )}
</div>
</div>
<div className="grid w-full min-w-0 items-center justify-between">
diff --git a/web/src/features/annotation-queues/components/AnnotationQueueItemPage.tsx b/web/src/features/annotation-queues/components/AnnotationQueueItemPage.tsx
index 993a2e53f4..73ad3de6c5 100644
--- a/web/src/features/annotation-queues/components/AnnotationQueueItemPage.tsx
+++ b/web/src/features/annotation-queues/components/AnnotationQueueItemPage.tsx
@@ -30,7 +30,6 @@ export const AnnotationQueueItemPage: React.FC<{
>(null);
const [seenItemIds, setSeenItemIds] = useState<string[]>([]);
const [progressIndex, setProgressIndex] = useState(0);
- const [hasCommentDraft, setHasCommentDraft] = useState(false);
const hasAccess = useHasProjectAccess({
projectId,
@@ -163,12 +162,6 @@ export const AnnotationQueueItemPage: React.FC<{
};
const handleNavigateNext = async () => {
- if (hasCommentDraft) {
- const proceed = confirm(
- "You have an unsaved comment. Do you want to go to the next item and discard this draft?",
- );
- if (!proceed) return;
- }
if (progressIndex >= seenItemIds.length - 1) {
const nextItem = await fetchAndLockNextMutation.mutateAsync({
queueId: annotationQueueId,
@@ -182,13 +175,6 @@ export const AnnotationQueueItemPage: React.FC<{
const handleComplete = async () => {
if (!relevantItem) return;
- const willNavigate = !isSingleItem && progressIndex + 1 < totalItems;
- if (hasCommentDraft && willNavigate) {
- const proceed = confirm(
- "You have an unsaved comment. Do you want to complete and move to the next item, discarding the draft?",
- );
- if (!proceed) return;
- }
await completeMutation.mutateAsync({
itemId: relevantItem.id,
projectId,
@@ -219,7 +205,6 @@ export const AnnotationQueueItemPage: React.FC<{
view={view}
configs={configs}
projectId={projectId}
- onHasCommentDraftChange={setHasCommentDraft}
/>
);
case AnnotationQueueObjectType.SESSION:
@@ -229,7 +214,6 @@ export const AnnotationQueueItemPage: React.FC<{
data={objectData.data}
configs={configs}
projectId={projectId}
- onHasCommentDraftChange={setHasCommentDraft}
/>
);
default:
diff --git a/web/src/features/annotation-queues/components/processors/SessionAnnotationProcessor.tsx b/web/src/features/annotation-queues/components/processors/SessionAnnotationProcessor.tsx
index 618cb8c08f..ae812303dd 100644
--- a/web/src/features/annotation-queues/components/processors/SessionAnnotationProcessor.tsx
+++ b/web/src/features/annotation-queues/components/processors/SessionAnnotationProcessor.tsx
@@ -22,7 +22,6 @@ interface SessionAnnotationProcessorProps {
data: any; // // Session data with scores
configs: ScoreConfigDomain[];
projectId: string;
- onHasCommentDraftChange?: (hasDraft: boolean) => void;
}
// some projects have thousands of traces in a session, paginate to avoid rendering all at once
@@ -30,7 +29,7 @@ const PAGE_SIZE = 10;
export const SessionAnnotationProcessor: React.FC<
SessionAnnotationProcessorProps
-> = ({ item, data, configs, projectId, onHasCommentDraftChange }) => {
+> = ({ item, data, configs, projectId }) => {
const [visibleTraces, setVisibleTraces] = useState(PAGE_SIZE);
const [currentTraceIndex, setCurrentTraceIndex] = useState(1);
@@ -155,7 +154,6 @@ export const SessionAnnotationProcessor: React.FC<
scores={data?.scores ?? []}
configs={configs}
environment={data?.environment}
- onHasCommentDraftChange={onHasCommentDraftChange}
/>
);
diff --git a/web/src/features/annotation-queues/components/processors/TraceAnnotationProcessor.tsx b/web/src/features/annotation-queues/components/processors/TraceAnnotationProcessor.tsx
index 3c3a9ab113..82104007e7 100644
--- a/web/src/features/annotation-queues/components/processors/TraceAnnotationProcessor.tsx
+++ b/web/src/features/annotation-queues/components/processors/TraceAnnotationProcessor.tsx
@@ -10,6 +10,9 @@ import { useEffect } from "react";
import { StringParam, useQueryParam } from "use-query-params";
import { AnnotationDrawerSection } from "../shared/AnnotationDrawerSection";
import { AnnotationProcessingLayout } from "../shared/AnnotationProcessingLayout";
+import { api } from "@/src/utils/api";
+import { castToNumberMap } from "@/src/utils/map-utils";
+import { useIsAuthenticatedAndProjectMember } from "@/src/features/auth/hooks";
interface TraceAnnotationProcessorProps {
item: AnnotationQueueItem & {
@@ -20,12 +23,11 @@ interface TraceAnnotationProcessorProps {
view: "showTree" | "hideTree";
configs: ScoreConfigDomain[];
projectId: string;
- onHasCommentDraftChange?: (hasDraft: boolean) => void;
}
export const TraceAnnotationProcessor: React.FC<
TraceAnnotationProcessorProps
-> = ({ item, data, view, configs, projectId, onHasCommentDraftChange }) => {
+> = ({ item, data, view, configs, projectId }) => {
const traceId = item.parentTraceId ?? item.objectId;
const [currentObservationId, setCurrentObservationId] = useQueryParam(
@@ -33,6 +35,42 @@ export const TraceAnnotationProcessor: React.FC<
StringParam,
);
+ const isAuthenticatedAndProjectMember =
+ useIsAuthenticatedAndProjectMember(projectId);
+
+ const traceCommentCounts = api.comments.getCountByObjectId.useQuery(
+ {
+ projectId: projectId,
+ objectId: traceId,
+ objectType: "TRACE",
+ },
+ {
+ trpc: {
+ context: {
+ skipBatch: true,
+ },
+ },
+ refetchOnMount: false,
+ enabled: isAuthenticatedAndProjectMember,
+ },
+ );
+
+ const observationCommentCounts = api.comments.getCountByObjectType.useQuery(
+ {
+ projectId: projectId,
+ objectType: "OBSERVATION",
+ },
+ {
+ trpc: {
+ context: {
+ skipBatch: true,
+ },
+ },
+ refetchOnMount: false,
+ enabled: isAuthenticatedAndProjectMember,
+ },
+ );
+
useEffect(() => {
if (
view === "showTree" &&
@@ -65,6 +103,8 @@ export const TraceAnnotationProcessor: React.FC<
serverScores={data.scores}
observations={data.observations}
viewType="focused"
+ showCommentButton={true}
+ commentCounts={castToNumberMap(traceCommentCounts.data)}
/>
) : (
<ObservationPreview
@@ -74,6 +114,8 @@ export const TraceAnnotationProcessor: React.FC<
currentObservationId={item.objectId}
traceId={traceId}
viewType="focused"
+ showCommentButton={true}
+ commentCounts={castToNumberMap(observationCommentCounts.data)}
/>
)}
</div>
@@ -102,7 +144,6 @@ export const TraceAnnotationProcessor: React.FC<
scores={data?.scores ?? []}
configs={configs}
environment={data?.environment}
- onHasCommentDraftChange={onHasCommentDraftChange}
/>
);
diff --git a/web/src/features/annotation-queues/components/shared/AnnotationDrawerSection.tsx b/web/src/features/annotation-queues/components/shared/AnnotationDrawerSection.tsx
index bb220e90f5..d82ab56444 100644
--- a/web/src/features/annotation-queues/components/shared/AnnotationDrawerSection.tsx
+++ b/web/src/features/annotation-queues/components/shared/AnnotationDrawerSection.tsx
@@ -1,10 +1,4 @@
import { Card } from "@/src/components/ui/card";
-import {
- ResizableHandle,
- ResizablePanel,
- ResizablePanelGroup,
-} from "@/src/components/ui/resizable";
-import useSessionStorage from "@/src/components/useSessionStorage";
import { type ScoreTarget } from "@/src/features/scores/types";
import {
type AnnotationQueueItem,
@@ -14,7 +8,6 @@ import {
} from "@langfuse/shared";
import { TriangleAlertIcon } from "lucide-react";
import { useSession } from "next-auth/react";
-import { CommentsSection } from "./CommentsSection";
import { AnnotationForm } from "@/src/features/scores/components/AnnotationForm";
interface AnnotationDrawerSectionProps {
@@ -26,76 +19,42 @@ interface AnnotationDrawerSectionProps {
scores: APIScoreV2[];
configs: ScoreConfigDomain[];
environment?: string;
- onHasCommentDraftChange?: (hasDraft: boolean) => void;
}
export const AnnotationDrawerSection: React.FC<
AnnotationDrawerSectionProps
-> = ({
- item,
- scoreTarget,
- scores,
- configs,
- environment,
- onHasCommentDraftChange,
-}) => {
+> = ({ item, scoreTarget, scores, configs, environment }) => {
const session = useSession();
- const [verticalSize, setVerticalSize] = useSessionStorage(
- `annotationQueueDrawerVertical-${item.projectId}`,
- 60,
- );
const isLockedByOtherUser = item.lockedByUserId !== session.data?.user?.id;
return (
- <Card className="col-span-2 flex h-full flex-col overflow-hidden">
- <ResizablePanelGroup
- direction="vertical"
- onLayout={(sizes) => setVerticalSize(sizes[0])}
- >
- <ResizablePanel
- className="w-full overflow-y-auto p-3"
- minSize={30}
- defaultSize={verticalSize}
- >
- <AnnotationForm
- key={"annotation-drawer-content" + item.objectId}
- scoreTarget={scoreTarget}
- serverScores={scores}
- configSelection={{ mode: "fixed", configs }}
- scoreMetadata={{
- projectId: item.projectId,
- queueId: item.queueId,
- environment,
- }}
- analyticsData={{
- type: scoreTarget.type,
- source: "AnnotationQueue",
- }}
- actionButtons={
- isLockedByOtherUser && isPresent(item.lockedByUser?.name) ? (
- <div className="flex items-center justify-center rounded-sm border border-dark-red bg-light-red p-1">
- <TriangleAlertIcon className="mr-1 h-4 w-4 text-dark-red" />
- <span className="text-xs text-dark-red">
- Currently edited by {item.lockedByUser.name}
- </span>
- </div>
- ) : undefined
- }
- />
- </ResizablePanel>
- <ResizableHandle withHandle />
- <ResizablePanel className="overflow-y-auto" minSize={20}>
- <CommentsSection
- projectId={item.projectId}
- objectId={item.objectId}
- objectType={item.objectType}
- onDraftChange={(draft) => {
- onHasCommentDraftChange?.(draft);
- }}
- />
- </ResizablePanel>
- </ResizablePanelGroup>
+ <Card className="col-span-2 flex h-full flex-col overflow-y-auto p-3">
+ <AnnotationForm
+ key={"annotation-drawer-content" + item.objectId}
+ scoreTarget={scoreTarget}
+ serverScores={scores}
+ configSelection={{ mode: "fixed", configs }}
+ scoreMetadata={{
+ projectId: item.projectId,
+ queueId: item.queueId,
+ environment,
+ }}
+ analyticsData={{
+ type: scoreTarget.type,
+ source: "AnnotationQueue",
+ }}
+ actionButtons={
+ isLockedByOtherUser && isPresent(item.lockedByUser?.name) ? (
+ <div className="flex items-center justify-center rounded-sm border border-dark-red bg-light-red p-1">
+ <TriangleAlertIcon className="mr-1 h-4 w-4 text-dark-red" />
+ <span className="text-xs text-dark-red">
+ Currently edited by {item.lockedByUser.name}
+ </span>
+ </div>
+ ) : undefined
+ }
+ />
</Card>
);
};