diff --git a/components/sidebar/ProductCollapsibleSection.tsx b/components/sidebar/ProductCollapsibleSection.tsx
index c1f5198fcd39..94f6c2e19e81 100644
--- a/components/sidebar/ProductCollapsibleSection.tsx
+++ b/components/sidebar/ProductCollapsibleSection.tsx
@@ -1,122 +1,77 @@
import cx from 'classnames'
-import { useState, SyntheticEvent } from 'react'
-import { ChevronDownIcon } from '@primer/octicons-react'
-import { ActionList } from '@primer/react'
+import { TreeView } from '@primer/react'
import { Link } from 'components/Link'
import { ProductTreeNode } from 'components/context/MainContext'
import { EventType, sendEvent } from 'src/events/browser'
-import styles from './SidebarProduct.module.scss'
type SectionProps = {
routePath: string
page: ProductTreeNode
title: string
- defaultOpen: boolean
}
export const ProductCollapsibleSection = (props: SectionProps) => {
- const { routePath, defaultOpen, title, page } = props
- const [isOpen, setIsOpen] = useState(defaultOpen)
-
- const onToggle = (e: SyntheticEvent) => {
- const newIsOpen = (e.target as HTMLDetailsElement).open
- setIsOpen(newIsOpen)
- sendEvent({
- type: EventType.navigate,
- navigate_label: `details ${newIsOpen ? 'open' : 'close'}: ${title}`,
- })
- }
-
+ const { routePath, page } = props
// The lowest level page link displayed in the tree
const renderTerminalPageLink = (page: ProductTreeNode) => {
const title = page.shortTitle || page.title
-
const isCurrent = routePath === page.href
+
return (
-
- {
+ sendEvent({
+ type: EventType.navigate,
+ navigate_label: `product page navigate to: ${page.href}`,
+ })
+ }}
>
{title}
-
-
+
+
)
}
return (
-
-
-
-
-
- {
+ <>
+ {/* */}
+ {page.childPages[0]?.documentType === 'mapTopic' ? (
<>
- {/* */}
- {page.childPages[0]?.documentType === 'mapTopic' ? (
-
- {page.childPages.map((childPage, i) => {
- const childTitle = childPage.shortTitle || childPage.title
+ {page.childPages.map((childPage, i) => {
+ const childTitle = childPage.shortTitle || childPage.title
+ const isActive = routePath.includes(childPage.href)
+ const isCurrent = routePath === childPage.href
- const isActive = routePath.includes(childPage.href)
- const isCurrent = routePath === childPage.href
-
- return (
-
- e.stopPropagation()}
- className="details-reset"
- >
-
- {childTitle}
-
-
-
- {childPage.childPages.map((cp) => {
- return renderTerminalPageLink(cp)
- })}
-
-
-
-
- )
- })}
-
- ) : page.childPages[0]?.documentType === 'article' ? (
-
-
- {page.childPages.map(renderTerminalPageLink)}
-
-
- ) : null}
+ return (
+
+
+ {childTitle}
+
+ {childPage.childPages.map((cp) => {
+ return renderTerminalPageLink(cp)
+ })}
+
+
+
+ )
+ })}
>
- }
-
+ ) : page.childPages[0]?.documentType === 'article' ? (
+
+ {page.childPages.map((cp) => {
+ return renderTerminalPageLink(cp)
+ })}
+
+ ) : null}
+ >
)
}
diff --git a/components/sidebar/RestCollapsibleSection.module.scss b/components/sidebar/RestCollapsibleSection.module.scss
new file mode 100644
index 000000000000..b22d8723c7fe
--- /dev/null
+++ b/components/sidebar/RestCollapsibleSection.module.scss
@@ -0,0 +1,14 @@
+.operationWidth {
+ li div div span {
+ white-space: normal !important;
+ padding: 2px;
+ }
+}
+
+.toggleHover {
+ li div div {
+ &:hover {
+ background-color: transparent !important;
+ }
+ }
+}
diff --git a/components/sidebar/RestCollapsibleSection.tsx b/components/sidebar/RestCollapsibleSection.tsx
index c68d294ce13d..095b4365fb76 100644
--- a/components/sidebar/RestCollapsibleSection.tsx
+++ b/components/sidebar/RestCollapsibleSection.tsx
@@ -1,45 +1,33 @@
import { useRouter } from 'next/router'
import cx from 'classnames'
-import { useState, useEffect, SyntheticEvent, ReactElement } from 'react'
-import { ChevronDownIcon } from '@primer/octicons-react'
-import { ActionList } from '@primer/react'
+import { useState, useEffect } from 'react'
+import { TreeView } from '@primer/react'
import { Link } from 'components/Link'
import { ProductTreeNode } from 'components/context/MainContext'
import { EventType, sendEvent } from 'src/events/browser'
import { useAutomatedPageContext } from 'components/context/AutomatedPageContext'
import type { MiniTocItem } from 'components/context/ArticleContext'
-import styles from './SidebarProduct.module.scss'
+
+import styles from './RestCollapsibleSection.module.scss'
+
+let prevTarget: object | undefined
type SectionProps = {
routePath: string
page: ProductTreeNode
title: string
- defaultOpen: boolean
isStandaloneCategory: boolean
}
-type ConditionalLinkTypes = {
- condition: boolean
- wrapper: Function
- children: ReactElement
-}
-
export const RestCollapsibleSection = (props: SectionProps) => {
const router = useRouter()
- const { routePath, defaultOpen, title, page, isStandaloneCategory } = props
- const [isOpen, setIsOpen] = useState(defaultOpen)
+ const { routePath, title, page, isStandaloneCategory } = props
const [currentAnchor, setCurrentAnchor] = useState('')
const [visibleAnchor, setVisibleAnchor] = useState('')
-
- const onToggle = (e: SyntheticEvent) => {
- const newIsOpen = (e.target as HTMLDetailsElement).open
- setIsOpen(newIsOpen)
- sendEvent({
- type: EventType.navigate,
- navigate_label: `details ${newIsOpen ? 'open' : 'close'}: ${title}`,
- })
- }
+ const isActive = routePath.includes(page.href + '/') || routePath === page.href
+ const [standAloneExpanded, setStandAloneExpanded] = useState(isActive)
+ const [mapTopicExpanded, setMapTopicExpanded] = useState(isActive)
const miniTocItems =
router.query.productId === 'rest' ||
@@ -100,138 +88,126 @@ export const RestCollapsibleSection = (props: SectionProps) => {
}
}
}, [miniTocItems])
- // This wrapper solves the issue of having standalone categories not
- // link to the new page. We want standalone categories to have links
- // just like maptopics/subcategories.
- const ConditionalLinkWrapper = ({ condition, wrapper, children }: ConditionalLinkTypes) =>
- condition ? wrapper(children) : children
+
+ useEffect(() => {
+ setMapTopicExpanded(true)
+ }, [router.query.subcategory])
const renderRestAnchorLink = (miniTocItem: MiniTocItem) => {
const miniTocAnchor = miniTocItem.contents.href
const title = miniTocItem.contents.title
- const isCurrent = visibleAnchor === miniTocAnchor
+ const isAnchorCurrent = visibleAnchor === miniTocAnchor
+
return (
- setVisibleAnchor(miniTocAnchor)}
+ href={miniTocAnchor}
+ className={cx(styles.operationWidth, 'color-fg-default no-underline')}
>
- setVisibleAnchor(miniTocAnchor)}
- href={miniTocAnchor}
+
{title}
-
-
+
+
)
}
return (
-
-
- (
-
- {children}
-
- )}
+ // This is where a category has no subcategory
+
+ {isStandaloneCategory ? (
+
-
-
-
-
- {
- <>
- {/* */}
-
+ )}
+
)
}
diff --git a/components/sidebar/SidebarHomepage.tsx b/components/sidebar/SidebarHomepage.tsx
index 86bf0316c011..e64e3dba51e7 100644
--- a/components/sidebar/SidebarHomepage.tsx
+++ b/components/sidebar/SidebarHomepage.tsx
@@ -1,6 +1,6 @@
import { useRouter } from 'next/router'
import { LinkExternalIcon } from '@primer/octicons-react'
-import { ActionList } from '@primer/react'
+import { TreeView } from '@primer/react'
import { useVersion } from 'components/hooks/useVersion'
import { useMainContext } from 'components/context/MainContext'
@@ -12,44 +12,37 @@ export const SidebarHomepage = () => {
const { activeProducts, isFPT } = useMainContext()
return (
-
-
-
- {activeProducts
- .filter(
- (product) => isFPT || product.versions?.includes(currentVersion) || product.external
- )
- .map((product) => {
- const href = `${!product.external ? `/${router.locale}` : ''}${
- product.versions?.includes(currentVersion) && !isFPT
- ? `/${currentVersion}/${product.id}`
- : product.href
- }`
+
+
+ {activeProducts
+ .filter(
+ (product) => isFPT || product.versions?.includes(currentVersion) || product.external
+ )
+ .map((product) => {
+ const href = `${!product.external ? `/${router.locale}` : ''}${
+ product.versions?.includes(currentVersion) && !isFPT
+ ? `/${currentVersion}/${product.id}`
+ : product.href
+ }`
- return (
-
+
-
- {product.name}
- {product.external && (
-
-
-
- )}
-
-
- )
- })}
-
-
-
+ {product.name}
+ {product.external && (
+
+
+
+ )}
+
+
+ )
+ })}
+
+
)
}
diff --git a/components/sidebar/SidebarProduct.module.scss b/components/sidebar/SidebarProduct.module.scss
deleted file mode 100644
index 5696dd25683a..000000000000
--- a/components/sidebar/SidebarProduct.module.scss
+++ /dev/null
@@ -1,13 +0,0 @@
-.sidebarArticle::before {
- content: "";
- position: absolute;
- left: calc(1.5rem + 2px);
- height: 100%;
- border-left: 1px solid var(--color-fg-default);
- width: 1px;
- top: 0;
-}
-
-.sidebarArticleActive::before {
- border-left-width: 2px;
-}
diff --git a/components/sidebar/SidebarProduct.tsx b/components/sidebar/SidebarProduct.tsx
index d4daac4f93e0..70817d0d6fe7 100644
--- a/components/sidebar/SidebarProduct.tsx
+++ b/components/sidebar/SidebarProduct.tsx
@@ -1,5 +1,6 @@
import { useRouter } from 'next/router'
import { useEffect, useRef } from 'react'
+import { TreeView } from '@primer/react'
import cx from 'classnames'
import { useMainContext } from 'components/context/MainContext'
@@ -10,13 +11,13 @@ import { ProductCollapsibleSection } from './ProductCollapsibleSection'
export const SidebarProduct = () => {
const router = useRouter()
- const sidebarRef = useRef(null)
+ const sidebarRef = useRef(null)
const { currentProduct, currentProductTree } = useMainContext()
const { t } = useTranslation(['products'])
const isRestPage = currentProduct && currentProduct.id === 'rest'
useEffect(() => {
- const activeArticle = document.querySelector('[data-is-current-page=true]')
+ const activeArticle = document.querySelector('[aria-expanded=true]')
// Setting to the top doesn't give enough context of surrounding categories
activeArticle?.scrollIntoView({ block: 'center' })
// scrollIntoView affects some articles that are very low in the sidebar
@@ -32,48 +33,50 @@ export const SidebarProduct = () => {
// remove query string and hash
const routePath = `/${router.locale}${router.asPath.split('?')[0].split('#')[0]}`
- const hasExactCategory = !!currentProductTree?.childPages.find(({ href }) =>
- routePath.includes(href)
- )
-
const productSection = () => (
-
-
+
+
{currentProductTree &&
currentProductTree.childPages.map((childPage, i) => {
const isStandaloneCategory = childPage.documentType === 'article'
-
const childTitle = childPage.shortTitle || childPage.title
const isActive =
routePath.includes(childPage.href + '/') || routePath === childPage.href
- const defaultOpen = hasExactCategory ? isActive : false
+
return (
-
+
{isStandaloneCategory ? (
-
- {childTitle}
-
+
+ {childTitle}
+
+
) : (
-
+
+ {childTitle}
+
+
+
+
)}
-
+
)
})}
-
-
+
+
)
const restSection = () => {
@@ -91,89 +94,79 @@ export const SidebarProduct = () => {
)
return (
<>
-
-