import { useMemo, useState } from 'react'; import { OptionTypes } from 'librechat-data-provider'; import type { DynamicSettingProps } from 'librechat-data-provider'; import { Label, HoverCard, HoverCardTrigger, SelectDropDown } from '~/components/ui'; import { useLocalize, useParameterEffects } from '~/hooks'; import { useChatContext } from '~/Providers'; import OptionHover from './OptionHover'; import { ESide } from '~/common'; import { cn } from '~/utils'; function DynamicDropdown({ label = '', settingKey, defaultValue, description = '', columnSpan, setOption, optionType, options, // type: _type, readonly = false, showLabel = true, showDefault = false, labelCode = false, descriptionCode = false, placeholder = '', placeholderCode = false, conversation, }: DynamicSettingProps) { const localize = useLocalize(); const { preset } = useChatContext(); const [inputValue, setInputValue] = useState(null); const selectedValue = useMemo(() => { if (optionType === OptionTypes.Custom) { // TODO: custom logic, add to payload but not to conversation return inputValue; } return conversation?.[settingKey] ?? defaultValue; }, [conversation, defaultValue, optionType, settingKey, inputValue]); const handleChange = (value: string) => { if (optionType === OptionTypes.Custom) { // TODO: custom logic, add to payload but not to conversation setInputValue(value); return; } setOption(settingKey)(value); }; useParameterEffects({ preset, settingKey, defaultValue, conversation, inputValue, setInputValue, preventDelayedUpdate: true, }); if (!options || options.length === 0) { return null; } return (
{showLabel === true && (
)}
{description && ( )}
); } export default DynamicDropdown;