fix(skills): hide main navigation on detail pages

This commit is contained in:
zxhlyh 2026-07-31 15:02:22 +08:00
parent f3853f48df
commit 779f57902e
2 changed files with 36 additions and 4 deletions

View File

@ -196,6 +196,31 @@ describe('MainNavLayout', () => {
expect(screen.getByRole('main')).toHaveTextContent('new knowledge detail')
})
it('hides the global main nav on a skill detail route', () => {
;(usePathname as Mock).mockReturnValue('/skills/skill-1')
render(
<MainNavLayout>
<div>skill detail</div>
</MainNavLayout>,
)
expect(screen.queryByTestId('main-nav')).not.toBeInTheDocument()
expect(screen.getByRole('main')).toHaveTextContent('skill detail')
})
it('keeps the global main nav on the skills collection route', () => {
;(usePathname as Mock).mockReturnValue('/skills')
render(
<MainNavLayout>
<div>skills collection</div>
</MainNavLayout>,
)
expect(screen.getByTestId('main-nav')).toBeInTheDocument()
})
it.each([
'/datasets/create',
'/datasets/new/create',

View File

@ -151,14 +151,21 @@ function isDatasetDetailPathname(pathname: string) {
return true
}
function isSkillDetailPathname(pathname: string) {
const [section, skillId] = pathname.split('/').filter(Boolean)
return section === 'skills' && !!skillId
}
export function shouldHideMainNavigation(pathname: string) {
const [section, namespace, knowledgeSpaceId] = pathname.split('/').filter(Boolean)
return (
section === 'datasets' &&
namespace === 'new' &&
!!knowledgeSpaceId &&
knowledgeSpaceId !== 'create'
(section === 'datasets' &&
namespace === 'new' &&
!!knowledgeSpaceId &&
knowledgeSpaceId !== 'create') ||
isSkillDetailPathname(pathname)
)
}