Skip to content

Commit 916dc90

Browse files
authored
Merge pull request github#16663 from github/repo-sync
repo sync
2 parents d1a0b3f + f2519a8 commit 916dc90

File tree

8 files changed

+42
-77
lines changed

8 files changed

+42
-77
lines changed

components/rest/PreviewsRow.tsx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { useTranslation } from 'components/hooks/useTranslation'
33

44
type Props = {
55
slug: string
6-
hasRequiredPreviews: boolean
76
xGitHub: xGitHub
87
}
98

10-
export function PreviewsRow({ slug, hasRequiredPreviews, xGitHub }: Props) {
9+
export function PreviewsRow({ slug, xGitHub }: Props) {
1110
const { t } = useTranslation('products')
1211
const hasPreviews = xGitHub.previews && xGitHub.previews.length > 0
1312

@@ -19,21 +18,17 @@ export function PreviewsRow({ slug, hasRequiredPreviews, xGitHub }: Props) {
1918
<td>string</td>
2019
<td>header</td>
2120
<td>
22-
{hasRequiredPreviews ? (
23-
<p>{t('rest.reference.preview_notice_to_change')}.</p>
24-
) : (
25-
<p className="m-0">
26-
Setting to
27-
<code>application/vnd.github.v3+json</code> is recommended.
28-
{hasPreviews && (
29-
<a href={`#${slug}-preview-notices`} className="d-inline">
30-
{xGitHub.previews.length > 1
31-
? ` ${t('rest.reference.see_preview_notices')}`
32-
: ` ${t('rest.reference.see_preview_notice')}`}
33-
</a>
34-
)}
35-
</p>
36-
)}
21+
<p className="m-0">
22+
Setting to
23+
<code>application/vnd.github.v3+json</code> is recommended.
24+
{hasPreviews && (
25+
<a href={`#${slug}-preview-notices`} className="d-inline">
26+
{xGitHub.previews.length > 1
27+
? ` ${t('rest.reference.see_preview_notices')}`
28+
: ` ${t('rest.reference.see_preview_notice')}`}
29+
</a>
30+
)}
31+
</p>
3732
</td>
3833
</tr>
3934
)

components/rest/RestOperation.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import { RestResponse } from './RestResponse'
66
import { Operation } from './types'
77
import { RestNotes } from './RestNotes'
88
import { RestPreviewNotice } from './RestPreviewNotice'
9+
import { useTranslation } from 'components/hooks/useTranslation'
10+
import { RestStatusCodes } from './RestStatusCodes'
911

1012
type Props = {
1113
operation: Operation
1214
index: number
1315
}
1416

1517
export function RestOperation({ operation }: Props) {
18+
const { t } = useTranslation('products')
1619
const previews = operation['x-github'].previews
17-
const hasRequiredPreviews = previews
18-
? previews.filter((preview) => preview.required).length > 0
19-
: false
20+
const nonErrorResponses = operation.responses.filter(
21+
(response) => parseInt(response.httpStatusCode) < 400
22+
)
2023

2124
return (
2225
<div>
@@ -29,7 +32,6 @@ export function RestOperation({ operation }: Props) {
2932
{operation.parameters && (
3033
<RestParameterTable
3134
slug={operation.slug}
32-
hasRequiredPreviews={hasRequiredPreviews}
3335
xGitHub={operation['x-github']}
3436
parameters={operation.parameters}
3537
bodyParameters={operation.bodyParameters}
@@ -38,7 +40,7 @@ export function RestOperation({ operation }: Props) {
3840
{operation['x-codeSamples'] && operation['x-codeSamples'].length > 0 && (
3941
<RestCodeSamples slug={operation.slug} xCodeSamples={operation['x-codeSamples']} />
4042
)}
41-
<RestResponse responses={operation.responses} />
43+
<RestResponse responses={nonErrorResponses} />
4244
{(operation.notes.length > 0 || operation['x-github'].enabledForGitHubApps) && (
4345
<RestNotes
4446
notes={operation.notes}
@@ -48,7 +50,7 @@ export function RestOperation({ operation }: Props) {
4850
{previews && (
4951
<RestPreviewNotice slug={operation.slug} previews={operation['x-github'].previews} />
5052
)}
51-
<RestResponse responses={operation.responses} variant="error" />
53+
<RestStatusCodes heading={t('rest.reference.status_codes')} responses={operation.responses} />
5254
</div>
5355
)
5456
}

components/rest/RestParameterTable.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@ import { BodyParameterRows } from './BodyParametersRows'
88

99
type Props = {
1010
slug: string
11-
hasRequiredPreviews: boolean
1211
xGitHub: xGitHub
1312
parameters: Array<Parameter>
1413
bodyParameters: Array<BodyParameter>
1514
}
1615

17-
export function RestParameterTable({
18-
slug,
19-
hasRequiredPreviews,
20-
xGitHub,
21-
parameters,
22-
bodyParameters,
23-
}: Props) {
16+
export function RestParameterTable({ slug, xGitHub, parameters, bodyParameters }: Props) {
2417
const { t } = useTranslation('products')
2518

2619
return (
@@ -38,7 +31,7 @@ export function RestParameterTable({
3831
</tr>
3932
</thead>
4033
<tbody>
41-
<PreviewsRow slug={slug} hasRequiredPreviews={hasRequiredPreviews} xGitHub={xGitHub} />
34+
<PreviewsRow slug={slug} xGitHub={xGitHub} />
4235
<ParameterRows parameters={parameters} />
4336
<BodyParameterRows slug={slug} bodyParameters={bodyParameters} />
4437
</tbody>

components/rest/RestResponse.tsx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
11
import { CodeResponse } from './types'
22
import { CodeBlock } from './CodeBlock'
3-
import { useTranslation } from 'components/hooks/useTranslation'
4-
import { RestResponseTable } from './RestResponseTable'
53

64
type Props = {
75
responses: Array<CodeResponse>
8-
variant?: 'non-error' | 'error'
96
}
107

118
export function RestResponse(props: Props) {
12-
const { responses, variant = 'non-error' } = props
13-
const { t } = useTranslation('products')
9+
const { responses } = props
1410

1511
if (!responses || responses.length === 0) {
1612
return null
1713
}
1814

19-
const filteredResponses = responses.filter((response) => {
20-
const responseCode = parseInt(response.httpStatusCode)
21-
22-
if (variant === 'error') {
23-
return responseCode >= 400
24-
} else {
25-
return responseCode < 400
26-
}
27-
})
28-
29-
if (filteredResponses.length === 0) {
30-
return null
31-
}
32-
33-
if (variant === 'error') {
34-
return (
35-
<RestResponseTable heading={t('rest.reference.error_codes')} responses={filteredResponses} />
36-
)
37-
}
38-
3915
return (
4016
<>
41-
{filteredResponses.map((response, index) => {
17+
{responses.map((response, index) => {
4218
return (
4319
<div key={`${response.httpStatusMessage}-${index}}`}>
4420
<h4 dangerouslySetInnerHTML={{ __html: response.description }} />

components/rest/RestResponseTable.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
th {
99
border: 0;
1010
font-weight: normal;
11+
background-color: transparent;
1112
}
1213

1314
th:first-child {

components/rest/RestResponseTable.tsx renamed to components/rest/RestStatusCodes.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = {
88
responses: Array<CodeResponse>
99
}
1010

11-
export function RestResponseTable({ heading, responses }: Props) {
11+
export function RestStatusCodes({ heading, responses }: Props) {
1212
const { t } = useTranslation('products')
1313

1414
return (
@@ -22,22 +22,21 @@ export function RestResponseTable({ heading, responses }: Props) {
2222
</tr>
2323
</thead>
2424
<tbody>
25-
{responses.map((response, index) => {
26-
return (
27-
<tr key={`${response.description}-${index}}`}>
28-
<td>
29-
<code>{response.httpStatusCode}</code>
30-
</td>
31-
<td>
32-
{response.description ? (
33-
<div dangerouslySetInnerHTML={{ __html: response.description }} />
34-
) : (
35-
response.httpStatusMessage
36-
)}
37-
</td>
38-
</tr>
39-
)
40-
})}
25+
{responses.map((response, index) => (
26+
<tr key={`${response.description}-${index}}`}>
27+
<td>
28+
<code>{response.httpStatusCode}</code>
29+
</td>
30+
<td>
31+
{response.description &&
32+
response.description.toLowerCase() !== '<p>response</p>' ? (
33+
<div dangerouslySetInnerHTML={{ __html: response.description }} />
34+
) : (
35+
response.httpStatusMessage
36+
)}
37+
</td>
38+
</tr>
39+
))}
4140
</tbody>
4241
</table>
4342
</>

components/rest/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export interface Operation {
66
notes: Array<string>
77
requestPath: string
88
responses: Array<CodeResponse>
9-
hasRequiredPreviews: boolean
109
parameters: Array<Parameter>
1110
bodyParameters: Array<BodyParameter>
1211
'x-github': xGitHub

data/ui.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ products:
113113
notes: Notes
114114
parameters: Parameters
115115
response: Response
116-
error_codes: Error Codes
116+
status_codes: Status codes
117117
http_status_code: HTTP Status Code
118118
code_sample: Code sample
119119
code_samples: Code samples

0 commit comments

Comments
 (0)