🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore(ui): Replace select with combobox for annotations (#9910)
Michael Fröhlichfb13b386ba27
diff --git a/web/src/components/ui/combobox.tsx b/web/src/components/ui/combobox.tsxnew file mode 100644index 0000000000..43df8fe55d--- /dev/null+++ b/web/src/components/ui/combobox.tsx@@ -0,0 +1,138 @@+"use client";++import * as React from "react";+import { Check, ChevronsUpDown } from "lucide-react";++import { cn } from "@/src/utils/tailwind";+import { Button } from "@/src/components/ui/button";+import {+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+} from "@/src/components/ui/command";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+} from "@/src/components/ui/popover";++export interface ComboboxOption<+ T extends string | number | boolean | { id: string },+> {+ value: T;+ label?: string;+ disabled?: boolean;+}+export interface ComboboxProps<+ T extends string | number | boolean | { id: string },+> {+ options: ComboboxOption<T>[];+ value?: T;+ onValueChange?: (value: T) => void;+ placeholder?: string;+ emptyText?: string;+ searchPlaceholder?: string;+ disabled?: boolean;+ className?: string;+ name?: string;+}++export function Combobox<T extends string | number | boolean | { id: string }>({+ options,+ value,+ onValueChange,+ placeholder = "Select option...",+ emptyText = "No option found.",+ searchPlaceholder = "Search...",+ disabled = false,+ className,+ name,+}: ComboboxProps<T>) {+ const [open, setOpen] = React.useState(false);++ const isEqual = (a: T | undefined, b: T | undefined) => {+ if (+ a &&+ b &&+ typeof a === "object" &&+ typeof b === "object" &&+ "id" in a &&+ "id" in b+ ) {+ return (a as { id: string }).id === (b as { id: string }).id;+ }+ return a === b;+ };++ const selectedOption = options.find((option) => isEqual(option.value, value));++ return (+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger asChild>+ <Button+ variant="outline"+ role="combobox"+ aria-expanded={open}+ className={cn(+ "w-full justify-between text-xs font-normal",+ !value && "text-muted-foreground",+ className,+ )}+ disabled={disabled}+ name={name}+ >+ <span className="truncate">+ {selectedOption+ ? (selectedOption.label ?? String(selectedOption.value))+ : placeholder}+ </span>+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />+ </Button>+ </PopoverTrigger>+ <PopoverContent className="w-[var(--radix-popover-trigger-width)] p-0">+ <Command>+ <CommandInput placeholder={searchPlaceholder} className="text-xs" />+ <CommandList>+ <CommandEmpty>{emptyText}</CommandEmpty>+ <CommandGroup>+ {options.map((option) => (+ <CommandItem+ key={+ typeof option.value === "object"+ ? (option.value as { id: string }).id+ : String(option.value)+ }+ value={option.label ?? String(option.value)}+ disabled={option.disabled}+ onSelect={() => {+ if (!option.disabled && onValueChange) {+ onValueChange(option.value as T);+ setOpen(false);+ }+ }}+ className={cn(+ "text-xs",+ option.disabled && "text-muted-foreground line-through",+ )}+ >+ <Check+ className={cn(+ "mr-2 h-4 w-4",+ isEqual(value as T | undefined, option.value)+ ? "opacity-100"+ : "opacity-0",+ )}+ />+ {option.label ?? String(option.value)}+ </CommandItem>+ ))}+ </CommandGroup>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover>+ );+}diff --git a/web/src/components/ui/command.tsx b/web/src/components/ui/command.tsxindex ba1c877889..f0ee241c95 100644--- a/web/src/components/ui/command.tsx+++ b/web/src/components/ui/command.tsx@@ -65,16 +65,16 @@ const CommandInput = React.forwardRef<>(({ className, showBorder = true, ...props }, ref) => (<divclassName={cn(- "flex items-center",- showBorder && "border-b px-3",+ "relative flex items-center p-1",+ showBorder && "border-b","cmdk-input-wrapper",)}>- <Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />+ <Search className="absolute left-2 top-1/2 mr-2 h-3.5 w-3.5 shrink-0 -translate-y-1/2 opacity-50" /><CommandPrimitive.Inputref={ref}className={cn(- "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",+ "flex h-8 w-full rounded-md bg-transparent px-6 py-3 text-sm outline-none placeholder:text-muted-foreground focus:outline-none focus:ring-0 disabled:cursor-not-allowed disabled:opacity-50",className,)}{...props}diff --git a/web/src/features/scores/components/AnnotationForm.tsx b/web/src/features/scores/components/AnnotationForm.tsxindex a9906cf685..93f09cde24 100644--- a/web/src/features/scores/components/AnnotationForm.tsx+++ b/web/src/features/scores/components/AnnotationForm.tsx@@ -33,13 +33,7 @@ import {PopoverContent,PopoverTrigger,} from "@/src/components/ui/popover";-import {- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,-} from "@/src/components/ui/select";+import { Combobox } from "@/src/components/ui/combobox";import { Textarea } from "@/src/components/ui/textarea";import { HoverCardContent } from "@radix-ui/react-hover-card";import { HoverCard, HoverCardTrigger } from "@/src/components/ui/hover-card";@@ -586,7 +580,7 @@ function InnerAnnotationForm<Target extends ScoreTarget>({render={({ field }) => (<FormItem><FormControl>- <Select+ <Comboboxname={field.name}value={field.value ?? ""}disabled={isInputDisabled(config)}@@ -594,35 +588,14 @@ function InnerAnnotationForm<Target extends ScoreTarget>({field.onChange(value);handleCategoricalUpsert(index, value);}}- >- <SelectTrigger>- <div className="text-xs">- <SelectValue placeholder="Select category" />- </div>- </SelectTrigger>- <SelectContent>- {categories.map((category) =>- category.isOutdated ? (- <SelectItem- key={category.value}- value={category.label}- disabled- className="text-muted-foreground line-through"- >- {category.label}- </SelectItem>- ) : (- <SelectItem- key={category.value}- value={category.label}- className="text-xs"- >- {category.label}- </SelectItem>- ),- )}- </SelectContent>- </Select>+ options={categories.map((category) => ({+ value: category.label,+ disabled: category.isOutdated,+ }))}+ placeholder="Select category"+ searchPlaceholder="Search categories..."+ emptyText="No category found."+ /></FormControl><FormMessage className="text-xs" /></FormItem>