1
1
"use client"
2
2
3
- import type { OpenAPIV3 } from "openapi-types"
4
- import type { Operation , PathsObject } from "@/types/openapi"
5
- import { useSidebar } from "docs-ui"
3
+ import type { Operation , PathsObject , TagObject } from "@/types/openapi"
4
+ import { findSidebarItem , useSidebar } from "docs-ui"
6
5
import { Fragment , Suspense , useEffect } from "react"
7
6
import dynamic from "next/dynamic"
8
7
import type { TagOperationProps } from "../Operation"
9
8
import clsx from "clsx"
10
9
import getTagChildSidebarItems from "@/utils/get-tag-child-sidebar-items"
11
10
import { useLoading } from "@/providers/loading"
12
11
import DividedLoading from "@/components/DividedLoading"
13
- import { SidebarItemSections , SidebarItem , SidebarItemCategory } from "types"
12
+ import { Sidebar } from "types"
14
13
15
14
const TagOperation = dynamic < TagOperationProps > (
16
15
async ( ) => import ( "../Operation" )
17
16
) as React . FC < TagOperationProps >
18
17
19
18
export type TagPathsProps = {
20
- tag : OpenAPIV3 . TagObject
19
+ tag : TagObject
21
20
paths : PathsObject
22
21
} & React . HTMLAttributes < HTMLDivElement >
23
22
24
23
const TagPaths = ( { tag, className, paths } : TagPathsProps ) => {
25
- const { items , addItems, findItemInSection } = useSidebar ( )
24
+ const { shownSidebar , addItems } = useSidebar ( )
26
25
const { loading } = useLoading ( )
27
26
28
27
useEffect ( ( ) => {
28
+ if ( ! shownSidebar ) {
29
+ return
30
+ }
31
+
29
32
if ( paths ) {
30
- const parentItem = findItemInSection (
31
- items [ SidebarItemSections . DEFAULT ] ,
32
- { title : tag . name } ,
33
- false
34
- ) as SidebarItemCategory
35
- const pathItems : SidebarItem [ ] = getTagChildSidebarItems ( paths )
36
- if ( ( parentItem ?. children ?. length || 0 ) < pathItems . length ) {
33
+ const parentItem = findSidebarItem ( {
34
+ sidebarItems :
35
+ "items" in shownSidebar
36
+ ? shownSidebar . items
37
+ : shownSidebar . children || [ ] ,
38
+ item : { title : tag . name , type : "category" } ,
39
+ checkChildren : false ,
40
+ } ) as Sidebar . SidebarItemCategory
41
+ const pathItems : Sidebar . SidebarItem [ ] = getTagChildSidebarItems ( paths )
42
+ const targetLength =
43
+ pathItems . length + ( tag [ "x-associatedSchema" ] ? 1 : 0 )
44
+ if ( ( parentItem . children ?. length || 0 ) < targetLength ) {
37
45
addItems ( pathItems , {
38
- section : SidebarItemSections . DEFAULT ,
46
+ sidebar_id : shownSidebar . sidebar_id ,
39
47
parent : {
40
48
type : "category" ,
41
49
title : tag . name ,
@@ -46,7 +54,7 @@ const TagPaths = ({ tag, className, paths }: TagPathsProps) => {
46
54
}
47
55
}
48
56
// eslint-disable-next-line react-hooks/exhaustive-deps
49
- } , [ paths ] )
57
+ } , [ paths , shownSidebar ?. sidebar_id ] )
50
58
51
59
return (
52
60
< Suspense >
0 commit comments