From b3ae29db83e915a142af213378f51978a06fdb6a Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 1 Oct 2025 10:57:06 -0300 Subject: [PATCH] implement custom value when custom is active on model selector --- .../onboarding/components/model-selector.tsx | 247 ++++++++++-------- 1 file changed, 145 insertions(+), 102 deletions(-) diff --git a/frontend/src/app/onboarding/components/model-selector.tsx b/frontend/src/app/onboarding/components/model-selector.tsx index dfed52ee..56244533 100644 --- a/frontend/src/app/onboarding/components/model-selector.tsx +++ b/frontend/src/app/onboarding/components/model-selector.tsx @@ -1,115 +1,158 @@ import { CheckIcon, ChevronsUpDownIcon } from "lucide-react"; import { useEffect, useState } from "react"; +import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { - Command, - CommandEmpty, - CommandGroup, - CommandInput, - CommandItem, - CommandList, + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList, } from "@/components/ui/command"; import { - Popover, - PopoverContent, - PopoverTrigger, + Popover, + PopoverContent, + PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; export function ModelSelector({ - options, - value, - onValueChange, - icon, - placeholder = "Select model...", - searchPlaceholder = "Search model...", - noOptionsPlaceholder = "No models available", + options, + value, + onValueChange, + icon, + placeholder = "Select model...", + searchPlaceholder = "Search model...", + noOptionsPlaceholder = "No models available", + custom = false, }: { - options: { - value: string; - label: string; - default?: boolean; - }[]; - value: string; - icon?: React.ReactNode; - placeholder?: string; - searchPlaceholder?: string; - noOptionsPlaceholder?: string; - onValueChange: (value: string) => void; + options: { + value: string; + label: string; + default?: boolean; + }[]; + value: string; + icon?: React.ReactNode; + placeholder?: string; + searchPlaceholder?: string; + noOptionsPlaceholder?: string; + custom?: boolean; + onValueChange: (value: string) => void; }) { - const [open, setOpen] = useState(false); - useEffect(() => { - if (value && !options.find((option) => option.value === value)) { - onValueChange(""); - } - }, [options, value, onValueChange]); - return ( - - - {/** biome-ignore lint/a11y/useSemanticElements: has to be a Button */} - - - - - - - {noOptionsPlaceholder} - - {options.map((option) => ( - { - if (currentValue !== value) { - onValueChange(currentValue); - } - setOpen(false); - }} - > - -
- {option.label} - {option.default && ( - - Default - - )} -
-
- ))} -
-
-
-
-
- ); + const [open, setOpen] = useState(false); + const [searchValue, setSearchValue] = useState(""); + + useEffect(() => { + if (value && (!options.find((option) => option.value === value) && !custom)) { + onValueChange(""); + } + }, [options, value, custom, onValueChange]); + return ( + + + {/** biome-ignore lint/a11y/useSemanticElements: has to be a Button */} + + + + + + + {noOptionsPlaceholder} + + {options.map((option) => ( + { + if (currentValue !== value) { + onValueChange(currentValue); + } + setOpen(false); + }} + > + +
+ {option.label} + {option.default && ( + + Default + + )} +
+
+ ))} + {custom && + searchValue && + !options.find((option) => option.value === searchValue) && ( + { + if (currentValue !== value) { + onValueChange(currentValue); + } + setOpen(false); + }} + > + +
+ {searchValue} + + Custom + +
+
+ )} +
+
+
+
+
+ ); }