Skip to content

Commit 04fa72e

Browse files
authored
Feat: Add a new button to import settings on the welcome screen (#2811)
1 parent a3d8c0e commit 04fa72e

File tree

19 files changed

+60
-19
lines changed

19 files changed

+60
-19
lines changed

src/core/config/__tests__/importExport.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe("importExport", () => {
5656
setValues: jest.fn(),
5757
setValue: jest.fn(),
5858
export: jest.fn().mockImplementation(() => Promise.resolve({})),
59+
setProviderSettings: jest.fn(),
5960
} as unknown as jest.Mocked<ContextProxy>
6061

6162
// Setup customModesManager mock

src/core/config/importExport.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as vscode from "vscode"
66
import { z } from "zod"
77

88
import { globalSettingsSchema } from "../../schemas"
9+
910
import { ProviderSettingsManager, providerProfilesSchema } from "./ProviderSettingsManager"
1011
import { ContextProxy } from "./ContextProxy"
1112
import { CustomModesManager } from "./CustomModesManager"
@@ -38,6 +39,7 @@ export const importSettings = async ({ providerSettingsManager, contextProxy, cu
3839

3940
try {
4041
const previousProviderProfiles = await providerSettingsManager.export()
42+
4143
const { providerProfiles: newProviderProfiles, globalSettings } = schema.parse(
4244
JSON.parse(await fs.readFile(uris[0].fsPath, "utf-8")),
4345
)
@@ -59,9 +61,20 @@ export const importSettings = async ({ providerSettingsManager, contextProxy, cu
5961
)
6062

6163
await providerSettingsManager.import(newProviderProfiles)
62-
6364
await contextProxy.setValues(globalSettings)
64-
contextProxy.setValue("currentApiConfigName", providerProfiles.currentApiConfigName)
65+
66+
// Set the current provider.
67+
const currentProviderName = providerProfiles.currentApiConfigName
68+
const currentProvider = providerProfiles.apiConfigs[currentProviderName]
69+
contextProxy.setValue("currentApiConfigName", currentProviderName)
70+
71+
// TODO: It seems like we don't need to have the provider settings in
72+
// the proxy; we can just use providerSettingsManager as the source of
73+
// truth.
74+
if (currentProvider) {
75+
contextProxy.setProviderSettings(currentProvider)
76+
}
77+
6578
contextProxy.setValue("listApiConfigMeta", await providerSettingsManager.listConfig())
6679

6780
return { providerProfiles, globalSettings, success: true }

webview-ui/src/components/welcome/WelcomeView.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useState } from "react"
2-
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
2+
import { VSCodeButton, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
33
import { useExtensionState } from "@src/context/ExtensionStateContext"
44
import { validateApiConfiguration } from "@src/utils/validate"
55
import { vscode } from "@src/utils/vscode"
@@ -114,6 +114,17 @@ const WelcomeView = () => {
114114
</TabContent>
115115
<div className="sticky bottom-0 bg-vscode-sideBar-background p-5">
116116
<div className="flex flex-col gap-1">
117+
<div className="flex justify-end">
118+
<VSCodeLink
119+
href="#"
120+
onClick={(e) => {
121+
e.preventDefault()
122+
vscode.postMessage({ type: "importSettings" })
123+
}}
124+
className="text-sm">
125+
{t("welcome:importSettings")}
126+
</VSCodeLink>
127+
</div>
117128
<VSCodeButton onClick={handleSubmit} appearance="primary">
118129
{t("welcome:start")}
119130
</VSCodeButton>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"allow": "Permetre",
2424
"deny": "Denegar"
2525
},
26-
"or": "o"
26+
"or": "o",
27+
"importSettings": "Importar configuració"
2728
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"allow": "Erlauben",
2424
"deny": "Ablehnen"
2525
},
26-
"or": "oder"
26+
"or": "oder",
27+
"importSettings": "Einstellungen importieren"
2728
}

webview-ui/src/i18n/locales/en/welcome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"allow": "Allow",
2424
"deny": "Deny"
2525
},
26-
"or": "or"
26+
"or": "or",
27+
"importSettings": "Import Settings"
2728
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"allow": "Permitir",
2424
"deny": "Denegar"
2525
},
26-
"or": "o"
26+
"or": "o",
27+
"importSettings": "Importar configuración"
2728
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"allow": "Autoriser",
2424
"deny": "Refuser"
2525
},
26-
"or": "ou"
26+
"or": "ou",
27+
"importSettings": "Importer les paramètres"
2728
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"allow": "अनुमति दें",
2424
"deny": "अस्वीकार करें"
2525
},
26-
"or": "या"
26+
"or": "या",
27+
"importSettings": "सेटिंग्स आयात करें"
2728
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"allow": "Consenti",
2424
"deny": "Nega"
2525
},
26-
"or": "o"
26+
"or": "o",
27+
"importSettings": "Importa impostazioni"
2728
}

0 commit comments

Comments
 (0)