Skip to content

Commit a1d93ff

Browse files
committed
revert: restore original SelectDropdown for API config selector
- Remove custom ApiConfigSelector component - Restore original SelectDropdown with built-in search functionality - Add back getApiConfigOptions and renderApiConfigItem functions - Maintain all original search behavior from SelectDropdown component
1 parent e67eb5d commit a1d93ff

File tree

18 files changed

+152
-26
lines changed

18 files changed

+152
-26
lines changed

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ import {
1919
SearchResult,
2020
} from "@src/utils/context-mentions"
2121
import { convertToMentionPath } from "@/utils/path-mentions"
22-
import { StandardTooltip } from "@/components/ui"
22+
import { SelectDropdown, DropdownOptionType, Button, StandardTooltip } from "@/components/ui"
2323

2424
import Thumbnails from "../common/Thumbnails"
2525
import ModeSelector from "./ModeSelector"
26-
import { ApiConfigSelector } from "./ApiConfigSelector"
2726
import { MAX_IMAGES_PER_MESSAGE } from "./ChatView"
2827
import ContextMenu from "./ContextMenu"
29-
import { VolumeX, Image, WandSparkles, SendHorizontal } from "lucide-react"
28+
import { VolumeX, Image, WandSparkles, SendHorizontal, Check, Pin } from "lucide-react"
3029
import { IndexingStatusBadge } from "./IndexingStatusBadge"
3130
import { cn } from "@/lib/utils"
3231
import { usePromptHistory } from "./hooks/usePromptHistory"
@@ -827,26 +826,136 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
827826

828827
// Helper function to handle API config change
829828
const handleApiConfigChange = useCallback((value: string) => {
830-
vscode.postMessage({ type: "loadApiConfigurationById", text: value })
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+
}
831838
}, [])
832839

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+
833941
// Helper function to render non-edit mode controls
834942
const renderNonEditModeControls = () => (
835943
<div className={cn("flex", "justify-between", "items-center", "mt-auto")}>
836944
<div className={cn("flex", "items-center", "gap-1", "min-w-0")}>
837945
<div className="shrink-0">{renderModeSelector()}</div>
838946

839947
<div className={cn("flex-1", "min-w-0", "overflow-hidden")}>
840-
<ApiConfigSelector
948+
<SelectDropdown
841949
value={currentConfigId}
842-
displayName={displayName}
843950
disabled={selectApiConfigDisabled}
844951
title={t("chat:selectApiConfig")}
952+
disableSearch={false}
953+
placeholder={displayName}
954+
options={getApiConfigOptions}
845955
onChange={handleApiConfigChange}
846956
triggerClassName="w-full text-ellipsis overflow-hidden"
847-
listApiConfigMeta={listApiConfigMeta || []}
848-
pinnedApiConfigs={pinnedApiConfigs}
849-
togglePinnedApiConfig={togglePinnedApiConfig}
957+
itemClassName="group"
958+
renderItem={renderApiConfigItem}
850959
/>
851960
</div>
852961
</div>

webview-ui/src/i18n/locales/ca/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/de/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/es/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/fr/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/hi/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/id/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/it/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/ja/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/ko/common.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)