-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathsubcategory.tsx
More file actions
96 lines (84 loc) · 3.31 KB
/
subcategory.tsx
File metadata and controls
96 lines (84 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { GetServerSideProps } from 'next'
import { Operation } from '@/rest/components/types'
import { RestReferencePage } from '@/rest/components/RestReferencePage'
import {
addUINamespaces,
getMainContext,
MainContext,
MainContextT,
} from '@/frame/components/context/MainContext'
import {
AutomatedPageContext,
AutomatedPageContextT,
getAutomatedPageContextFromRequest,
} from '@/automated-pipelines/components/AutomatedPageContext'
import type { MiniTocItem } from '@/frame/components/context/ArticleContext'
type MinitocItemsT = {
restOperationsMiniTocItems: MiniTocItem[]
}
type Props = {
mainContext: MainContextT
automatedPageContext: AutomatedPageContextT
restOperations: Operation[]
}
export default function SubCategory({ mainContext, automatedPageContext, restOperations }: Props) {
return (
<MainContext.Provider value={mainContext}>
<AutomatedPageContext.Provider value={automatedPageContext}>
<RestReferencePage restOperations={restOperations} />
</AutomatedPageContext.Provider>
</MainContext.Provider>
)
}
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
const { default: getRest, getRestMiniTocItems } = await import('@/rest/lib/index')
const req = context.req as any
const res = context.res as any
// e.g. the `activity` from `/en/rest/activity/events`
const category = context.params!.category as string
let subCategory = context.params!.subcategory as string
const currentVersion = context.params!.versionId as string
const currentLanguage = req.context.currentLanguage as string
const allVersions = req.context.allVersions
const queryApiVersion = context.query.apiVersion
const apiVersion = allVersions[currentVersion].apiVersions.includes(queryApiVersion)
? queryApiVersion
: allVersions[currentVersion].latestApiVersion
// For pages with category level only operations like /rest/billing, we set
// the subcategory's value to be the category for the call to getRest()
if (!subCategory) {
subCategory = category
}
const restData = await getRest(currentVersion, apiVersion)
const restOperations = (restData && restData[category] && restData[category][subCategory]) || []
// Gets the miniTocItems in the article context. At this point it will only
// include miniTocItems generated from the Markdown pages in
// content/rest/*
const { miniTocItems } = getAutomatedPageContextFromRequest(req)
// When operations exist, update the miniTocItems in the article context
// with the list of operations in the OpenAPI.
// The context passed will have the Markdown content for the language
// of the page being requested and the Markdown will be rendered
// using the `currentVersion`
if (restOperations) {
const { restOperationsMiniTocItems } = (await getRestMiniTocItems(
category,
subCategory,
apiVersion,
restOperations,
currentLanguage,
currentVersion,
req.context,
)) as MinitocItemsT
restOperationsMiniTocItems && miniTocItems.push(...restOperationsMiniTocItems)
}
const mainContext = await getMainContext(req, res)
addUINamespaces(req, mainContext.data.ui, ['parameter_table', 'rest_reference'])
return {
props: {
restOperations,
mainContext,
automatedPageContext: getAutomatedPageContextFromRequest(req),
},
}
}