@@ -3,11 +3,10 @@ import { useTranslation } from 'components/hooks/useTranslation'
|
||||
|
||||
type Props = {
|
||||
slug: string
|
||||
hasRequiredPreviews: boolean
|
||||
xGitHub: xGitHub
|
||||
}
|
||||
|
||||
export function PreviewsRow({ slug, hasRequiredPreviews, xGitHub }: Props) {
|
||||
export function PreviewsRow({ slug, xGitHub }: Props) {
|
||||
const { t } = useTranslation('products')
|
||||
const hasPreviews = xGitHub.previews && xGitHub.previews.length > 0
|
||||
|
||||
@@ -19,21 +18,17 @@ export function PreviewsRow({ slug, hasRequiredPreviews, xGitHub }: Props) {
|
||||
<td>string</td>
|
||||
<td>header</td>
|
||||
<td>
|
||||
{hasRequiredPreviews ? (
|
||||
<p>{t('rest.reference.preview_notice_to_change')}.</p>
|
||||
) : (
|
||||
<p className="m-0">
|
||||
Setting to
|
||||
<code>application/vnd.github.v3+json</code> is recommended.
|
||||
{hasPreviews && (
|
||||
<a href={`#${slug}-preview-notices`} className="d-inline">
|
||||
{xGitHub.previews.length > 1
|
||||
? ` ${t('rest.reference.see_preview_notices')}`
|
||||
: ` ${t('rest.reference.see_preview_notice')}`}
|
||||
</a>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
<p className="m-0">
|
||||
Setting to
|
||||
<code>application/vnd.github.v3+json</code> is recommended.
|
||||
{hasPreviews && (
|
||||
<a href={`#${slug}-preview-notices`} className="d-inline">
|
||||
{xGitHub.previews.length > 1
|
||||
? ` ${t('rest.reference.see_preview_notices')}`
|
||||
: ` ${t('rest.reference.see_preview_notice')}`}
|
||||
</a>
|
||||
)}
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
|
||||
@@ -6,6 +6,8 @@ import { RestResponse } from './RestResponse'
|
||||
import { Operation } from './types'
|
||||
import { RestNotes } from './RestNotes'
|
||||
import { RestPreviewNotice } from './RestPreviewNotice'
|
||||
import { useTranslation } from 'components/hooks/useTranslation'
|
||||
import { RestStatusCodes } from './RestStatusCodes'
|
||||
|
||||
type Props = {
|
||||
operation: Operation
|
||||
@@ -13,10 +15,11 @@ type Props = {
|
||||
}
|
||||
|
||||
export function RestOperation({ operation }: Props) {
|
||||
const { t } = useTranslation('products')
|
||||
const previews = operation['x-github'].previews
|
||||
const hasRequiredPreviews = previews
|
||||
? previews.filter((preview) => preview.required).length > 0
|
||||
: false
|
||||
const nonErrorResponses = operation.responses.filter(
|
||||
(response) => parseInt(response.httpStatusCode) < 400
|
||||
)
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -29,7 +32,6 @@ export function RestOperation({ operation }: Props) {
|
||||
{operation.parameters && (
|
||||
<RestParameterTable
|
||||
slug={operation.slug}
|
||||
hasRequiredPreviews={hasRequiredPreviews}
|
||||
xGitHub={operation['x-github']}
|
||||
parameters={operation.parameters}
|
||||
bodyParameters={operation.bodyParameters}
|
||||
@@ -38,7 +40,7 @@ export function RestOperation({ operation }: Props) {
|
||||
{operation['x-codeSamples'] && operation['x-codeSamples'].length > 0 && (
|
||||
<RestCodeSamples slug={operation.slug} xCodeSamples={operation['x-codeSamples']} />
|
||||
)}
|
||||
<RestResponse responses={operation.responses} />
|
||||
<RestResponse responses={nonErrorResponses} />
|
||||
{(operation.notes.length > 0 || operation['x-github'].enabledForGitHubApps) && (
|
||||
<RestNotes
|
||||
notes={operation.notes}
|
||||
@@ -48,7 +50,7 @@ export function RestOperation({ operation }: Props) {
|
||||
{previews && (
|
||||
<RestPreviewNotice slug={operation.slug} previews={operation['x-github'].previews} />
|
||||
)}
|
||||
<RestResponse responses={operation.responses} variant="error" />
|
||||
<RestStatusCodes heading={t('rest.reference.status_codes')} responses={operation.responses} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,19 +8,12 @@ import { BodyParameterRows } from './BodyParametersRows'
|
||||
|
||||
type Props = {
|
||||
slug: string
|
||||
hasRequiredPreviews: boolean
|
||||
xGitHub: xGitHub
|
||||
parameters: Array<Parameter>
|
||||
bodyParameters: Array<BodyParameter>
|
||||
}
|
||||
|
||||
export function RestParameterTable({
|
||||
slug,
|
||||
hasRequiredPreviews,
|
||||
xGitHub,
|
||||
parameters,
|
||||
bodyParameters,
|
||||
}: Props) {
|
||||
export function RestParameterTable({ slug, xGitHub, parameters, bodyParameters }: Props) {
|
||||
const { t } = useTranslation('products')
|
||||
|
||||
return (
|
||||
@@ -38,7 +31,7 @@ export function RestParameterTable({
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<PreviewsRow slug={slug} hasRequiredPreviews={hasRequiredPreviews} xGitHub={xGitHub} />
|
||||
<PreviewsRow slug={slug} xGitHub={xGitHub} />
|
||||
<ParameterRows parameters={parameters} />
|
||||
<BodyParameterRows slug={slug} bodyParameters={bodyParameters} />
|
||||
</tbody>
|
||||
|
||||
@@ -1,44 +1,20 @@
|
||||
import { CodeResponse } from './types'
|
||||
import { CodeBlock } from './CodeBlock'
|
||||
import { useTranslation } from 'components/hooks/useTranslation'
|
||||
import { RestResponseTable } from './RestResponseTable'
|
||||
|
||||
type Props = {
|
||||
responses: Array<CodeResponse>
|
||||
variant?: 'non-error' | 'error'
|
||||
}
|
||||
|
||||
export function RestResponse(props: Props) {
|
||||
const { responses, variant = 'non-error' } = props
|
||||
const { t } = useTranslation('products')
|
||||
const { responses } = props
|
||||
|
||||
if (!responses || responses.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
const filteredResponses = responses.filter((response) => {
|
||||
const responseCode = parseInt(response.httpStatusCode)
|
||||
|
||||
if (variant === 'error') {
|
||||
return responseCode >= 400
|
||||
} else {
|
||||
return responseCode < 400
|
||||
}
|
||||
})
|
||||
|
||||
if (filteredResponses.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (variant === 'error') {
|
||||
return (
|
||||
<RestResponseTable heading={t('rest.reference.error_codes')} responses={filteredResponses} />
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{filteredResponses.map((response, index) => {
|
||||
{responses.map((response, index) => {
|
||||
return (
|
||||
<div key={`${response.httpStatusMessage}-${index}}`}>
|
||||
<h4 dangerouslySetInnerHTML={{ __html: response.description }} />
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
th {
|
||||
border: 0;
|
||||
font-weight: normal;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
th:first-child {
|
||||
|
||||
@@ -8,7 +8,7 @@ type Props = {
|
||||
responses: Array<CodeResponse>
|
||||
}
|
||||
|
||||
export function RestResponseTable({ heading, responses }: Props) {
|
||||
export function RestStatusCodes({ heading, responses }: Props) {
|
||||
const { t } = useTranslation('products')
|
||||
|
||||
return (
|
||||
@@ -22,22 +22,21 @@ export function RestResponseTable({ heading, responses }: Props) {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{responses.map((response, index) => {
|
||||
return (
|
||||
<tr key={`${response.description}-${index}}`}>
|
||||
<td>
|
||||
<code>{response.httpStatusCode}</code>
|
||||
</td>
|
||||
<td>
|
||||
{response.description ? (
|
||||
<div dangerouslySetInnerHTML={{ __html: response.description }} />
|
||||
) : (
|
||||
response.httpStatusMessage
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})}
|
||||
{responses.map((response, index) => (
|
||||
<tr key={`${response.description}-${index}}`}>
|
||||
<td>
|
||||
<code>{response.httpStatusCode}</code>
|
||||
</td>
|
||||
<td>
|
||||
{response.description &&
|
||||
response.description.toLowerCase() !== '<p>response</p>' ? (
|
||||
<div dangerouslySetInnerHTML={{ __html: response.description }} />
|
||||
) : (
|
||||
response.httpStatusMessage
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</>
|
||||
@@ -6,7 +6,6 @@ export interface Operation {
|
||||
notes: Array<string>
|
||||
requestPath: string
|
||||
responses: Array<CodeResponse>
|
||||
hasRequiredPreviews: boolean
|
||||
parameters: Array<Parameter>
|
||||
bodyParameters: Array<BodyParameter>
|
||||
'x-github': xGitHub
|
||||
|
||||
@@ -113,7 +113,7 @@ products:
|
||||
notes: Notes
|
||||
parameters: Parameters
|
||||
response: Response
|
||||
error_codes: Error Codes
|
||||
status_codes: Status codes
|
||||
http_status_code: HTTP Status Code
|
||||
code_sample: Code sample
|
||||
code_samples: Code samples
|
||||
|
||||
Reference in New Issue
Block a user