mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
🧹 chore: pre-release cleanup 2 (#3600)
* refactor: scrollToEnd * fix(validateConvoAccess): search conversation by ID for proper validation * feat: Add unique index for conversationId and user in convoSchema * refactor: Update font sizes 1 rem -> font-size-base in style.css * fix: Assistants map type issues * refactor: Remove obsolete scripts * fix: Update DropdownNoState component to handle both string and OptionType values * refactor: Remove config/loader.js file * fix: remove crypto.randomBytes(); refactor: Create reusable function for generating token and hash
This commit is contained in:
parent
6fead1005b
commit
1ff4841603
20 changed files with 172 additions and 637 deletions
|
|
@ -15,9 +15,9 @@ type OptionType = {
|
|||
};
|
||||
|
||||
interface DropdownProps {
|
||||
value: string;
|
||||
value: string | OptionType;
|
||||
label?: string;
|
||||
onChange: (value: string) => void;
|
||||
onChange: (value: string) => void | ((value: OptionType) => void);
|
||||
options: (string | OptionType)[];
|
||||
className?: string;
|
||||
anchor?: AnchorPropsWithSelection;
|
||||
|
|
@ -35,14 +35,19 @@ const Dropdown: FC<DropdownProps> = ({
|
|||
sizeClasses,
|
||||
testId = 'dropdown-menu',
|
||||
}) => {
|
||||
const getValue = (option: string | OptionType): string =>
|
||||
typeof option === 'string' ? option : option.value;
|
||||
|
||||
const getDisplay = (option: string | OptionType): string =>
|
||||
typeof option === 'string' ? option : (option.display ?? '') || option.value;
|
||||
|
||||
const selectedOption = options.find((option) => getValue(option) === getValue(value));
|
||||
|
||||
const displayValue = selectedOption != null ? getDisplay(selectedOption) : getDisplay(value);
|
||||
|
||||
return (
|
||||
<div className={cn('relative', className)}>
|
||||
<Listbox
|
||||
value={value}
|
||||
onChange={(newValue) => {
|
||||
onChange(newValue);
|
||||
}}
|
||||
>
|
||||
<Listbox value={value} onChange={onChange}>
|
||||
<div className={cn('relative', className)}>
|
||||
<ListboxButton
|
||||
data-testid={testId}
|
||||
|
|
@ -55,9 +60,7 @@ const Dropdown: FC<DropdownProps> = ({
|
|||
>
|
||||
<span className="block truncate">
|
||||
{label}
|
||||
{options
|
||||
.map((o) => (typeof o === 'string' ? { value: o, display: o } : o))
|
||||
.find((o) => o.value === value)?.display || value}
|
||||
{displayValue}
|
||||
</span>
|
||||
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
|
||||
<svg
|
||||
|
|
@ -79,7 +82,7 @@ const Dropdown: FC<DropdownProps> = ({
|
|||
>
|
||||
<ListboxOptions
|
||||
className={cn(
|
||||
'absolute z-50 mt-1 flex flex-col items-start gap-1 overflow-auto rounded-lg border border-gray-300 bg-white bg-white p-1.5 text-gray-700 shadow-lg transition-opacity focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-white',
|
||||
'absolute z-50 mt-1 flex flex-col items-start gap-1 overflow-auto rounded-lg border border-gray-300 bg-white p-1.5 text-gray-700 shadow-lg transition-opacity focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-white',
|
||||
sizeClasses,
|
||||
className,
|
||||
)}
|
||||
|
|
@ -89,17 +92,15 @@ const Dropdown: FC<DropdownProps> = ({
|
|||
{options.map((item, index) => (
|
||||
<ListboxOption
|
||||
key={index}
|
||||
value={typeof item === 'string' ? item : item.value}
|
||||
value={item}
|
||||
className={cn(
|
||||
'relative cursor-pointer select-none rounded border-gray-300 bg-white py-2.5 pl-3 pr-3 text-sm text-gray-700 hover:bg-gray-100 dark:border-gray-300 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600',
|
||||
)}
|
||||
style={{ width: '100%' }}
|
||||
data-theme={typeof item === 'string' ? item : (item as OptionType).value}
|
||||
data-theme={getValue(item)}
|
||||
>
|
||||
<div className="flex w-full items-center justify-between">
|
||||
<span className="block truncate">
|
||||
{typeof item === 'string' ? item : (item as OptionType).display}
|
||||
</span>
|
||||
<span className="block truncate">{getDisplay(item)}</span>
|
||||
</div>
|
||||
</ListboxOption>
|
||||
))}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue