fix: dropdown model position (#5199)

This commit is contained in:
Faisal Amir 2025-06-05 12:07:43 +07:00 committed by GitHub
parent 2588c3fa55
commit 8ee4969aa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,7 +8,7 @@ import { useModelProvider } from '@/hooks/useModelProvider'
import { cn, getProviderTitle } from '@/lib/utils' import { cn, getProviderTitle } from '@/lib/utils'
import { highlightFzfMatch } from '@/utils/highlight' import { highlightFzfMatch } from '@/utils/highlight'
import Capabilities from './Capabilities' import Capabilities from './Capabilities'
import { IconSettings, IconX, IconCheck } from '@tabler/icons-react' import { IconSettings, IconX } from '@tabler/icons-react'
import { useNavigate } from '@tanstack/react-router' import { useNavigate } from '@tanstack/react-router'
import { route } from '@/constants/routes' import { route } from '@/constants/routes'
import { useThreads } from '@/hooks/useThreads' import { useThreads } from '@/hooks/useThreads'
@ -149,8 +149,19 @@ const DropdownModelProvider = ({ model }: DropdownModelProviderProps) => {
const groupedItems = useMemo(() => { const groupedItems = useMemo(() => {
const groups: Record<string, SearchableModel[]> = {} const groups: Record<string, SearchableModel[]> = {}
if (!searchValue) {
// When not searching, show all active providers (even without models)
providers.forEach((provider) => {
if (provider.active) {
groups[provider.provider] = []
}
})
}
// Add the filtered items to their respective groups
filteredItems.forEach((item) => { filteredItems.forEach((item) => {
const providerKey = item.provider.provider const providerKey = item.provider.provider
console.log(providerKey, 'providerKey')
if (!groups[providerKey]) { if (!groups[providerKey]) {
groups[providerKey] = [] groups[providerKey] = []
} }
@ -158,7 +169,7 @@ const DropdownModelProvider = ({ model }: DropdownModelProviderProps) => {
}) })
return groups return groups
}, [filteredItems]) }, [filteredItems, providers, searchValue])
const handleSelect = useCallback( const handleSelect = useCallback(
(searchableModel: SearchableModel) => { (searchableModel: SearchableModel) => {
@ -213,14 +224,14 @@ const DropdownModelProvider = ({ model }: DropdownModelProviderProps) => {
</div> </div>
<PopoverContent <PopoverContent
className="w-80 p-0 max-h-[400px] overflow-hidden" className={cn('w-60 p-0', searchValue.length === 0 && 'h-[320px]')}
side="bottom"
align="start" align="start"
sideOffset={10} sideOffset={10}
alignOffset={-8} alignOffset={-8}
avoidCollisions={false} side={searchValue.length === 0 ? undefined : 'top'}
avoidCollisions={searchValue.length === 0 ? true : false}
> >
<div className="flex flex-col w-full"> <div className="flex flex-col w-full h-full">
{/* Search input */} {/* Search input */}
<div className="relative px-2 py-1.5 border-b border-main-view-fg/10"> <div className="relative px-2 py-1.5 border-b border-main-view-fg/10">
<input <input
@ -253,6 +264,7 @@ const DropdownModelProvider = ({ model }: DropdownModelProviderProps) => {
const providerInfo = providers.find( const providerInfo = providers.find(
(p) => p.provider === providerKey (p) => p.provider === providerKey
) )
if (!providerInfo) return null if (!providerInfo) return null
return ( return (
@ -287,10 +299,15 @@ const DropdownModelProvider = ({ model }: DropdownModelProviderProps) => {
</div> </div>
{/* Models for this provider */} {/* Models for this provider */}
{models.map((searchableModel) => { {models.length === 0 ? (
// Show message when provider has no available models
<></>
) : (
models.map((searchableModel) => {
const isSelected = const isSelected =
selectedModel?.id === searchableModel.model.id && selectedModel?.id === searchableModel.model.id &&
selectedProvider === searchableModel.provider.provider selectedProvider ===
searchableModel.provider.provider
const capabilities = const capabilities =
searchableModel.model.capabilities || [] searchableModel.model.capabilities || []
@ -313,22 +330,18 @@ const DropdownModelProvider = ({ model }: DropdownModelProviderProps) => {
searchableModel.model.id, searchableModel.model.id,
}} }}
/> />
{isSelected && (
<IconCheck
size={16}
className="text-accent shrink-0"
/>
)}
<div className="flex-1"></div> <div className="flex-1"></div>
{capabilities.length > 0 && ( {capabilities.length > 0 && (
<div className="flex-shrink-0"> <div className="flex-shrink-0 -mr-1.5">
<Capabilities capabilities={capabilities} /> <Capabilities capabilities={capabilities} />
</div> </div>
)} )}
</div> </div>
</div> </div>
) )
})} })
)}
</div> </div>
) )
})} })}