From 1d216e73f09fb8facc720283d69d19f665f321b3 Mon Sep 17 00:00:00 2001 From: dongmucat <1127093059@qq.com> Date: Mon, 27 Jul 2026 18:02:07 +0800 Subject: [PATCH] fix(frontend): expose namespace picker value Signed-off-by: dongmucat <1127093059@qq.com> --- .../my-namespaces-super-admin-actions.spec.ts | 8 +++++--- web/src/pages/dashboard/publish.tsx | 1 + .../shared/components/namespace-picker.test.tsx | 16 +++++++++++++--- web/src/shared/components/namespace-picker.tsx | 14 ++++++++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/web/e2e/my-namespaces-super-admin-actions.spec.ts b/web/e2e/my-namespaces-super-admin-actions.spec.ts index ff0679d1..07ce0bf1 100644 --- a/web/e2e/my-namespaces-super-admin-actions.spec.ts +++ b/web/e2e/my-namespaces-super-admin-actions.spec.ts @@ -74,7 +74,8 @@ test.describe('My Namespaces super admin actions (Real API)', () => { namespaceArchived = true await page.goto('/dashboard/publish') - await page.getByRole('button', { name: 'Select namespace', exact: true }).click() + const namespaceTrigger = page.locator('#namespace') + await namespaceTrigger.click() await page.getByRole('searchbox', { name: 'Search namespaces' }).fill(activeNamespace.slug) const activeOption = page.getByRole('button', { name: `${activeNamespace.displayName} (@${activeNamespace.slug})`, @@ -82,7 +83,8 @@ test.describe('My Namespaces super admin actions (Real API)', () => { await expect(activeOption).toBeVisible() await activeOption.click() - await page.getByRole('button', { name: `@${activeNamespace.slug}`, exact: true }).click() + await expect(namespaceTrigger).toContainText(`@${activeNamespace.slug}`) + await namespaceTrigger.click() await page.getByRole('searchbox', { name: 'Search namespaces' }).fill(namespace.slug) await expect(page.getByText('No namespaces found')).toBeVisible() await expect(page.getByRole('button', { @@ -90,7 +92,7 @@ test.describe('My Namespaces super admin actions (Real API)', () => { })).toHaveCount(0) await page.goto(`/dashboard/publish?namespace=${encodeURIComponent(namespace.slug)}&visibility=PUBLIC`) - await expect(page.getByRole('button', { name: `@${namespace.slug}`, exact: true })).toBeVisible() + await expect(namespaceTrigger).toContainText(`@${namespace.slug}`) await expect(page.getByText('The selected namespace is not active or is no longer available.')).toBeVisible() await page.goto('/dashboard/namespaces') diff --git a/web/src/pages/dashboard/publish.tsx b/web/src/pages/dashboard/publish.tsx index 2fc2d8d5..a45f64a1 100644 --- a/web/src/pages/dashboard/publish.tsx +++ b/web/src/pages/dashboard/publish.tsx @@ -166,6 +166,7 @@ export function PublishPage() { { }, true) }) - it('forwards the trigger id for labels and stable form selectors', () => { - render() + it('keeps the current value in the accessible name when associated with a label', () => { + render( + <> + + + , + ) expect(document.getElementById('namespace')).toBe( - screen.getByRole('button', { name: 'namespacePicker.placeholder' }), + screen.getByRole('button', { name: 'Namespace: @active-team' }), ) }) diff --git a/web/src/shared/components/namespace-picker.tsx b/web/src/shared/components/namespace-picker.tsx index ab918629..153a5e43 100644 --- a/web/src/shared/components/namespace-picker.tsx +++ b/web/src/shared/components/namespace-picker.tsx @@ -17,6 +17,7 @@ const PAGE_SIZE = 20 interface NamespacePickerProps { id?: string + accessibleLabel?: string value: string onValueChange: (slug: string) => void status?: 'ACTIVE' | 'FROZEN' | 'ARCHIVED' @@ -29,6 +30,7 @@ interface NamespacePickerProps { */ export function NamespacePicker({ id, + accessibleLabel, value, onValueChange, status, @@ -40,6 +42,7 @@ export function NamespacePicker({ const [page, setPage] = useState(0) const [search, setSearch] = useState('') const debouncedSearch = useDebounce(search.trim(), 300) + const triggerText = value ? `@${value}` : emptyValueLabel ?? t('namespacePicker.placeholder') const query = useMyNamespacesPage({ page, size: PAGE_SIZE, @@ -60,8 +63,15 @@ export function NamespacePicker({ return ( -