Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions webview-ui/src/components/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
StandardTooltip,
} from "@src/components/ui"

import { Checkbox } from "vscrui"
import { Tab, TabContent, TabHeader, TabList, TabTrigger } from "../common/Tab"
import { SetCachedStateField, SetExperimentEnabled } from "./types"
import { SectionHeader } from "./SectionHeader"
Expand Down Expand Up @@ -203,6 +204,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
includeCurrentTime,
includeCurrentCost,
maxGitStatusFiles,
lockApiConfigAcrossModes,
} = cachedState

const apiConfiguration = useMemo(() => cachedState.apiConfiguration ?? {}, [cachedState.apiConfiguration])
Expand Down Expand Up @@ -430,6 +432,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
vscode.postMessage({ type: "upsertApiConfiguration", text: currentApiConfigName, apiConfiguration })
vscode.postMessage({ type: "telemetrySetting", text: telemetrySetting })
vscode.postMessage({ type: "debugSetting", bool: cachedState.debug })
vscode.postMessage({ type: "lockApiConfigAcrossModes", bool: !!lockApiConfigAcrossModes })

setChangeDetected(false)
}
Expand Down Expand Up @@ -766,6 +769,19 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
})
}
/>
<div className="flex flex-col gap-1 mt-4 mb-2">
<Checkbox
checked={!!lockApiConfigAcrossModes}
onChange={(checked: boolean) =>
setCachedStateField("lockApiConfigAcrossModes", checked)
}
data-testid="lock-api-config-checkbox">
{t("settings:providers.lockApiConfigAcrossModes")}
</Checkbox>
<div className="text-sm text-vscode-descriptionForeground ml-6">
{t("settings:providers.lockApiConfigAcrossModesDescription")}
</div>
</div>
<ApiOptions
uriScheme={uriScheme}
apiConfiguration={apiConfiguration}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import SettingsView from "../SettingsView"

vi.mock("@src/utils/vscode", () => ({ vscode: { postMessage: vi.fn() } }))

vi.mock("vscrui", () => ({
Checkbox: ({ children, checked, onChange, "data-testid": dataTestId }: any) => (
<label>
<input
type="checkbox"
checked={checked}
onChange={(e) => onChange(e.target.checked)}
data-testid={dataTestId}
/>
{children}
</label>
),
}))

vi.mock("../ApiConfigManager", () => ({
__esModule: true,
default: ({ currentApiConfigName }: any) => (
Expand Down Expand Up @@ -714,3 +728,39 @@ describe("SettingsView - Duplicate Commands", () => {
)
})
})

describe("SettingsView - Lock API Config Across Modes", () => {
beforeEach(() => {
vi.clearAllMocks()
})

it("renders lock API config checkbox unchecked by default on the providers tab", () => {
const { getSettingsContent } = renderSettingsView()

const content = getSettingsContent()
const lockCheckbox = within(content).getByTestId("lock-api-config-checkbox")
expect(lockCheckbox).not.toBeChecked()
})

it("toggles lock API config and sends lockApiConfigAcrossModes message on save", () => {
const { getSettingsContent } = renderSettingsView()

const content = getSettingsContent()
const lockCheckbox = within(content).getByTestId("lock-api-config-checkbox")

// Enable the lock
fireEvent.click(lockCheckbox)
expect(lockCheckbox).toBeChecked()

// Click Save
const saveButton = screen.getByTestId("save-button")
fireEvent.click(saveButton)

expect(vscode.postMessage).toHaveBeenCalledWith(
expect.objectContaining({
type: "lockApiConfigAcrossModes",
bool: true,
}),
)
})
})
2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/ca/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/de/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@
"providerDocumentation": "{{provider}} documentation",
"configProfile": "Configuration Profile",
"description": "Save different API configurations to quickly switch between providers and settings.",
"lockApiConfigAcrossModes": "Use the same configuration for all modes",
"lockApiConfigAcrossModesDescription": "When enabled, switching modes (e.g. Code, Architect, Ask) will keep the current API configuration instead of switching to a mode-specific one.",
"apiProvider": "API Provider",
"apiProviderDocs": "Provider Docs",
"model": "Model",
Expand Down
2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/es/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/fr/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/hi/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/id/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/it/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/ja/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/ko/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/nl/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/pl/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/pt-BR/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/ru/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/tr/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/vi/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/zh-CN/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/src/i18n/locales/zh-TW/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading