Skip to content

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

chore(evals-ux): Preserve edit mode in URL and add quick 'Edit template' link from evaluator form (#12853)

marliessophiebc7f1c785c0a
diff --git a/web/src/features/evals/components/eval-template-detail.tsx b/web/src/features/evals/components/eval-template-detail.tsx
index 9b2420296f..80bf6d24c4 100644
--- a/web/src/features/evals/components/eval-template-detail.tsx
+++ b/web/src/features/evals/components/eval-template-detail.tsx
@@ -12,7 +12,6 @@ import {
SelectValue,
} from "@/src/components/ui/select";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import { useState } from "react";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import Page from "@/src/components/layouts/page";
import { Switch } from "@/src/components/ui/switch";
@@ -31,8 +30,8 @@ export const EvalTemplateDetail = () => {
const router = useRouter();
const projectId = router.query.projectId as string;
const templateId = router.query.id as string;
-
- const [isEditing, setIsEditing] = useState(false);
+ const mode = router.query.mode;
+ const isEditing = mode === "edit";
// get the current template by id
const template = api.evals.templateById.useQuery({
@@ -64,6 +63,29 @@ export const EvalTemplateDetail = () => {
);
};
+ const setIsEditing = (nextIsEditing: boolean) => {
+ if (!router.isReady) {
+ return;
+ }
+
+ const nextQuery = { ...router.query };
+
+ if (nextIsEditing) {
+ nextQuery.mode = "edit";
+ } else {
+ delete nextQuery.mode;
+ }
+
+ void router.replace(
+ {
+ pathname: router.pathname,
+ query: nextQuery,
+ },
+ undefined,
+ { shallow: true },
+ );
+ };
+
return (
<Page
headerProps={{
diff --git a/web/src/features/evals/components/eval-templates-table.tsx b/web/src/features/evals/components/eval-templates-table.tsx
index 26812c78df..35bf17c4ce 100644
--- a/web/src/features/evals/components/eval-templates-table.tsx
+++ b/web/src/features/evals/components/eval-templates-table.tsx
@@ -84,6 +84,7 @@ export default function EvalsTemplateTable({
const [pendingCloneSubmission, setPendingCloneSubmission] = useState<
RouterInput["evals"]["createTemplate"] | null
>(null);
+
const utils = api.useUtils();
const templates = api.evals.templateNames.useQuery({
projectId,
diff --git a/web/src/features/evals/components/variable-mapping-card.tsx b/web/src/features/evals/components/variable-mapping-card.tsx
index 1106621b20..4b67639782 100644
--- a/web/src/features/evals/components/variable-mapping-card.tsx
+++ b/web/src/features/evals/components/variable-mapping-card.tsx
@@ -47,8 +47,10 @@ import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNa
import { useEvalConfigMappingData } from "@/src/features/evals/hooks/useEvalConfigMappingData";
import { useEffect, useState } from "react";
import { Alert, AlertTitle, AlertDescription } from "@/src/components/ui/alert";
-import { AlertCircle } from "lucide-react";
+import { AlertCircle, ExternalLink } from "lucide-react";
import { useVariableMappingSync } from "@/src/features/evals/hooks/useVariableMappingSync";
+import { Button } from "@/src/components/ui/button";
+import Link from "next/link";
export const VariableMappingCard = ({
projectId,
@@ -149,8 +151,32 @@ export const VariableMappingCard = ({
return (
<Card className="max-w-full min-w-0 p-4">
- <div className="mb-2 flex items-center justify-between">
+ <div className="mb-2 flex items-center gap-2">
<span className="text-lg font-medium">Variable mapping</span>
+ <div className="flex flex-wrap items-center justify-between gap-2">
+ {evalTemplate.projectId ? (
+ <Button asChild variant="outline" size="sm">
+ <Link
+ href={`/project/${projectId}/evals/templates/${evalTemplate.id}?mode=edit`}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ Edit prompt
+ <ExternalLink className="ml-1 h-4 w-4" />
+ </Link>
+ </Button>
+ ) : (
+ <Button
+ variant="outline"
+ size="sm"
+ disabled
+ title="Only user-managed templates can be edited"
+ >
+ Edit prompt
+ <ExternalLink className="h-4 w-4" />
+ </Button>
+ )}
+ </div>
</div>
{isTraceTarget(form.watch("target")) && !disabled && (
<FormDescription>