docs: fix sidebar items not showing if they have same title in API reference (#11122)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-01-24 18:54:21 +02:00
1 parent dc3a4b5c40
commit 8038a917ee
5 files changed
+19 -20

No files matched your search

@@ -37,6 +37,7 @@ const TagPaths = ({ tag, className, paths }: TagPathsProps) => {
addItems(pathItems, { addItems(pathItems, {
section: SidebarItemSections.DEFAULT, section: SidebarItemSections.DEFAULT,
parent: { parent: {
type: "category",
title: tag.name, title: tag.name,
path: "", path: "",
changeLoaded: true, changeLoaded: true,
@@ -73,8 +73,9 @@ const TagSectionSchema = ({ schema, tagName }: TagSectionSchemaProps) => {
{ {
section: SidebarItemSections.DEFAULT, section: SidebarItemSections.DEFAULT,
parent: { parent: {
type: "category",
title: tagName, title: tagName,
path: tagSlugName, path: "",
changeLoaded: true, changeLoaded: true,
}, },
indexPosition: 0, indexPosition: 0,
@@ -1,19 +1,12 @@
"use client" "use client"
import { ExpandedDocument, SecuritySchemeObject } from "@/types/openapi" import { ExpandedDocument, SecuritySchemeObject } from "@/types/openapi"
import { import { ReactNode, createContext, useContext, useEffect, useMemo } from "react"
ReactNode,
createContext,
useCallback,
useContext,
useEffect,
useMemo,
} from "react"
import { SidebarItem, SidebarItemSections } from "types" import { SidebarItem, SidebarItemSections } from "types"
import getSectionId from "../utils/get-section-id" import getSectionId from "../utils/get-section-id"
import getTagChildSidebarItems from "../utils/get-tag-child-sidebar-items" import getTagChildSidebarItems from "../utils/get-tag-child-sidebar-items"
import { usePathname, useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { usePrevious, useSidebar } from "docs-ui" import { useSidebar } from "docs-ui"
type BaseSpecsContextType = { type BaseSpecsContextType = {
baseSpecs: ExpandedDocument | undefined baseSpecs: ExpandedDocument | undefined
@@ -29,10 +22,7 @@ type BaseSpecsProviderProps = {
const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => { const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => {
const router = useRouter() const router = useRouter()
const { items, activePath, addItems, setActivePath, resetItems } = const { activePath, addItems, setActivePath, resetItems } = useSidebar()
useSidebar()
const pathname = usePathname()
const prevPathName = usePrevious(pathname)
const getSecuritySchema = ( const getSecuritySchema = (
securityName: string securityName: string
@@ -21,6 +21,7 @@ import {
InteractiveSidebarItem, InteractiveSidebarItem,
SidebarItemCategory, SidebarItemCategory,
SidebarItemLinkWithParent, SidebarItemLinkWithParent,
SidebarItemTypes,
} from "types" } from "types"
import { useIsBrowser } from "../BrowserProvider" import { useIsBrowser } from "../BrowserProvider"
@@ -70,6 +71,7 @@ export const SidebarContext = createContext<SidebarContextType | null>(null)
export type ActionOptionsType = { export type ActionOptionsType = {
section?: SidebarItemSections section?: SidebarItemSections
parent?: { parent?: {
type: SidebarItemTypes
path: string path: string
title: string title: string
changeLoaded?: boolean changeLoaded?: boolean
@@ -106,17 +108,20 @@ export const isSidebarItemLink = (
} }
const areItemsEqual = (itemA: SidebarItem, itemB: SidebarItem): boolean => { const areItemsEqual = (itemA: SidebarItem, itemB: SidebarItem): boolean => {
if (itemA.type === "separator" || itemB.type === "separator") { if (
itemA.type === "separator" ||
itemB.type === "separator" ||
itemA.type !== itemB.type
) {
return false return false
} }
const hasSameTitle = itemA.title === itemB.title const hasSameTitle = itemA.title === itemB.title
const hasSamePath = const hasSamePath =
isSidebarItemLink(itemA) && !isSidebarItemLink(itemA) ||
isSidebarItemLink(itemB) && !isSidebarItemLink(itemB) ||
itemA.type === itemB.type &&
itemA.path === itemB.path itemA.path === itemB.path
return hasSameTitle || hasSamePath return hasSameTitle && hasSamePath
} }
const findItem = ( const findItem = (
+2
View File
@@ -17,6 +17,8 @@ export type SidebarItemCommon = {
description?: string description?: string
} }
export type SidebarItemTypes = "category" | "sub-category" | "link" | "ref"
export type SidebarItemLink = SidebarItemCommon & { export type SidebarItemLink = SidebarItemCommon & {
type: "link" | "ref" type: "link" | "ref"
path: string path: string