@@ -19,13 +19,14 @@ import {
1919 SearchResult ,
2020} from "@src/utils/context-mentions"
2121import { convertToMentionPath } from "@/utils/path-mentions"
22- import { SelectDropdown , DropdownOptionType , Button , StandardTooltip } from "@/components/ui"
22+ import { StandardTooltip } from "@/components/ui"
2323
2424import Thumbnails from "../common/Thumbnails"
2525import ModeSelector from "./ModeSelector"
26+ import { ApiConfigSelector } from "./ApiConfigSelector"
2627import { MAX_IMAGES_PER_MESSAGE } from "./ChatView"
2728import ContextMenu from "./ContextMenu"
28- import { VolumeX , Image , WandSparkles , SendHorizontal , Check , Pin } from "lucide-react"
29+ import { VolumeX , Image , WandSparkles , SendHorizontal } from "lucide-react"
2930import { IndexingStatusBadge } from "./IndexingStatusBadge"
3031import { cn } from "@/lib/utils"
3132import { usePromptHistory } from "./hooks/usePromptHistory"
@@ -826,136 +827,26 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
826827
827828 // Helper function to handle API config change
828829 const handleApiConfigChange = useCallback ( ( value : string ) => {
829- if ( value === "settingsButtonClicked" ) {
830- vscode . postMessage ( {
831- type : "loadApiConfiguration" ,
832- text : value ,
833- values : { section : "providers" } ,
834- } )
835- } else {
836- vscode . postMessage ( { type : "loadApiConfigurationById" , text : value } )
837- }
830+ vscode . postMessage ( { type : "loadApiConfigurationById" , text : value } )
838831 } , [ ] )
839832
840- // Helper function to get API config options
841- const getApiConfigOptions = useMemo ( ( ) => {
842- const pinnedConfigs = ( listApiConfigMeta || [ ] )
843- . filter ( ( config ) => pinnedApiConfigs && pinnedApiConfigs [ config . id ] )
844- . map ( ( config ) => ( {
845- value : config . id ,
846- label : config . name ,
847- name : config . name ,
848- type : DropdownOptionType . ITEM ,
849- pinned : true ,
850- } ) )
851- . sort ( ( a , b ) => a . label . localeCompare ( b . label ) )
852-
853- const unpinnedConfigs = ( listApiConfigMeta || [ ] )
854- . filter ( ( config ) => ! pinnedApiConfigs || ! pinnedApiConfigs [ config . id ] )
855- . map ( ( config ) => ( {
856- value : config . id ,
857- label : config . name ,
858- name : config . name ,
859- type : DropdownOptionType . ITEM ,
860- pinned : false ,
861- } ) )
862- . sort ( ( a , b ) => a . label . localeCompare ( b . label ) )
863-
864- return [
865- ...pinnedConfigs ,
866- ...( pinnedConfigs . length > 0 && unpinnedConfigs . length > 0
867- ? [
868- {
869- value : "sep-1" ,
870- label : t ( "chat:separator" ) ,
871- type : DropdownOptionType . SEPARATOR ,
872- } ,
873- ]
874- : [ ] ) ,
875- ...unpinnedConfigs ,
876- {
877- value : "sep-2" ,
878- label : t ( "chat:separator" ) ,
879- type : DropdownOptionType . SEPARATOR ,
880- } ,
881- {
882- value : "settingsButtonClicked" ,
883- label : t ( "chat:edit" ) ,
884- type : DropdownOptionType . ACTION ,
885- } ,
886- ]
887- } , [ listApiConfigMeta , pinnedApiConfigs , t ] )
888-
889- // Helper function to render API config item
890- const renderApiConfigItem = useCallback (
891- ( { type, value, label, pinned } : any ) => {
892- if ( type !== DropdownOptionType . ITEM ) {
893- return label
894- }
895-
896- const config = listApiConfigMeta ?. find ( ( c ) => c . id === value )
897- const isCurrentConfig = config ?. name === currentApiConfigName
898-
899- return (
900- < div className = "flex justify-between gap-2 w-full h-5" >
901- < div
902- className = { cn ( "truncate min-w-0 overflow-hidden" , {
903- "font-medium" : isCurrentConfig ,
904- } ) } >
905- { label }
906- </ div >
907- < div className = "flex justify-end w-10 flex-shrink-0" >
908- < div
909- className = { cn ( "size-5 p-1" , {
910- "block group-hover:hidden" : ! pinned ,
911- hidden : ! isCurrentConfig ,
912- } ) } >
913- < Check className = "size-3" />
914- </ div >
915- < StandardTooltip content = { pinned ? t ( "chat:unpin" ) : t ( "chat:pin" ) } >
916- < Button
917- variant = "ghost"
918- size = "icon"
919- onClick = { ( e ) => {
920- e . stopPropagation ( )
921- togglePinnedApiConfig ( value )
922- vscode . postMessage ( {
923- type : "toggleApiConfigPin" ,
924- text : value ,
925- } )
926- } }
927- className = { cn ( "size-5" , {
928- "hidden group-hover:flex" : ! pinned ,
929- "bg-accent" : pinned ,
930- } ) } >
931- < Pin className = "size-3 p-0.5 opacity-50" />
932- </ Button >
933- </ StandardTooltip >
934- </ div >
935- </ div >
936- )
937- } ,
938- [ listApiConfigMeta , currentApiConfigName , t , togglePinnedApiConfig ] ,
939- )
940-
941833 // Helper function to render non-edit mode controls
942834 const renderNonEditModeControls = ( ) => (
943835 < div className = { cn ( "flex" , "justify-between" , "items-center" , "mt-auto" ) } >
944836 < div className = { cn ( "flex" , "items-center" , "gap-1" , "min-w-0" ) } >
945837 < div className = "shrink-0" > { renderModeSelector ( ) } </ div >
946838
947839 < div className = { cn ( "flex-1" , "min-w-0" , "overflow-hidden" ) } >
948- < SelectDropdown
840+ < ApiConfigSelector
949841 value = { currentConfigId }
842+ displayName = { displayName }
950843 disabled = { selectApiConfigDisabled }
951844 title = { t ( "chat:selectApiConfig" ) }
952- disableSearch = { false }
953- placeholder = { displayName }
954- options = { getApiConfigOptions }
955845 onChange = { handleApiConfigChange }
956846 triggerClassName = "w-full text-ellipsis overflow-hidden"
957- itemClassName = "group"
958- renderItem = { renderApiConfigItem }
847+ listApiConfigMeta = { listApiConfigMeta || [ ] }
848+ pinnedApiConfigs = { pinnedApiConfigs }
849+ togglePinnedApiConfig = { togglePinnedApiConfig }
959850 />
960851 </ div >
961852 </ div >
0 commit comments