import * as React from "react"; import { EvalTemplateForm } from "@/src/features/evals/components/template-form"; import { api } from "@/src/utils/api"; import { type EvalTemplate } from "@langfuse/shared"; import { useRouter } from "next/router"; import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, 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"; import { Command } from "@/src/components/ui/command"; import { Badge } from "@/src/components/ui/badge"; import { StatusBadge } from "@/src/components/layouts/status-badge"; import { SidePanel, SidePanelContent, SidePanelHeader, SidePanelTitle, } from "@/src/components/ui/side-panel"; import { LangfuseIcon } from "@/src/components/LangfuseLogo"; 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); // get the current template by id const template = api.evals.templateById.useQuery({ projectId: projectId, id: templateId, }); // get all templates for the current template name const allTemplates = api.evals.allTemplatesForName.useQuery( { projectId: projectId, name: template.data?.name ?? "", isUserManaged: template.data?.projectId !== null, }, { enabled: !template.isPending && !template.isError && template.data?.name !== undefined, }, ); const handleTemplateSelect = (newTemplate: EvalTemplate) => { // Update URL without full page reload router.push( `/project/${projectId}/evals/templates/${newTemplate.id}`, undefined, { shallow: true }, ); }; return ( {/* TODO: moved to LFE-4573 */} {/* */} ), }} > {allTemplates.isLoading || !allTemplates.data || !template.data ? (
Loading...
) : isEditing ? (
) : (
Change history
{allTemplates.data.templates.map((template, index) => (
handleTemplateSelect(template)} >
{ e.stopPropagation(); }} variant="outline" className="h-6 shrink-0 bg-background/50" data-version-trigger="false" > # {template.version} {index === 0 && ( )}
{template.createdAt.toLocaleDateString()}
))}
)}
); }; export function EvalVersionDropdown(props: { disabled: boolean; options?: EvalTemplate[]; defaultOption?: EvalTemplate; onSelect?: (template: EvalTemplate) => void; }) { const capture = usePostHogClientCapture(); const handleSelect = (value: string) => { const selectedTemplate = props.options?.find( (template) => template.id === value, ); if (selectedTemplate && props.onSelect) { props.onSelect(selectedTemplate); capture("eval_templates:view_version"); } }; return ( ); } export function UpdateTemplate({ projectId, isEditing, setIsEditing, isCustom, }: { projectId: string; isEditing: boolean; setIsEditing: (isEditing: boolean) => void; isCustom: boolean; }) { const hasAccess = useHasProjectAccess({ projectId, scope: "evalTemplate:CUD", }); const capture = usePostHogClientCapture(); const handlePromptEdit = (checked: boolean) => { setIsEditing(checked); if (checked) capture("eval_templates:update_form_open"); }; if (!isCustom) { return (
View only
); } return (
Edit mode
); }