From 42a8e0064f3e4261e99b1a56316da51b8e436349 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:45:29 +0000 Subject: [PATCH] feat: Add prompt history modal --- .../prompts/PromptHistoryDialog.tsx | 205 ++++++++++++++++++ src/pages/Prompts.tsx | 19 +- 2 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 src/components/prompts/PromptHistoryDialog.tsx diff --git a/src/components/prompts/PromptHistoryDialog.tsx b/src/components/prompts/PromptHistoryDialog.tsx new file mode 100644 index 0000000..631f5f4 --- /dev/null +++ b/src/components/prompts/PromptHistoryDialog.tsx @@ -0,0 +1,205 @@ +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Button } from "@/components/ui/button"; +import { Badge } from "@/components/ui/badge"; +import { ScrollArea } from "@/components/ui/scroll-area"; +import { Separator } from "@/components/ui/separator"; +import { GitBranch, Clock, User, FileText, Undo2 } from "lucide-react"; + +interface PromptVersion { + version: string; + type: "major" | "minor" | "patch"; + changeDescription: string; + systemPrompt: string; + createdAt: string; + createdBy: string; +} + +interface PromptHistoryDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + prompt: { + id: number; + title: string; + currentVersion: string; + } | null; +} + +export function PromptHistoryDialog({ open, onOpenChange, prompt }: PromptHistoryDialogProps) { + // Mock data - substituir por dados reais do backend + const versions: PromptVersion[] = [ + { + version: "2.1.0", + type: "minor", + changeDescription: "Adicionado mais empatia nas respostas e incluídos exemplos práticos", + systemPrompt: "Você é Clara, assistente de atendimento ao cliente. Seja empática...", + createdAt: "2 dias atrás", + createdBy: "João Silva", + }, + { + version: "2.0.0", + type: "major", + changeDescription: "Reformulação completa do tom de voz e objetivos principais", + systemPrompt: "Você é Clara, assistente de atendimento ao cliente...", + createdAt: "1 semana atrás", + createdBy: "Maria Santos", + }, + { + version: "1.5.0", + type: "minor", + changeDescription: "Adicionadas instruções sobre política de devolução", + systemPrompt: "Você é um assistente virtual de atendimento...", + createdAt: "2 semanas atrás", + createdBy: "João Silva", + }, + { + version: "1.0.0", + type: "major", + changeDescription: "Versão inicial do prompt", + systemPrompt: "Você é um assistente virtual...", + createdAt: "1 mês atrás", + createdBy: "João Silva", + }, + ]; + + const getVersionTypeColor = (type: string) => { + switch (type) { + case "major": + return "destructive"; + case "minor": + return "default"; + case "patch": + return "secondary"; + default: + return "secondary"; + } + }; + + const getVersionTypeLabel = (type: string) => { + switch (type) { + case "major": + return "Major"; + case "minor": + return "Minor"; + case "patch": + return "Patch"; + default: + return type; + } + }; + + const handleRestore = (version: string) => { + console.log("Restaurar versão:", version, "do prompt:", prompt?.id); + // Implementar lógica de restauração + }; + + if (!prompt) return null; + + return ( + + + + + + Histórico de Versões + + + Histórico completo de versões do prompt "{prompt.title}" + + + + + + {versions.map((version, index) => ( + + + + + {index < versions.length - 1 && ( + + )} + + + + + + + v{version.version} + + + {getVersionTypeLabel(version.type)} + + {version.version === prompt.currentVersion && ( + + Atual + + )} + + {version.version !== prompt.currentVersion && ( + handleRestore(version.version)} + > + + Restaurar + + )} + + + + + + + {version.createdAt} + + + + {version.createdBy} + + + + + + {version.changeDescription} + + + + + ▶ + Ver conteúdo do prompt + + + + {version.systemPrompt} + + + + + + + + ))} + + + + + + + onOpenChange(false)}> + Fechar + + + + + ); +} diff --git a/src/pages/Prompts.tsx b/src/pages/Prompts.tsx index 21ffb70..9619bce 100644 --- a/src/pages/Prompts.tsx +++ b/src/pages/Prompts.tsx @@ -1,6 +1,7 @@ import { useState, useMemo } from "react"; import { CreatePromptDialog } from "@/components/prompts/CreatePromptDialog"; import { EditPromptDialog } from "@/components/prompts/EditPromptDialog"; +import { PromptHistoryDialog } from "@/components/prompts/PromptHistoryDialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Badge } from "@/components/ui/badge"; @@ -34,6 +35,7 @@ const ITEMS_PER_PAGE = 10; export default function Prompts() { const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); const [isEditDialogOpen, setIsEditDialogOpen] = useState(false); + const [isHistoryDialogOpen, setIsHistoryDialogOpen] = useState(false); const [selectedPrompt, setSelectedPrompt] = useState(null); const [searchQuery, setSearchQuery] = useState(""); const [currentPage, setCurrentPage] = useState(1); @@ -131,6 +133,15 @@ export default function Prompts() { setIsEditDialogOpen(true); }; + const handleViewHistory = (prompt: any) => { + setSelectedPrompt({ + id: prompt.id, + title: prompt.title, + currentVersion: prompt.version, + }); + setIsHistoryDialogOpen(true); + }; + return ( @@ -207,7 +218,7 @@ export default function Prompts() { Editar - console.log("History", prompt.id)}> + handleViewHistory(prompt)}> Histórico @@ -293,6 +304,12 @@ export default function Prompts() { onOpenChange={setIsEditDialogOpen} prompt={selectedPrompt} /> + + ); }
+ v{version.version} +
{version.changeDescription}
+ {version.systemPrompt} +