fix: docs sidebar collapse and highlight (#22108)

* fix: make sidebar collapse work when hash is selected

* fix: persist sidebar highlight when hash is selected

* chore: cleanup

* fix: fix enterprise sso case
This commit is contained in:
Charis
2024-03-25 10:31:00 -04:00
committed by GitHub
parent 01cd022722
commit fa8c9f360b
6 changed files with 27 additions and 32 deletions

View File

@@ -1,39 +1,23 @@
import * as Accordion from '@radix-ui/react-accordion'
import { useRouter } from 'next/router'
import React from 'react'
import NavigationMenuGuideListItems from './NavigationMenuGuideListItems'
import * as NavItems from './NavigationMenu.constants'
interface Props {
id: string
collapsible?: boolean
value?: string[]
}
const NavigationMenuGuideList: React.FC<Props> = ({ id, value }) => {
const router = useRouter()
import * as NavItems from './NavigationMenu.constants'
import { getPathWithoutHash } from './NavigationMenu.utils'
import NavigationMenuGuideListItems from './NavigationMenuGuideListItems'
const NavigationMenuGuideList = ({ id }: { id: string }) => {
const path = useRouter().asPath
const url = getPathWithoutHash(path)
const firstLevelRoute = url?.split('/')?.slice(0, 4)?.join('/')
const menu = NavItems[id]
// get url
const url = router.asPath
// We need to decide how deep we want the menu to be for matching urls
// if the links are really deep, we don't want to match all the way out
// But we need to reach out further to make the structure of /resources/postgres/ work
// look at /resources/postgres/ vs /auth/phone-login for how these are different
let firstLevelRoute
if (url.includes('resources/postgres/')) {
firstLevelRoute = url?.split('/')?.slice(0, 5)?.join('/')
} else {
firstLevelRoute = url?.split('/')?.slice(0, 4)?.join('/')
}
return (
<Accordion.Root
collapsible={true}
key={id}
type={value ? 'multiple' : 'single'}
value={value ?? firstLevelRoute}
type="single"
value={firstLevelRoute}
className="transition-all duration-150 ease-out opacity-100 ml-0 delay-150"
>
<NavigationMenuGuideListItems menu={menu} id={id} />