diff --git a/services/platform/app/features/settings/connectors/components/connectors-settings.test.tsx b/services/platform/app/features/settings/connectors/components/connectors-settings.test.tsx index b48f7c5cc5..152ed80a03 100644 --- a/services/platform/app/features/settings/connectors/components/connectors-settings.test.tsx +++ b/services/platform/app/features/settings/connectors/components/connectors-settings.test.tsx @@ -28,6 +28,8 @@ const setDefaultCredential = vi.hoisted(() => vi.fn()); const goToAuthorization = vi.hoisted(() => vi.fn()); const toastSpy = vi.hoisted(() => vi.fn()); +const urlState = vi.hoisted(() => ({ connector: null as string | null })); +const setUrlState = vi.hoisted(() => vi.fn()); const fixtures = vi.hoisted(() => ({ connectors: [] as unknown[], credentials: [] as unknown[], @@ -115,10 +117,13 @@ vi.mock('@/app/hooks/use-url-state', () => { const React = require('react') as typeof import('react'); return { useUrlState: () => { - const [open, setOpen] = React.useState(null); + const [open, setOpen] = React.useState(urlState.connector); return { state: { connector: open }, - setState: (_key: string, value: string | null) => setOpen(value), + setState: (key: string, value: string | null) => { + setUrlState(key, value); + setOpen(value); + }, setStates: () => {}, clearState: () => {}, clearAll: () => {}, @@ -285,6 +290,7 @@ async function rename( describe('ConnectorsSettings', () => { beforeEach(() => { vi.clearAllMocks(); + urlState.connector = null; abilityState.canRead = true; fixtures.connectors = [githubConnector, slackConnector]; fixtures.credentials = [...defaultCredentials]; @@ -325,6 +331,50 @@ describe('ConnectorsSettings', () => { }); describe('narrowing', () => { + it.each(['slack', 'github', 'retired-connector'])( + 'keeps a single-vendor %s deep link clearable', + async (connector) => { + urlState.connector = connector; + const { user, container } = render( + , + ); + const filter = await screen.findByRole('button', { name: /Filter/ }); + expect(filter).toBeEnabled(); + expect(screen.getByPlaceholderText('Search credentials')).toBeEnabled(); + if (connector !== 'github') { + expect( + screen.getByRole('heading', { name: 'No results found' }), + ).toBeInTheDocument(); + expect( + screen.queryByRole('heading', { + name: 'No connectors connected yet', + }), + ).not.toBeInTheDocument(); + } + await checkAccessibility(container); + await user.click(filter); + await user.click(screen.getByRole('button', { name: /^Connector/ })); + expect( + screen.getByRole('checkbox', { + name: + connector === 'slack' + ? 'Slack' + : connector === 'github' + ? 'GitHub' + : connector, + }), + ).toBeChecked(); + await user.click( + within(screen.getByRole('dialog', { name: 'Filters' })).getByRole( + 'button', + { name: 'Clear all' }, + ), + ); + expect(setUrlState).toHaveBeenCalledWith('connector', null); + expect(screen.getByText('Platform bot')).toBeInTheDocument(); + }, + ); + it('finds a credential by the connector it authenticates', async () => { fixtures.credentials = [ ...defaultCredentials, diff --git a/services/platform/app/features/settings/credentials/credential-table.tsx b/services/platform/app/features/settings/credentials/credential-table.tsx index e501b4b8f6..4c7c0c4511 100644 --- a/services/platform/app/features/settings/credentials/credential-table.tsx +++ b/services/platform/app/features/settings/credentials/credential-table.tsx @@ -173,8 +173,6 @@ export function CredentialTable< .sort((a, b) => a.localeCompare(b)); }, [adapter, credentials, vendorsByKey]); - // Only vendors actually represented in the table are worth offering: a facet - // that can only ever narrow to zero rows is noise. const vendorFacets = useMemo(() => { const seen = new Map(); for (const credential of credentials) { @@ -183,13 +181,18 @@ export function CredentialTable< seen.set(key, vendorsByKey.get(key)?.displayName ?? key); } } + for (const key of vendorFilter) { + if (!seen.has(key)) { + seen.set(key, vendorsByKey.get(key)?.displayName ?? key); + } + } return [...seen.entries()] .map(([value, label]) => ({ value, label })) .sort((a, b) => a.label.localeCompare(b.label)); - }, [adapter, credentials, vendorsByKey]); + }, [adapter, credentials, vendorFilter, vendorsByKey]); const filterConfigs: FilterConfig[] = - vendorFacets.length > 1 + vendorFacets.length > 1 || vendorFilter.length > 0 ? [ { key: 'vendor', diff --git a/services/platform/app/features/settings/providers/components/providers-settings.test.tsx b/services/platform/app/features/settings/providers/components/providers-settings.test.tsx index 02138cef3d..d918011e74 100644 --- a/services/platform/app/features/settings/providers/components/providers-settings.test.tsx +++ b/services/platform/app/features/settings/providers/components/providers-settings.test.tsx @@ -1,14 +1,20 @@ import { pickFilterOption } from '@tale/ui/testing/filters'; import { useState, type ReactNode } from 'react'; -import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { SettingsHeaderActionsSetter, type SettingsHeaderAction, } from '@/app/features/settings/components/settings-secondary-action-context'; +import { i18n } from '@/lib/i18n/i18n'; import { AppError } from '@/lib/shared/errors/app-error'; import { checkAccessibility } from '@/tests/utils/a11y'; -import { render, screen, waitFor, within } from '@/tests/utils/render'; +import { + SHIPPED_LOCALES, + saveLocale, + forgetSavedLocale, +} from '@/tests/utils/lapsed-session'; +import { cleanup, render, screen, waitFor, within } from '@/tests/utils/render'; import type { ProviderCatalog, MaskedCredential } from '../hooks/queries'; import { ProvidersSettings } from './providers-settings'; @@ -31,6 +37,8 @@ const setDefaultCredential = vi.hoisted(() => vi.fn()); const refreshCatalogs = vi.hoisted(() => vi.fn()); const checkCatalog = vi.hoisted(() => vi.fn()); const toastSpy = vi.hoisted(() => vi.fn()); +const urlState = vi.hoisted(() => ({ provider: null as string | null })); +const setUrlState = vi.hoisted(() => vi.fn()); const fixtures = vi.hoisted(() => ({ catalogs: [] as unknown[], @@ -133,10 +141,15 @@ vi.mock('@/app/hooks/use-url-state', () => { const React = require('react') as typeof import('react'); return { useUrlState: () => { - const [provider, setProvider] = React.useState(null); + const [provider, setProvider] = React.useState( + urlState.provider, + ); return { state: { provider }, - setState: (_key: string, value: string | null) => setProvider(value), + setState: (key: string, value: string | null) => { + setUrlState(key, value); + setProvider(value); + }, setStates: () => {}, clearState: () => {}, clearAll: () => {}, @@ -315,6 +328,7 @@ async function rename( describe('ProvidersSettings', () => { beforeEach(() => { vi.clearAllMocks(); + urlState.provider = null; abilityState.canRead = true; fixtures.catalogs = [anthropicProvider, openrouterProvider]; fixtures.credentials = [...defaultCredentials]; @@ -376,6 +390,144 @@ describe('ProvidersSettings', () => { }); describe('narrowing', () => { + describe('localized no-results recovery', () => { + afterEach(async () => { + cleanup(); + await forgetSavedLocale(); + }); + + it.each(SHIPPED_LOCALES)( + 'keeps the filter keyboard-clearable in %s', + async (locale) => { + saveLocale(locale); + await i18n.changeLanguage(locale); + urlState.provider = 'openrouter'; + const { user, container } = renderPage(); + expect( + await screen.findByRole('heading', { + name: i18n.t('search.noResults', { ns: 'common' }), + }), + ).toBeInTheDocument(); + expect( + screen.getByPlaceholderText( + i18n.t('credentials.searchPlaceholder', { ns: 'settings' }), + ), + ).toBeEnabled(); + const filter = screen.getByRole('button', { + name: new RegExp(i18n.t('labels.filter', { ns: 'common' })), + }); + filter.focus(); + await user.keyboard('{Enter}'); + const group = screen.getByRole('button', { + name: new RegExp( + `^${i18n.t('providers.vendorFilterLabel', { ns: 'settings' })}`, + ), + }); + group.focus(); + await user.keyboard('{Enter}'); + const selected = screen.getByRole('checkbox', { name: 'OpenRouter' }); + expect(selected).toBeChecked(); + await checkAccessibility(container); + selected.focus(); + await user.keyboard(' '); + await user.keyboard('{Escape}'); + expect(screen.getByText('Production key')).toBeInTheDocument(); + expect(setUrlState).toHaveBeenCalledWith('provider', null); + }, + ); + }); + + it.each(['openrouter', 'retired-provider'])( + 'keeps an unmatched %s deep-link filter reversible', + async (provider) => { + urlState.provider = provider; + const { user, container } = renderPage(); + expect( + await screen.findByRole('heading', { name: 'No results found' }), + ).toBeInTheDocument(); + expect( + screen.queryByRole('heading', { + name: 'Connect your first AI provider', + }), + ).not.toBeInTheDocument(); + expect(screen.getByPlaceholderText('Search credentials')).toBeEnabled(); + const filter = screen.getByRole('button', { name: /Filter/ }); + expect(filter).toBeEnabled(); + await checkAccessibility(container); + await user.click(filter); + await user.click(screen.getByRole('button', { name: /^Provider/ })); + const option = screen.getByRole('checkbox', { + name: provider === 'openrouter' ? 'OpenRouter' : provider, + }); + expect(option).toBeChecked(); + await user.click(option); + await user.keyboard('{Escape}'); + expect(screen.getByText('Production key')).toBeInTheDocument(); + expect(setUrlState).toHaveBeenCalledWith('provider', null); + }, + ); + + it('keeps a matching single-provider deep link clearable', async () => { + urlState.provider = 'anthropic'; + const { user } = renderPage(); + await user.click(await screen.findByRole('button', { name: /Filter/ })); + await user.click( + within(screen.getByRole('dialog', { name: 'Filters' })).getByRole( + 'button', + { name: 'Clear all' }, + ), + ); + expect(setUrlState).toHaveBeenCalledWith('provider', null); + expect(screen.getByText('Production key')).toBeInTheDocument(); + }); + + it('keeps the active facet after deleting its last credential', async () => { + const routerCredential = credential({ + id: 'router', + name: 'Router key', + providerSlug: 'openrouter', + isDefault: true, + }); + fixtures.credentials = [...defaultCredentials, routerCredential]; + const { user, rerender } = renderPage(); + await pickFilterOption(user, 'Provider', 'OpenRouter'); + await user.keyboard('{Escape}'); + await user.click( + screen.getByRole('button', { name: 'Actions for Router key' }), + ); + await user.click( + within(await screen.findByRole('menu')).getByRole('menuitem', { + name: 'Delete', + }), + ); + const dialog = within( + await screen.findByRole('dialog', { name: 'Delete credential' }), + ); + await user.click(dialog.getByRole('button', { name: /Delete/ })); + expect(deleteCredential).toHaveBeenCalledWith({ + organizationId: 'org-1', + credentialId: 'router', + }); + fixtures.credentials = [...defaultCredentials]; + rerender( + + + , + ); + expect( + await screen.findByRole('heading', { name: 'No results found' }), + ).toBeInTheDocument(); + expect(screen.getByPlaceholderText('Search credentials')).toBeEnabled(); + await user.click(screen.getByRole('button', { name: /Filter/ })); + await user.click( + within(screen.getByRole('dialog', { name: 'Filters' })).getByRole( + 'button', + { name: 'Clear all' }, + ), + ); + expect(screen.getByText('Production key')).toBeInTheDocument(); + }); + it('finds a credential by the provider it authenticates', async () => { fixtures.credentials = [ ...defaultCredentials, diff --git a/services/platform/app/hooks/use-url-state.test.tsx b/services/platform/app/hooks/use-url-state.test.tsx new file mode 100644 index 0000000000..24bcf996e6 --- /dev/null +++ b/services/platform/app/hooks/use-url-state.test.tsx @@ -0,0 +1,49 @@ +import { + createMemoryHistory, + createRootRoute, + createRouter, + RouterProvider, +} from '@tanstack/react-router'; +import { describe, expect, it } from 'vitest'; + +import { render, screen, waitFor } from '@/tests/utils/render'; + +import { useUrlState } from './use-url-state'; + +describe('credential deep-link URL state', () => { + it.each(['provider', 'connector'])( + 'removes the %s parameter when the facet clears', + async (parameter) => { + function Probe() { + const { state, setState } = useUrlState({ + definitions: { [parameter]: { default: null } }, + }); + return ( + + ); + } + + const history = createMemoryHistory({ + initialEntries: [`/?${parameter}=absent-vendor&keep=1`], + }); + const router = createRouter({ + routeTree: createRootRoute({ component: Probe }), + history, + }); + const { user } = render(); + await user.click( + await screen.findByRole('button', { name: 'absent-vendor' }), + ); + await waitFor(() => { + const search = new URLSearchParams(history.location.search); + expect(search.has(parameter)).toBe(false); + expect(search.get('keep')).toBe('1'); + }); + expect( + await screen.findByRole('button', { name: 'Cleared' }), + ).toBeInTheDocument(); + }, + ); +}); diff --git a/services/platform/tests/manual/suites/connectors.md b/services/platform/tests/manual/suites/connectors.md index 05488b0570..a1b9e0537c 100644 --- a/services/platform/tests/manual/suites/connectors.md +++ b/services/platform/tests/manual/suites/connectors.md @@ -153,6 +153,13 @@ Sign in as an owner/admin — the page requires the `developerSettings` ability the GitHub rows show — the param seeded the **Connector** facet (`settings.connectors.vendorFilterLabel`). Changing or clearing the facet removes `?connector=` from the URL and the facet's own selection takes over. + Repeat with only GitHub credentials and `?connector=slack`, and after + deleting the selected connector's last credential → The shared no-results + state appears (never the first-connector invitation); search and Filter stay + enabled, the selected connector stays visible in the facet, and clearing it + removes the param and restores GitHub rows. A matching single-connector link + also keeps its filter clearable. Check EN/DE/FR and keyboard access to the + facet and clear action. - [ ] `CONN-F10` · **Row actions** — Row 3-dot menu (`settings.credentials.actionsLabel`) → Offers **Make default** / **Disable** / **Replace …** / **Edit credential** / **Delete** diff --git a/services/platform/tests/manual/suites/settings.md b/services/platform/tests/manual/suites/settings.md index 8ee1c26344..ab94d33614 100644 --- a/services/platform/tests/manual/suites/settings.md +++ b/services/platform/tests/manual/suites/settings.md @@ -870,7 +870,13 @@ run. `/dashboard/{org}/settings/providers/openrouter` → Redirects to the providers index with `?provider=openrouter` — the vendor filter (`settings.providers.vendorFilterLabel`) arrives pre-applied to that vendor; - clearing the filter clears the URL param. + clearing the filter clears the URL param. Repeat with only one other provider + holding credentials, and after deleting the selected provider's last + credential → The shared no-results state appears (never the first-provider + invitation); search and Filter stay enabled, the selected provider stays + visible in the facet, and clearing it restores the remaining rows. A link + matching the only provider also keeps its filter clearable. Check EN/DE/FR + and keyboard access to the facet and clear action. - [ ] `SET-B4` · **Role gating — member** — Sign in as a **member** role account → The rail shows only the Personal section plus **Skills**; direct URLs are refused with the full access-denied message —