Просмотр исходного кода

Feat: Add a new button to import settings on the welcome screen (#2811)

Julio Navarro 8 месяцев назад
Родитель
Сommit
04fa72eebe

+ 1 - 0
src/core/config/__tests__/importExport.test.ts

@@ -56,6 +56,7 @@ describe("importExport", () => {
 			setValues: jest.fn(),
 			setValue: jest.fn(),
 			export: jest.fn().mockImplementation(() => Promise.resolve({})),
+			setProviderSettings: jest.fn(),
 		} as unknown as jest.Mocked<ContextProxy>
 
 		// Setup customModesManager mock

+ 15 - 2
src/core/config/importExport.ts

@@ -6,6 +6,7 @@ import * as vscode from "vscode"
 import { z } from "zod"
 
 import { globalSettingsSchema } from "../../schemas"
+
 import { ProviderSettingsManager, providerProfilesSchema } from "./ProviderSettingsManager"
 import { ContextProxy } from "./ContextProxy"
 import { CustomModesManager } from "./CustomModesManager"
@@ -38,6 +39,7 @@ export const importSettings = async ({ providerSettingsManager, contextProxy, cu
 
 	try {
 		const previousProviderProfiles = await providerSettingsManager.export()
+
 		const { providerProfiles: newProviderProfiles, globalSettings } = schema.parse(
 			JSON.parse(await fs.readFile(uris[0].fsPath, "utf-8")),
 		)
@@ -59,9 +61,20 @@ export const importSettings = async ({ providerSettingsManager, contextProxy, cu
 		)
 
 		await providerSettingsManager.import(newProviderProfiles)
-
 		await contextProxy.setValues(globalSettings)
-		contextProxy.setValue("currentApiConfigName", providerProfiles.currentApiConfigName)
+
+		// Set the current provider.
+		const currentProviderName = providerProfiles.currentApiConfigName
+		const currentProvider = providerProfiles.apiConfigs[currentProviderName]
+		contextProxy.setValue("currentApiConfigName", currentProviderName)
+
+		// TODO: It seems like we don't need to have the provider settings in
+		// the proxy; we can just use providerSettingsManager as the source of
+		// truth.
+		if (currentProvider) {
+			contextProxy.setProviderSettings(currentProvider)
+		}
+
 		contextProxy.setValue("listApiConfigMeta", await providerSettingsManager.listConfig())
 
 		return { providerProfiles, globalSettings, success: true }

+ 12 - 1
webview-ui/src/components/welcome/WelcomeView.tsx

@@ -1,5 +1,5 @@
 import { useCallback, useState } from "react"
-import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
+import { VSCodeButton, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
 import { useExtensionState } from "@src/context/ExtensionStateContext"
 import { validateApiConfiguration } from "@src/utils/validate"
 import { vscode } from "@src/utils/vscode"
@@ -114,6 +114,17 @@ const WelcomeView = () => {
 			</TabContent>
 			<div className="sticky bottom-0 bg-vscode-sideBar-background p-5">
 				<div className="flex flex-col gap-1">
+					<div className="flex justify-end">
+						<VSCodeLink
+							href="#"
+							onClick={(e) => {
+								e.preventDefault()
+								vscode.postMessage({ type: "importSettings" })
+							}}
+							className="text-sm">
+							{t("welcome:importSettings")}
+						</VSCodeLink>
+					</div>
 					<VSCodeButton onClick={handleSubmit} appearance="primary">
 						{t("welcome:start")}
 					</VSCodeButton>

+ 2 - 1
webview-ui/src/i18n/locales/ca/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Permetre",
 		"deny": "Denegar"
 	},
-	"or": "o"
+	"or": "o",
+	"importSettings": "Importar configuració"
 }

+ 2 - 1
webview-ui/src/i18n/locales/de/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Erlauben",
 		"deny": "Ablehnen"
 	},
-	"or": "oder"
+	"or": "oder",
+	"importSettings": "Einstellungen importieren"
 }

+ 2 - 1
webview-ui/src/i18n/locales/en/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Allow",
 		"deny": "Deny"
 	},
-	"or": "or"
+	"or": "or",
+	"importSettings": "Import Settings"
 }

+ 2 - 1
webview-ui/src/i18n/locales/es/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Permitir",
 		"deny": "Denegar"
 	},
-	"or": "o"
+	"or": "o",
+	"importSettings": "Importar configuración"
 }

+ 2 - 1
webview-ui/src/i18n/locales/fr/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Autoriser",
 		"deny": "Refuser"
 	},
-	"or": "ou"
+	"or": "ou",
+	"importSettings": "Importer les paramètres"
 }

+ 2 - 1
webview-ui/src/i18n/locales/hi/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "अनुमति दें",
 		"deny": "अस्वीकार करें"
 	},
-	"or": "या"
+	"or": "या",
+	"importSettings": "सेटिंग्स आयात करें"
 }

+ 2 - 1
webview-ui/src/i18n/locales/it/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Consenti",
 		"deny": "Nega"
 	},
-	"or": "o"
+	"or": "o",
+	"importSettings": "Importa impostazioni"
 }

+ 2 - 1
webview-ui/src/i18n/locales/ja/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "許可",
 		"deny": "拒否"
 	},
-	"or": "または"
+	"or": "または",
+	"importSettings": "設定をインポート"
 }

+ 2 - 1
webview-ui/src/i18n/locales/ko/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "허용",
 		"deny": "거부"
 	},
-	"or": "또는"
+	"or": "또는",
+	"importSettings": "설정 가져오기"
 }

+ 2 - 1
webview-ui/src/i18n/locales/pl/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Zezwól",
 		"deny": "Odmów"
 	},
-	"or": "lub"
+	"or": "lub",
+	"importSettings": "Importuj ustawienia"
 }

+ 2 - 1
webview-ui/src/i18n/locales/pt-BR/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Permitir",
 		"deny": "Negar"
 	},
-	"or": "ou"
+	"or": "ou",
+	"importSettings": "Importar configurações"
 }

+ 2 - 1
webview-ui/src/i18n/locales/ru/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Разрешить",
 		"deny": "Запретить"
 	},
-	"or": "или"
+	"or": "или",
+	"importSettings": "Импорт настроек"
 }

+ 2 - 1
webview-ui/src/i18n/locales/tr/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "İzin Ver",
 		"deny": "Reddet"
 	},
-	"or": "veya"
+	"or": "veya",
+	"importSettings": "Ayarları İçe Aktar"
 }

+ 2 - 1
webview-ui/src/i18n/locales/vi/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "Cho phép",
 		"deny": "Từ chối"
 	},
-	"or": "hoặc"
+	"or": "hoặc",
+	"importSettings": "Nhập cài đặt"
 }

+ 2 - 1
webview-ui/src/i18n/locales/zh-CN/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "允许",
 		"deny": "拒绝"
 	},
-	"or": "或"
+	"or": "或",
+	"importSettings": "导入设置"
 }

+ 2 - 1
webview-ui/src/i18n/locales/zh-TW/welcome.json

@@ -23,5 +23,6 @@
 		"allow": "允許",
 		"deny": "拒絕"
 	},
-	"or": "或是"
+	"or": "或是",
+	"importSettings": "匯入設定"
 }