forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RestOperation.tsx
62 lines (50 loc) · 1.84 KB
/
RestOperation.tsx
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
import slugger from 'github-slugger'
import { RestOperationHeading } from './RestOperationHeading'
import { CodeBlock } from './CodeBlock'
import { RestParameterTable } from './RestParameterTable'
import { RestCodeSamples } from './RestCodeSamples'
import { RestStatusCodes } from './RestStatusCodes'
import { Operation } from './types'
import { RestNotes } from './RestNotes'
import { RestPreviewNotice } from './RestPreviewNotice'
import { useTranslation } from 'components/hooks/useTranslation'
type Props = {
operation: Operation
}
export function RestOperation({ operation }: Props) {
const { t } = useTranslation('products')
const slug = slugger.slug(operation.title)
const numPreviews = operation.previews.length
const hasStatusCodes = operation.statusCodes.length > 0
const hasCodeSamples = operation.codeExamples.length > 0
const hasParameters = operation.parameters.length > 0 || operation.bodyParameters.length > 0
return (
<div>
<RestOperationHeading
slug={slug}
title={operation.title}
descriptionHTML={operation.descriptionHTML}
/>
{operation.requestPath && (
<CodeBlock verb={operation.verb} codeBlock={operation.requestPath}></CodeBlock>
)}
{hasParameters && (
<RestParameterTable
slug={slug}
numPreviews={numPreviews}
parameters={operation.parameters}
bodyParameters={operation.bodyParameters}
/>
)}
{hasCodeSamples && <RestCodeSamples operation={operation} slug={slug} />}
{hasStatusCodes && (
<RestStatusCodes
heading={t('rest.reference.status_codes')}
statusCodes={operation.statusCodes}
/>
)}
{operation.enabledForGitHubApps && <RestNotes />}
{numPreviews > 0 && <RestPreviewNotice slug={slug} previews={operation.previews} />}
</div>
)
}