Skip to content

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

style(prompts): actions on hover (#3135)

marliessophiec39279f677dc
diff --git a/web/src/components/trace/ObservationPreview.tsx b/web/src/components/trace/ObservationPreview.tsx
index b07d8d95e2..0caf2f6b7c 100644
--- a/web/src/components/trace/ObservationPreview.tsx
+++ b/web/src/components/trace/ObservationPreview.tsx
@@ -186,7 +186,6 @@ export const ObservationPreview = (props: {
source="generation"
generation={observationWithInputAndOutput.data}
analyticsEventName="trace_detail:test_in_playground_button_click"
- fullWidth
/>
)}
{observationWithInputAndOutput.data ? (
diff --git a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
index 3b641fda42..690610207e 100644
--- a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
+++ b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
@@ -32,7 +32,7 @@ type JumpToPlaygroundButtonProps = (
analyticsEventName: "trace_detail:test_in_playground_button_click";
}
) & {
- fullWidth?: boolean;
+ variant?: "outline" | "secondary";
};
export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (
@@ -61,17 +61,14 @@ export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (
return (
<Button
- variant={props.fullWidth ? "secondary" : "outline"}
+ variant={props.variant ?? "secondary"}
title="Test in LLM playground"
- size={!props.fullWidth ? "icon" : undefined}
onClick={handleClick}
asChild
>
<Link href={`/project/${projectId}/playground`}>
<Terminal className="h-4 w-4" />
- {props.fullWidth ? (
- <span className="ml-2">Test in playground</span>
- ) : null}
+ <span className="ml-2">Test in playground</span>
</Link>
</Button>
);
diff --git a/web/src/features/prompts/components/SetPromptVersionLabels/index.tsx b/web/src/features/prompts/components/SetPromptVersionLabels/index.tsx
index fbf622fec4..4d799c02c2 100644
--- a/web/src/features/prompts/components/SetPromptVersionLabels/index.tsx
+++ b/web/src/features/prompts/components/SetPromptVersionLabels/index.tsx
@@ -83,8 +83,6 @@ export function SetPromptVersionLabels({ prompt }: { prompt: Prompt }) {
setIsOpen(false);
};
- if (!hasAccess) return null;
-
return (
<Popover
key={prompt.id}
@@ -98,8 +96,10 @@ export function SetPromptVersionLabels({ prompt }: { prompt: Prompt }) {
<Button
variant="outline"
size="icon"
+ className="h-7 w-7 px-0"
aria-label="Set prompt labels"
title="Set prompt labels"
+ disabled={!hasAccess}
>
<TagIcon className="h-4 w-4" />
</Button>
@@ -160,7 +160,7 @@ export function SetPromptVersionLabels({ prompt }: { prompt: Prompt }) {
) : (
<Button
variant="ghost"
- className="mt-2 w-full justify-start px-2 py-1 text-sm font-normal"
+ className="mt-2 w-full justify-start px-2 py-1 text-sm font-normal"
onClick={() => setIsAddingLabel(true)}
>
<PlusIcon className="mr-2 h-4 w-4" />
diff --git a/web/src/features/prompts/components/delete-prompt-version.tsx b/web/src/features/prompts/components/delete-prompt-version.tsx
index 263d136b8a..c0fbb5d111 100644
--- a/web/src/features/prompts/components/delete-prompt-version.tsx
+++ b/web/src/features/prompts/components/delete-prompt-version.tsx
@@ -62,6 +62,7 @@ export function DeletePromptVersion({
variant="outline"
type="button"
size="icon"
+ className="h-7 w-7 px-0"
disabled={!hasAccess}
>
<Trash className="h-4 w-4" />
diff --git a/web/src/features/prompts/components/prompt-detail.tsx b/web/src/features/prompts/components/prompt-detail.tsx
index b5b27b797c..4961075322 100644
--- a/web/src/features/prompts/components/prompt-detail.tsx
+++ b/web/src/features/prompts/components/prompt-detail.tsx
@@ -1,4 +1,3 @@
-import { Pencil } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/router";
import { NumberParam, useQueryParam } from "use-query-params";
@@ -7,10 +6,8 @@ import Header from "@/src/components/layouts/header";
import { OpenAiMessageView } from "@/src/components/trace/IOPreview";
import { Tabs, TabsList, TabsTrigger } from "@/src/components/ui/tabs";
import { Badge } from "@/src/components/ui/badge";
-import { Button } from "@/src/components/ui/button";
import { CodeView, JSONView } from "@/src/components/ui/CodeJsonViewer";
import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNav";
-import { DeletePromptVersion } from "@/src/features/prompts/components/delete-prompt-version";
import { PromptType } from "@/src/features/prompts/server/utils/validation";
import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";
import { api } from "@/src/utils/api";
@@ -18,7 +15,6 @@ import { extractVariables } from "@/src/utils/string";
import { ScrollArea } from "@radix-ui/react-scroll-area";
import { TagPromptDetailsPopover } from "@/src/features/tag/components/TagPromptDetailsPopover";
import { PromptHistoryNode } from "./prompt-history";
-import { SetPromptVersionLabels } from "@/src/features/prompts/components/SetPromptVersionLabels";
import Generations from "@/src/components/table/use-cases/generations";
import {
Accordion,
@@ -26,14 +22,12 @@ import {
AccordionItem,
AccordionTrigger,
} from "@/src/components/ui/accordion";
-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { JumpToPlaygroundButton } from "@/src/ee/features/playground/page/components/JumpToPlaygroundButton";
import { ChatMlArraySchema } from "@/src/components/schemas/ChatMlSchema";
import { CommentList } from "@/src/features/comments/CommentList";
export const PromptDetail = () => {
const projectId = useProjectIdFromURL();
- const capture = usePostHogClientCapture();
const promptName = decodeURIComponent(useRouter().query.promptName as string);
const [currentPromptVersion, setCurrentPromptVersion] = useQueryParam(
"version",
@@ -107,31 +101,11 @@ export const PromptDetail = () => {
]}
actionButtons={
<>
- <SetPromptVersionLabels prompt={prompt} />
-
<JumpToPlaygroundButton
source="prompt"
prompt={prompt}
analyticsEventName="prompt_detail:test_in_playground_button_click"
- />
-
- <Button
variant="outline"
- size="icon"
- onClick={() => capture("prompts:update_form_open")}
- asChild
- >
- <Link
- href={`/project/${projectId}/prompts/new?promptId=${encodeURIComponent(prompt.id)}`}
- >
- <Pencil className="h-4 w-4" />
- </Link>
- </Button>
-
- <DeletePromptVersion
- promptVersionId={prompt.id}
- version={prompt.version}
- countVersions={promptHistory.data.totalCount}
/>
<DetailPageNav
key="nav"
@@ -242,6 +216,7 @@ export const PromptDetail = () => {
prompts={promptHistory.data.promptVersions}
currentPromptVersion={prompt.version}
setCurrentPromptVersion={setCurrentPromptVersion}
+ totalCount={promptHistory.data.totalCount}
/>
</ScrollArea>
</div>
diff --git a/web/src/features/prompts/components/prompt-history.tsx b/web/src/features/prompts/components/prompt-history.tsx
index ca131811a4..c90ba76e2f 100644
--- a/web/src/features/prompts/components/prompt-history.tsx
+++ b/web/src/features/prompts/components/prompt-history.tsx
@@ -1,7 +1,15 @@
import { StatusBadge } from "@/src/components/layouts/status-badge";
+import { Button } from "@/src/components/ui/button";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
+import { DeletePromptVersion } from "@/src/features/prompts/components/delete-prompt-version";
+import { SetPromptVersionLabels } from "@/src/features/prompts/components/SetPromptVersionLabels";
import { PRODUCTION_LABEL } from "@/src/features/prompts/constants";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import { type RouterOutputs } from "@/src/utils/api";
+import { Pencil, PencilOff } from "lucide-react";
+import Link from "next/link";
import { type NextRouter, useRouter } from "next/router";
+import { useState } from "react";
const PromptHistoryTraceNode = (props: {
index: number;
@@ -10,7 +18,14 @@ const PromptHistoryTraceNode = (props: {
setCurrentPromptVersion: (version: number | undefined) => void;
router: NextRouter;
projectId: string;
+ totalCount: number;
}) => {
+ const capture = usePostHogClientCapture();
+ const [isHovered, setIsHovered] = useState(false);
+ const hasAccess = useHasProjectAccess({
+ projectId: props.projectId,
+ scope: "prompts:CUD",
+ });
const { prompt } = props;
let badges: JSX.Element[] = prompt.labels
.sort((a, b) =>
@@ -21,7 +36,7 @@ const PromptHistoryTraceNode = (props: {
: a.localeCompare(b),
)
.map((label) => {
- return <StatusBadge type={label} key={label} />;
+ return <StatusBadge type={label} key={label} className="h-6" />;
});
return (
@@ -29,19 +44,63 @@ const PromptHistoryTraceNode = (props: {
className={`group mb-2 flex cursor-pointer flex-col gap-1 rounded-sm p-2 hover:bg-primary-foreground ${
props.currentPromptVersion === prompt.version ? "bg-muted" : ""
}`}
+ onMouseEnter={() => setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
onClick={() => {
props.index === 0
? props.setCurrentPromptVersion(undefined)
: props.setCurrentPromptVersion(prompt.version);
}}
>
- <div className="flex flex-wrap items-center gap-2">
- <span className="rounded-sm bg-input p-1 text-xs">
- Version {prompt.version}
- </span>
- {badges}
+ <div className="grid grid-cols-[auto,1fr] items-start gap-2">
+ <div
+ className={`grid grid-cols-[auto,1fr] items-start ${isHovered ? "h-full" : "h-7"}`}
+ >
+ <span className="flex h-6 text-nowrap rounded-sm bg-input p-1 text-xs">
+ Version {prompt.version}
+ </span>
+ {Boolean(prompt.labels.length) && (
+ <div className="ml-2 flex h-full flex-wrap gap-1 overflow-auto">
+ {badges}
+ </div>
+ )}
+ </div>
+ {isHovered && (
+ <div className="flex flex-row space-x-1">
+ <SetPromptVersionLabels prompt={prompt} />
+ {hasAccess ? (
+ <Button
+ variant="outline"
+ size="icon"
+ className="h-7 w-7 px-0"
+ onClick={() => {
+ capture("prompts:update_form_open");
+ }}
+ >
+ <Link
+ href={`/project/${props.projectId}/prompts/new?promptId=${encodeURIComponent(prompt.id)}`}
+ >
+ <Pencil className="h-4 w-4" />
+ </Link>
+ </Button>
+ ) : (
+ <Button
+ variant="outline"
+ size="icon"
+ className="h-7 w-7 px-0"
+ disabled
+ >
+ <PencilOff className="h-4 w-4" />
+ </Button>
+ )}
+ <DeletePromptVersion
+ promptVersionId={prompt.id}
+ version={prompt.version}
+ countVersions={props.totalCount}
+ />
+ </div>
+ )}
</div>
-
<div className="flex gap-2">
<span className="text-xs text-muted-foreground">
{prompt.createdAt.toLocaleString()}
@@ -60,6 +119,7 @@ export const PromptHistoryNode = (props: {
prompts: RouterOutputs["prompts"]["allVersions"]["promptVersions"];
currentPromptVersion: number | undefined;
setCurrentPromptVersion: (id: number | undefined) => void;
+ totalCount: number;
}) => {
const router = useRouter();
const projectId = router.query.projectId as string;
@@ -74,6 +134,7 @@ export const PromptHistoryNode = (props: {
setCurrentPromptVersion={props.setCurrentPromptVersion}
router={router}
projectId={projectId}
+ totalCount={props.totalCount}
/>
))}
</div>