Skip to content

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

fix(ui): polish embedded review controls (#17794)

Nikita Kabardin55b9dfdcc8c0
diff --git a/web/src/components/ui/Button.stories.tsx b/web/src/components/ui/Button.stories.tsx
index 543be4db2c..ab249ceb4e 100644
--- a/web/src/components/ui/Button.stories.tsx
+++ b/web/src/components/ui/Button.stories.tsx
@@ -1,6 +1,6 @@
import React from "react";
import { PlusIcon } from "lucide-react";
-import { fn } from "storybook/test";
+import { expect, fn } from "storybook/test";
import preview from "../../../.storybook/preview";
import { Button, type ButtonProps } from "./button";
@@ -118,3 +118,16 @@ export const VariantMatrix = meta.story({
</div>
),
});
+
+export const KeyboardFocus = meta.story({
+ name: "(Test) Keyboard Focus",
+ args: {
+ children: "Add to",
+ size: "sm",
+ variant: "secondary",
+ },
+ play: async ({ canvas, userEvent }) => {
+ await userEvent.tab();
+ await expect(canvas.getByRole("button", { name: "Add to" })).toHaveFocus();
+ },
+});
diff --git a/web/src/components/ui/button.tsx b/web/src/components/ui/button.tsx
index b4f1957d44..1a5bef0149 100644
--- a/web/src/components/ui/button.tsx
+++ b/web/src/components/ui/button.tsx
@@ -10,7 +10,7 @@ import { Spinner as SpinnerLib } from "@/src/components/design-system/Spinner/Sp
const buttonVariants = cva(
// No font-* here: buttons follow the text-sm token weight (one weight per
// token; heavier text must be an explicit, deliberate exception).
- "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
+ "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm transition-colors focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
{
variants: {
variant: {
diff --git a/web/src/features/scores/components/AnnotationForm.tsx b/web/src/features/scores/components/AnnotationForm.tsx
index 078b5190e0..863d54f663 100644
--- a/web/src/features/scores/components/AnnotationForm.tsx
+++ b/web/src/features/scores/components/AnnotationForm.tsx
@@ -53,25 +53,27 @@ function AnnotateHeader({
}: {
saveStatus: React.ReactNode;
actionButtons: React.ReactNode;
- description: string;
+ description?: string;
}) {
return (
- <Header
- title="Annotate"
- help={{
- description,
- href: "https://langfuse.com/docs/evaluation/evaluation-methods/annotation",
- className: "leading-relaxed",
- }}
- actionButtons={[
- <React.Fragment key="annotation-save-status">
- {saveStatus}
- </React.Fragment>,
- <React.Fragment key="annotation-actions">
- {actionButtons}
- </React.Fragment>,
- ]}
- />
+ <div>
+ <Header
+ title="Annotate"
+ help={
+ description
+ ? {
+ description,
+ href: "https://langfuse.com/docs/evaluation/evaluation-methods/annotation",
+ className: "leading-relaxed",
+ }
+ : undefined
+ }
+ actionButtons={actionButtons}
+ />
+ <div className="-mt-1 flex h-4 items-center justify-end overflow-hidden pr-1">
+ {saveStatus}
+ </div>
+ </div>
);
}
@@ -264,7 +266,7 @@ export function AnnotationFormContent({
{actionButtons}
</>
}
- description={description}
+ description={rowCount > 0 ? description : undefined}
/>
</div>
{/* No real submit: scores save per-field. Prevent the browser's implicit
@@ -274,6 +276,11 @@ export function AnnotationFormContent({
className="flex flex-col gap-4"
onSubmit={(e) => e.preventDefault()}
>
+ {rowCount === 0 ? (
+ <p className="text-muted-foreground max-w-sm text-sm leading-relaxed">
+ {description}
+ </p>
+ ) : null}
<div className="grid grid-flow-row gap-2.5">
{fields.map((field, index) => {
const target = targetFor(field);
diff --git a/web/src/features/scores/components/AnnotationSaveStatus.tsx b/web/src/features/scores/components/AnnotationSaveStatus.tsx
index d71f16caa1..7b5a994ca5 100644
--- a/web/src/features/scores/components/AnnotationSaveStatus.tsx
+++ b/web/src/features/scores/components/AnnotationSaveStatus.tsx
@@ -6,6 +6,7 @@ import type { AnnotationFormActions } from "@/src/features/scores/actions/annota
import type { AnnotateFormSchemaType } from "@/src/features/scores/types";
import { annotationFieldKey } from "@/src/features/scores/lib/annotationConfigSelection";
import { hasChangedAnnotationValue } from "@/src/features/scores/state/annotationSaveStore";
+import { cn } from "@/src/utils/tailwind";
export function AnnotationSaveStatus({
form,
@@ -29,26 +30,40 @@ export function AnnotationSaveStatus({
else if (state.saved && !dirty && !errors.scoreData) status = "saved";
return (
- <>
- {status !== "idle" ? (
- <div
- role="status"
- aria-label="Score save status"
- className="flex items-center justify-end"
- >
- <div className="mr-1 items-center justify-center">
- {status === "saving" ? <Spinner size="xxs" /> : null}
- {status === "saved" ? <Check className="h-3 w-3" /> : null}
+ <div className="grid items-center justify-items-end">
+ {(["saving", "saved", "error"] as const).map((itemStatus) => {
+ const active = status === itemStatus;
+ return (
+ <div
+ key={itemStatus}
+ role={active ? "status" : undefined}
+ aria-label={active ? "Score save status" : undefined}
+ aria-hidden={!active}
+ className={cn(
+ "col-start-1 row-start-1 flex items-center justify-end gap-1 text-xs transition-[opacity,transform] duration-200 ease-out motion-reduce:transition-none",
+ active
+ ? "translate-y-0 opacity-100"
+ : "pointer-events-none -translate-y-0.5 opacity-0",
+ )}
+ >
+ <span className="flex size-3 items-center justify-center">
+ {itemStatus === "saving" && active ? (
+ <Spinner size="xxs" />
+ ) : null}
+ {itemStatus === "saved" ? <Check className="size-3" /> : null}
+ </span>
+ <span className="text-muted-foreground">
+ {
+ {
+ saving: "Saving…",
+ saved: "Saved",
+ error: "Could not save",
+ }[itemStatus]
+ }
+ </span>
</div>
- <span className="text-muted-foreground text-xs">
- {
- { saving: "Saving…", saved: "Saved", error: "Could not save" }[
- status
- ]
- }
- </span>
- </div>
- ) : null}
- </>
+ );
+ })}
+ </div>
);
}
diff --git a/web/src/features/scores/components/AnnotationScoreRow.tsx b/web/src/features/scores/components/AnnotationScoreRow.tsx
index 96f0e2f553..a83715a06d 100644
--- a/web/src/features/scores/components/AnnotationScoreRow.tsx
+++ b/web/src/features/scores/components/AnnotationScoreRow.tsx
@@ -236,7 +236,7 @@ export function AnnotationScoreRow({
role="group"
aria-label={showTarget ? `${score.name} (${target.label})` : score.name}
className={cn(
- "group grid w-full grid-cols-[1fr_2fr] items-center gap-3 rounded-md px-3 py-1 text-left transition-colors outline-none",
+ "group grid w-full grid-cols-[minmax(0,1fr)_minmax(0,2fr)] items-center gap-3 rounded-md py-1 text-left transition-colors outline-none",
"focus-within:ring-primary/30 focus-within:bg-accent/40 focus-within:ring-1 focus-within:ring-inset",
)}
>
diff --git a/web/src/features/scores/components/DualAnnotationContent.clienttest.tsx b/web/src/features/scores/components/DualAnnotationContent.clienttest.tsx
index bc3b7e77b7..1ad21d5b3c 100644
--- a/web/src/features/scores/components/DualAnnotationContent.clienttest.tsx
+++ b/web/src/features/scores/components/DualAnnotationContent.clienttest.tsx
@@ -303,6 +303,17 @@ describe("unified annotation targets", () => {
expect(outside).toHaveFocus();
});
+ it("shows the annotation guidance inline when no scores are selected", () => {
+ localStorage.clear();
+ renderContent();
+
+ expect(
+ screen.getByText(
+ "Annotate the trace and observation with scores to capture human evaluation across different dimensions.",
+ ),
+ ).toBeVisible();
+ });
+
it("suspends score shortcuts while a shared action menu is open", async () => {
mocks.create.mockResolvedValue({});
const view = (menuOpen: boolean) => (
@@ -810,7 +821,7 @@ describe("unified annotation targets", () => {
1,
);
expect(
- screen.queryByText(/Score data saved|^Saved$/),
+ screen.queryByRole("status", { name: "Score save status" }),
).not.toBeInTheDocument();
const observationRow = screen.getByRole("group", {
name: "Quality (Observation)",
@@ -1133,7 +1144,9 @@ describe("unified annotation targets", () => {
).not.toBeInTheDocument();
fireEvent.blur(input);
expect(mocks.update).not.toHaveBeenCalled();
- expect(screen.queryByText("Saved")).not.toBeInTheDocument();
+ expect(
+ screen.queryByRole("status", { name: "Score save status" }),
+ ).not.toBeInTheDocument();
});
it("does not delete a saved score for Firefox badInput and recovers from number and range errors", async () => {
diff --git a/web/src/features/sessions/SessionPages.tsx b/web/src/features/sessions/SessionPages.tsx
index 7d3bbe058e..57a6d54ba1 100644
--- a/web/src/features/sessions/SessionPages.tsx
+++ b/web/src/features/sessions/SessionPages.tsx
@@ -608,7 +608,14 @@ export const SessionPage: React.FC<{
) : (
<>
<MessageSquare className="h-4 w-4" />
- <span>Comments</span>
+ <span>
+ {getNumberFromMap(
+ sessionCommentCounts.data,
+ sessionId,
+ )
+ ? "Comments"
+ : "Comment"}
+ </span>
{getNumberFromMap(
sessionCommentCounts.data,
sessionId,
@@ -734,7 +741,11 @@ export const SessionPage: React.FC<{
) : (
<MessageSquare className="h-4 w-4" />
)}
- <span className="text-sm">Comments</span>
+ <span className="text-sm">
+ {getNumberFromMap(sessionCommentCounts.data, sessionId)
+ ? "Comments"
+ : "Comment"}
+ </span>
{!disabled &&
getNumberFromMap(sessionCommentCounts.data, sessionId) ? (
<ActionButtonCountBadge
@@ -1667,7 +1678,14 @@ const LoadedSessionEventsPage: React.FC<{
) : (
<>
<MessageSquare className="h-4 w-4" />
- <span>Comments</span>
+ <span>
+ {getNumberFromMap(
+ sessionCommentCounts.data,
+ sessionId,
+ )
+ ? "Comments"
+ : "Comment"}
+ </span>
{getNumberFromMap(
sessionCommentCounts.data,
sessionId,
@@ -1826,7 +1844,11 @@ const LoadedSessionEventsPage: React.FC<{
) : (
<MessageSquare className="h-4 w-4" />
)}
- <span className="text-sm">Comments</span>
+ <span className="text-sm">
+ {getNumberFromMap(sessionCommentCounts.data, sessionId)
+ ? "Comments"
+ : "Comment"}
+ </span>
{!disabled &&
getNumberFromMap(sessionCommentCounts.data, sessionId) ? (
<ActionButtonCountBadge
diff --git a/web/src/features/sessions/SessionTraceActionButtons.tsx b/web/src/features/sessions/SessionTraceActionButtons.tsx
index a1e3dc786b..0af8719bef 100644
--- a/web/src/features/sessions/SessionTraceActionButtons.tsx
+++ b/web/src/features/sessions/SessionTraceActionButtons.tsx
@@ -140,7 +140,7 @@ export function SessionTraceActionButtons({
) : (
<>
<MessageSquare className="h-4 w-4" />
- <span>Comments</span>
+ <span>{commentCount ? "Comments" : "Comment"}</span>
{!!commentCount ? (
<ActionButtonCountBadge count={commentCount} />
) : null}
diff --git a/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx b/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx
index f2374ca29c..8a6d124ac0 100644
--- a/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx
+++ b/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx
@@ -102,6 +102,11 @@ export const ObservationDetailViewHeader = memo(
const { isAnnotationMode } = useViewPreferences();
const isMobile = useIsMobile();
const mobileActionsTriggerRef = useRef<HTMLButtonElement>(null);
+ const commentActionLabel = commentCount ? "Comments" : "Comment";
+ const mobileCommentActionLabel =
+ commentCount && !commentDrawerControl.disabled
+ ? `${commentActionLabel} (${commentCount})`
+ : commentActionLabel;
const { isV4: isV4Enabled } = useReadPath();
const { trace, serverScores } = useTraceData();
@@ -276,10 +281,7 @@ export const ObservationDetailViewHeader = memo(
{
type: "item",
id: "comments",
- title:
- !commentDrawerControl.disabled && commentCount
- ? `Comments (${commentCount})`
- : "Comments",
+ title: mobileCommentActionLabel,
icon: commentDrawerControl.disabled
? MessageSquareOff
: MessageSquare,
@@ -427,7 +429,7 @@ export const ObservationDetailViewHeader = memo(
) : (
<>
<MessageSquare className="h-3.5 w-3.5" />
- <span>Comments</span>
+ <span>{commentActionLabel}</span>
{!!commentCount ? (
<ActionButtonCountBadge count={commentCount} />
) : null}
diff --git a/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx b/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
index a232ffd6ca..cd05c037ef 100644
--- a/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
+++ b/web/src/features/traces/components/TraceDetailView/components/TraceDetailViewHeader.tsx
@@ -76,6 +76,11 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
const { isV4 } = useReadPath();
const isMobile = useIsMobile();
const mobileActionsTriggerRef = useRef<HTMLButtonElement>(null);
+ const commentActionLabel = commentCount ? "Comments" : "Comment";
+ const mobileCommentActionLabel =
+ commentCount && !commentDrawerControl.disabled
+ ? `${commentActionLabel} (${commentCount})`
+ : commentActionLabel;
const targetTraceId =
trace.environment === LangfuseInternalTraceEnvironment.LLMJudge
? resolveEvalExecutionMetadata(parsedMetadata)
@@ -187,10 +192,7 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
{
type: "item",
id: "comments",
- title:
- !commentDrawerControl.disabled && commentCount
- ? `Comments (${commentCount})`
- : "Comments",
+ title: mobileCommentActionLabel,
icon: commentDrawerControl.disabled
? MessageSquareOff
: MessageSquare,
@@ -318,7 +320,7 @@ export const TraceDetailViewHeader = memo(function TraceDetailViewHeader({
) : (
<>
<MessageSquare className="h-3.5 w-3.5" />
- <span>Comments</span>
+ <span>{commentActionLabel}</span>
{!!commentCount ? (
<ActionButtonCountBadge count={commentCount} />
) : null}
diff --git a/web/src/features/traces/components/TraceReviewLayout.stories.tsx b/web/src/features/traces/components/TraceReviewLayout.stories.tsx
new file mode 100644
index 0000000000..b0cc164326
--- /dev/null
+++ b/web/src/features/traces/components/TraceReviewLayout.stories.tsx
@@ -0,0 +1,32 @@
+import preview from "../../../../.storybook/preview";
+import { TraceReviewLayout } from "./TraceReviewLayout";
+
+const meta = preview.meta({
+ component: TraceReviewLayout,
+ render: (args) => (
+ <div className="h-[36rem] min-w-[64rem] overflow-hidden border">
+ <TraceReviewLayout {...args} />
+ </div>
+ ),
+});
+
+export const ThreePaneReview = meta.story({
+ args: {
+ open: true,
+ children: ({ collapsed }) => (
+ <div
+ className={
+ collapsed
+ ? "bg-muted/30 h-full p-4"
+ : "grid h-full grid-cols-[22rem_minmax(0,1fr)]"
+ }
+ >
+ {collapsed ? null : (
+ <div className="bg-muted/30 border-r p-4">Trace tree</div>
+ )}
+ <div className="p-4">Observation detail</div>
+ </div>
+ ),
+ review: <div className="h-full p-4">Annotate</div>,
+ },
+});
diff --git a/web/src/features/traces/components/TraceReviewPanel.tsx b/web/src/features/traces/components/TraceReviewPanel.tsx
index 44e3379889..11dd512dea 100644
--- a/web/src/features/traces/components/TraceReviewPanel.tsx
+++ b/web/src/features/traces/components/TraceReviewPanel.tsx
@@ -25,7 +25,7 @@ function CloseReviewPanelButton() {
return (
<Button
variant="ghost"
- size="icon"
+ size="icon-xs"
aria-label="Close side panel"
onClick={() => closeReviewPanel(store, router)}
>