feat: Add tooltips to template attributes
Some checks failed
Build static content / build (push) Has been cancelled

This commit is contained in:
2025-05-30 18:50:21 +08:00
parent 7694ed6792
commit d830b92fbf

View File

@@ -1,5 +1,12 @@
import { useState } from "react"; import { useState } from "react";
import { ChatStore } from "@/types/chatstore"; import { ChatStore } from "@/types/chatstore";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
@@ -31,7 +38,9 @@ export function TemplateAttributeDialog({
langCode, langCode,
}: TemplateAttributeDialogProps) { }: TemplateAttributeDialogProps) {
// Create a map of all ChatStore attributes and their selection state // Create a map of all ChatStore attributes and their selection state
const [selectedAttributes, setSelectedAttributes] = useState<Record<string, boolean>>(() => { const [selectedAttributes, setSelectedAttributes] = useState<
Record<string, boolean>
>(() => {
const initial: Record<string, boolean> = {}; const initial: Record<string, boolean> = {};
// Initialize all attributes as selected by default // Initialize all attributes as selected by default
Object.keys(chatStore).forEach((key) => { Object.keys(chatStore).forEach((key) => {
@@ -71,13 +80,31 @@ export function TemplateAttributeDialog({
setSelectedAttributes(newSelected); setSelectedAttributes(newSelected);
}; };
const formatValue = (value: any): string => {
if (value === null || value === undefined) return "null";
if (typeof value === "object") {
if (Array.isArray(value)) {
return `[${value.length} items]`;
}
return "{...}";
}
if (typeof value === "string") {
if (value.length > 50) {
return value.substring(0, 47) + "...";
}
return value;
}
return String(value);
};
return ( return (
<Dialog open={open} onOpenChange={onClose}> <Dialog open={open} onOpenChange={onClose}>
<DialogContent className="max-w-2xl"> <DialogContent className="max-w-2xl">
<DialogHeader> <DialogHeader>
<DialogTitle>Select Template Attributes</DialogTitle> <DialogTitle>Select Template Attributes</DialogTitle>
<DialogDescription> <DialogDescription>
Choose which attributes to include in your template. Unselected attributes will be omitted. Choose which attributes to include in your template. Unselected
attributes will be omitted.
</DialogDescription> </DialogDescription>
</DialogHeader> </DialogHeader>
@@ -93,9 +120,7 @@ export function TemplateAttributeDialog({
}} }}
placeholder={tr("Enter template name", langCode)} placeholder={tr("Enter template name", langCode)}
/> />
{nameError && ( {nameError && <p className="text-sm text-red-500">{nameError}</p>}
<p className="text-sm text-red-500">{nameError}</p>
)}
</div> </div>
<div className="flex items-center space-x-2"> <div className="flex items-center space-x-2">
@@ -108,7 +133,7 @@ export function TemplateAttributeDialog({
</div> </div>
<ScrollArea className="h-[400px] rounded-md border p-4"> <ScrollArea className="h-[400px] rounded-md border p-4">
<div className="grid grid-cols-2 gap-4"> <div className="grid grid-cols-1 gap-4">
{Object.keys(chatStore).map((key) => ( {Object.keys(chatStore).map((key) => (
<div key={key} className="flex items-center space-x-2"> <div key={key} className="flex items-center space-x-2">
<Checkbox <Checkbox
@@ -121,9 +146,29 @@ export function TemplateAttributeDialog({
})) }))
} }
/> />
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div className="flex flex-col">
<Label htmlFor={key} className="text-sm"> <Label htmlFor={key} className="text-sm">
{key} {key}
</Label> </Label>
<span className="text-xs text-muted-foreground">
{formatValue(chatStore[key as keyof ChatStore])}
</span>
</div>
</TooltipTrigger>
<TooltipContent>
<p className="max-w-xs break-words">
{JSON.stringify(
chatStore[key as keyof ChatStore],
null,
2
)}
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div> </div>
))} ))}
</div> </div>