mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix(frontend): load provider integrations through the typed OpenCode client
Fetch integrations with callOpenCode instead of a dedicated backend route, drop the unused provider credentials list query, label an existing key as "Edit API key", and keep the loaded provider list when a background refetch fails.
This commit is contained in:
1 parent
b179267376
commit
99713e15b4
13 files changed
+44
-84
No files matched your search
@@ -12,7 +12,6 @@ import type { ReactNode } from 'react'
|
||||
vi.mock('@/api/providers', () => ({
|
||||
getProviders: vi.fn(),
|
||||
providerCredentialsApi: {
|
||||
list: vi.fn(),
|
||||
getStatus: vi.fn(),
|
||||
set: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
@@ -343,8 +342,9 @@ describe('ProviderSettings', () => {
|
||||
renderSettings()
|
||||
|
||||
await screen.findByText('Anthropic Integration')
|
||||
expect(screen.getByText('2 models')).toBeInTheDocument()
|
||||
expect(screen.getByText('Connected')).toBeInTheDocument()
|
||||
const row = screen.getByText('Anthropic Integration').closest('.py-3') as HTMLElement
|
||||
expect(within(row).getByText('2 models')).toBeInTheDocument()
|
||||
expect(within(row).getByText('Connected')).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Reconnect' }))
|
||||
expect(screen.getByTestId('oauth-authorize-dialog')).toHaveTextContent('anthropic')
|
||||
@@ -395,7 +395,7 @@ describe('ProviderSettings', () => {
|
||||
expect(screen.getByTestId('api-key-dialog')).toHaveAttribute('data-mode', 'add')
|
||||
})
|
||||
|
||||
it('labels an existing API key action as Add API key without changing its handling', async () => {
|
||||
it('labels an existing API key action as Edit API key and opens the dialog in edit mode', async () => {
|
||||
vi.mocked(getProviders).mockResolvedValue({
|
||||
providers: [providerFixture('anthropic', 'Anthropic', 2)],
|
||||
models: [],
|
||||
@@ -409,10 +409,10 @@ describe('ProviderSettings', () => {
|
||||
await screen.findByText('Anthropic')
|
||||
const row = screen.getByText('Anthropic').closest('.py-3') as HTMLElement
|
||||
|
||||
const addKeyButton = within(row).getByRole('button', { name: 'Add API key for Anthropic' })
|
||||
expect(addKeyButton).toHaveTextContent('Add API key')
|
||||
const editKeyButton = within(row).getByRole('button', { name: 'Edit API key for Anthropic' })
|
||||
expect(editKeyButton).toHaveTextContent('Edit API key')
|
||||
|
||||
await user.click(addKeyButton)
|
||||
await user.click(editKeyButton)
|
||||
expect(screen.getByTestId('api-key-dialog')).toHaveAttribute('data-mode', 'edit')
|
||||
})
|
||||
|
||||
@@ -497,4 +497,23 @@ describe('ProviderSettings', () => {
|
||||
expect(screen.queryByText('Anthropic')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('No OAuth-capable providers available.')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keeps the loaded providers when an integration refetch fails', async () => {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
})
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ProviderSettings />
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
await screen.findByText('Anthropic')
|
||||
|
||||
vi.mocked(oauthApi.getIntegrations).mockRejectedValue(new Error('Server unavailable'))
|
||||
await queryClient.refetchQueries({ queryKey: ['provider-integrations'] })
|
||||
|
||||
await waitFor(() => expect(queryClient.getQueryState(['provider-integrations'])?.status).toBe('error'))
|
||||
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Anthropic')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -81,7 +81,6 @@ function buildProviderEntries(
|
||||
!seen.has(integration.id) &&
|
||||
(supportsSettingsAuthentication(integration.methods) || hasCredentialConnection(integration)),
|
||||
)
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
.map((integration): ProviderEntry => ({
|
||||
id: integration.id,
|
||||
name: integration.name || integration.id,
|
||||
@@ -90,6 +89,7 @@ function buildProviderEntries(
|
||||
connected: hasCredentialConnection(integration),
|
||||
keyConnected: hasKeyConnection(integration),
|
||||
}))
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
|
||||
return [...entries, ...integrationOnly]
|
||||
}
|
||||
@@ -117,10 +117,11 @@ export function ProviderSettings() {
|
||||
isLoading: integrationsLoading,
|
||||
isError: integrationsError,
|
||||
} = useProviderIntegrations()
|
||||
const integrationsUnavailable = integrationsError && !integrations
|
||||
|
||||
const providerEntries = useMemo(
|
||||
() => integrationsError ? [] : buildProviderEntries(providers, integrations),
|
||||
[providers, integrations, integrationsError],
|
||||
() => buildProviderEntries(providers, integrations),
|
||||
[providers, integrations],
|
||||
)
|
||||
|
||||
const deleteCredentialMutation = useMutation({
|
||||
@@ -225,7 +226,7 @@ export function ProviderSettings() {
|
||||
}
|
||||
}, [])
|
||||
|
||||
if (integrationsError) {
|
||||
if (integrationsUnavailable) {
|
||||
return (
|
||||
<div role="alert" className="rounded-md border border-destructive/50 bg-card p-4">
|
||||
<p className="text-sm font-medium text-foreground">Unable to load provider integrations.</p>
|
||||
@@ -310,10 +311,10 @@ export function ProviderSettings() {
|
||||
size="sm"
|
||||
variant={keyConnected ? 'outline' : 'secondary'}
|
||||
onClick={() => keyConnected ? handleEditApiKey(provider) : handleAddApiKey(provider)}
|
||||
aria-label={`Add API key for ${provider.name || provider.id}`}
|
||||
aria-label={`${keyConnected ? 'Edit' : 'Add'} API key for ${provider.name || provider.id}`}
|
||||
>
|
||||
<Key className="h-4 w-4 mr-1" />
|
||||
Add API key
|
||||
{keyConnected ? 'Edit API key' : 'Add API key'}
|
||||
</Button>
|
||||
)}
|
||||
{isConnected && (
|
||||
|
||||
Reference in new issue
Block a user