Skip to content

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

feat(prompts): scroll selected prompt version into view (#5293)

Marc Klingen22371b4c323e
diff --git a/web/src/components/trace/ObservationTree.tsx b/web/src/components/trace/ObservationTree.tsx
index b627e7ae7e..7e634f17a8 100644
--- a/web/src/components/trace/ObservationTree.tsx
+++ b/web/src/components/trace/ObservationTree.tsx
@@ -309,6 +309,7 @@ const ObservationTreeNodeCard = ({
) {
currentObservationRef.current.scrollIntoView({
behavior: "smooth",
+ block: "center",
});
}
// Should only trigger a single time on initial render
diff --git a/web/src/features/prompts/components/prompt-history.tsx b/web/src/features/prompts/components/prompt-history.tsx
index ed079eb162..f09251ee8b 100644
--- a/web/src/features/prompts/components/prompt-history.tsx
+++ b/web/src/features/prompts/components/prompt-history.tsx
@@ -4,7 +4,7 @@ import { SetPromptVersionLabels } from "@/src/features/prompts/components/SetPro
import { PRODUCTION_LABEL } from "@/src/features/prompts/constants";
import { type RouterOutputs } from "@/src/utils/api";
import { type NextRouter, useRouter } from "next/router";
-import { useState } from "react";
+import { useState, useRef, useEffect } from "react";
import { PromptVersionDiffDialog } from "./PromptVersionDiffDialog";
const PromptHistoryTraceNode = (props: {
@@ -21,6 +21,26 @@ const PromptHistoryTraceNode = (props: {
const [isLabelPopoverOpen, setIsLabelPopoverOpen] = useState(false);
const [isPromptDiffOpen, setIsPromptDiffOpen] = useState(false);
const { prompt } = props;
+
+ // Add ref for scroll into view
+ const currentPromptRef = useRef<HTMLDivElement>(null);
+
+ // Add useEffect for scroll into view behavior
+ useEffect(() => {
+ if (
+ props.currentPromptVersion &&
+ currentPromptRef.current &&
+ props.currentPromptVersion === prompt.version
+ ) {
+ currentPromptRef.current.scrollIntoView({
+ behavior: "smooth",
+ block: "center",
+ });
+ }
+ // Should only trigger a single time on initial render
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [currentPromptRef.current]);
+
let badges: JSX.Element[] = prompt.labels
.sort((a, b) =>
a === PRODUCTION_LABEL
@@ -41,6 +61,7 @@ const PromptHistoryTraceNode = (props: {
return (
<div
+ ref={currentPromptRef}
className={`group mb-2 flex w-full cursor-pointer flex-col gap-1 rounded-sm p-2 hover:bg-primary-foreground ${
props.currentPromptVersion === prompt.version ? "bg-muted" : ""
}`}