mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(app): confirm before disconnecting providers or removing accounts in settings (#64212)
This commit is contained in:
committed by
GitHub
Unverified
parent
b083c4d510
commit
c5f18d1616
@@ -2251,8 +2251,17 @@ test("providers: the account options rename and remove the active account", asyn
|
||||
await settings.getByRole("tab", { name: "Providers", exact: true }).click()
|
||||
await expect(trigger).toHaveText("Shared")
|
||||
|
||||
const confirm = page.getByRole("dialog", { name: "Remove Shared?", exact: true })
|
||||
await settings.getByRole("button", { name: "Shared options", exact: true }).click()
|
||||
await page.getByRole("menuitem", { name: "Remove", exact: true }).click()
|
||||
await confirm.getByRole("button", { name: "Cancel", exact: true }).click()
|
||||
await expect(confirm).toBeHidden()
|
||||
await expect(trigger).toHaveText("Shared")
|
||||
expect(removed).toEqual([])
|
||||
|
||||
await settings.getByRole("button", { name: "Shared options", exact: true }).click()
|
||||
await page.getByRole("menuitem", { name: "Remove", exact: true }).click()
|
||||
await confirm.getByRole("button", { name: "Remove", exact: true }).click()
|
||||
await expect.poll(() => removed).toEqual(["cred_work"])
|
||||
})
|
||||
|
||||
@@ -2269,6 +2278,10 @@ test("providers: a disconnect that finds no stored credentials keeps the provide
|
||||
await expect(connected.getByText("OpenRouter", { exact: true })).toBeVisible()
|
||||
|
||||
await disconnect.click()
|
||||
await page
|
||||
.getByRole("dialog", { name: "Disconnect OpenRouter?", exact: true })
|
||||
.getByRole("button", { name: "Disconnect", exact: true })
|
||||
.click()
|
||||
await expect(page.getByText("No removable credentials found for OpenRouter", { exact: true })).toBeVisible()
|
||||
await expect(connected.getByText("OpenRouter", { exact: true })).toBeVisible()
|
||||
await expect(disconnect).toBeVisible()
|
||||
|
||||
@@ -1246,6 +1246,17 @@ export const dict = {
|
||||
"settings.providers.account.switched.description": "Now using {{account}}.",
|
||||
"settings.providers.account.removed.title": "{{account}} removed",
|
||||
"settings.providers.account.removed.description": "{{provider}} will no longer use this account.",
|
||||
"settings.providers.account.remove.title": "Remove {{account}}?",
|
||||
"settings.providers.account.remove.description": "{{provider}} will no longer use this account.",
|
||||
"settings.providers.account.remove.finalDescription":
|
||||
"This is your only {{provider}} account, so {{provider}} will be disconnected.",
|
||||
"settings.providers.disconnect.title": "Disconnect {{provider}}?",
|
||||
"settings.providers.disconnect.description":
|
||||
"Its saved credentials will be removed and its models will no longer be available.",
|
||||
"settings.providers.disconnect.consoleDescription.one":
|
||||
"Your sign-in will be removed and {{count}} provider from {{workspace}} will no longer be available.",
|
||||
"settings.providers.disconnect.consoleDescription.other":
|
||||
"Your sign-in will be removed and {{count}} providers from {{workspace}} will no longer be available.",
|
||||
"settings.providers.console.available.one": "{{count}} provider available",
|
||||
"settings.providers.console.available.other": "{{count}} providers available",
|
||||
"settings.providers.section.popular": "Popular providers",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Button } from "@opencode/ui/button"
|
||||
import { Badge } from "@opencode/ui/badge"
|
||||
import { useDialog } from "@opencode/ui/context/dialog"
|
||||
import { Dialog, DialogFooter, DialogHeader, DialogTitleGroup } from "@opencode/ui/dialog"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import { IconButton } from "@opencode/ui/icon-button"
|
||||
import { Menu } from "@opencode/ui/menu"
|
||||
@@ -298,13 +299,30 @@ export const SettingsProviders: Component<{
|
||||
const note = (id: string) => PROVIDER_NOTES.find((item) => item.match(id))?.key
|
||||
|
||||
const disconnect = (item: ProviderItem, name: string) => {
|
||||
const group = consoleGroup()
|
||||
dispatch({
|
||||
type: "disconnect.requested",
|
||||
providerIDs: group?.root.id === item.id ? group.providers.map((provider) => provider.id) : [item.id],
|
||||
integrationID: item.integrationID ?? item.id,
|
||||
providerName: name,
|
||||
})
|
||||
const group = consoleGroup()?.root.id === item.id ? consoleGroup() : undefined
|
||||
|
||||
void dialog.push(() => (
|
||||
<DialogConfirmProviderRemoval
|
||||
title={language.t("settings.providers.disconnect.title", { provider: name })}
|
||||
description={
|
||||
group && group.providers.length > 1
|
||||
? language.plural("settings.providers.disconnect.consoleDescription", group.providers.length, {
|
||||
count: group.providers.length,
|
||||
workspace: group.workspace,
|
||||
})
|
||||
: language.t("settings.providers.disconnect.description")
|
||||
}
|
||||
action={language.t("common.disconnect")}
|
||||
onConfirm={() =>
|
||||
dispatch({
|
||||
type: "disconnect.requested",
|
||||
providerIDs: group ? group.providers.map((provider) => provider.id) : [item.id],
|
||||
integrationID: item.integrationID ?? item.id,
|
||||
providerName: name,
|
||||
})
|
||||
}
|
||||
/>
|
||||
))
|
||||
}
|
||||
|
||||
const activate = (provider: ProviderItem, providerName: string, account: ProviderAccount) =>
|
||||
@@ -318,14 +336,29 @@ export const SettingsProviders: Component<{
|
||||
})
|
||||
|
||||
const remove = (provider: ProviderItem, providerName: string, account: ProviderAccount) =>
|
||||
dispatch({
|
||||
type: "account.remove.requested",
|
||||
integrationID: provider.integrationID ?? provider.id,
|
||||
providerName,
|
||||
account,
|
||||
final: providerAccounts(integration(provider)).length === 1,
|
||||
catalog: untrack(available),
|
||||
})
|
||||
void dialog.push(() => (
|
||||
<DialogConfirmProviderRemoval
|
||||
title={language.t("settings.providers.account.remove.title", { account: account.label })}
|
||||
description={language.t(
|
||||
providerAccounts(integration(provider)).length === 1
|
||||
? "settings.providers.account.remove.finalDescription"
|
||||
: "settings.providers.account.remove.description",
|
||||
{ provider: providerName },
|
||||
)}
|
||||
action={language.t("dialog.provider.accounts.remove")}
|
||||
// The account list can change while the dialog is open, so whether this is the last one is read on confirm.
|
||||
onConfirm={() =>
|
||||
dispatch({
|
||||
type: "account.remove.requested",
|
||||
integrationID: provider.integrationID ?? provider.id,
|
||||
providerName,
|
||||
account,
|
||||
final: providerAccounts(integration(provider)).length === 1,
|
||||
catalog: untrack(available),
|
||||
})
|
||||
}
|
||||
/>
|
||||
))
|
||||
|
||||
function AccountMenu(menuProps: { provider: ProviderItem; name?: string }) {
|
||||
const accounts = () => providerAccounts(integration(menuProps.provider))
|
||||
@@ -634,3 +667,36 @@ export const SettingsProviders: Component<{
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// The row leaves the list as soon as the removal starts, so the dialog closes before the request settles.
|
||||
function DialogConfirmProviderRemoval(props: {
|
||||
title: string
|
||||
description: string
|
||||
action: string
|
||||
onConfirm: () => void
|
||||
}) {
|
||||
const dialog = useDialog()
|
||||
const language = useLanguage()
|
||||
|
||||
const confirm = () => {
|
||||
if (dialog.closing) return
|
||||
dialog.close()
|
||||
props.onConfirm()
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog fit>
|
||||
<DialogHeader hideClose>
|
||||
<DialogTitleGroup title={props.title} description={props.description} />
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="ghost" autofocus disabled={dialog.closing} onClick={() => dialog.close()}>
|
||||
{language.t("common.cancel")}
|
||||
</Button>
|
||||
<Button variant="danger" disabled={dialog.closing} onClick={confirm}>
|
||||
{props.action}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user