import TagCommandItem from "@/src/features/tag/components/TagCommandItem"; import TagCreateItem from "@/src/features/tag/components/TagCreateItem"; import { TagInput } from "@/src/features/tag/components/TagInput"; import TagList from "@/src/features/tag/components/TagList"; import { useTagManager } from "@/src/features/tag/hooks/useTagManager"; import { Popover, PopoverTrigger, PopoverContent, } from "@/src/components/ui/popover"; import { Command, CommandList, CommandGroup } from "cmdk"; import { cn } from "@/src/utils/tailwind"; import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture"; import { Label } from "@/src/components/ui/label"; type TagManagerProps = { itemName: "prompt" | "trace"; tags: string[]; allTags: string[]; hasAccess: boolean; isLoading: boolean; mutateTags: (value: string[]) => void; className?: string; isTableCell?: boolean; allowTagRemoval?: boolean; }; const TagManager = ({ itemName, tags, allTags, hasAccess, isLoading, mutateTags, className, isTableCell = false, allowTagRemoval = true, }: TagManagerProps) => { const { selectedTags, inputValue, availableTags, handleItemCreate, setInputValue, setSelectedTags, } = useTagManager({ initialTags: tags, allTags }); const capture = usePostHogClientCapture(); const filteredTags = availableTags.filter( (value) => value.toLowerCase().includes(inputValue.trim().toLowerCase()) && !selectedTags.includes(value), ); const handlePopoverChange = (open: boolean) => { if (open) { capture("tag:modal_open"); } if (!open && selectedTags !== tags) { setInputValue(""); mutateTags(selectedTags); } }; if (!hasAccess) { return (
); } return ( handlePopoverChange(open)}> { if (isTableCell) { e.stopPropagation(); } }} >
{ if (isTableCell) { e.stopPropagation(); } }} onKeyDown={(e) => { if (isTableCell) { e.stopPropagation(); } }} > 0 ? "Available Tags" : ""} className={cn( "mt-2 max-h-52 overflow-auto text-sm font-medium [&>[cmdk-group-heading]]:mb-2", filteredTags.length > 0 && "mb-2", )} > {filteredTags.slice(0, 20).map((value: string) => ( ))}
); }; export default TagManager;