Skip to content

Commit 622eda0

Browse files
authored
change error codes table to all status codes table (github#26518)
1 parent 7f3b259 commit 622eda0

File tree

5 files changed

+28
-46
lines changed

5 files changed

+28
-46
lines changed

components/rest/RestOperation.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +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
20+
const nonErrorResponses = operation.responses.filter(
21+
(response) => parseInt(response.httpStatusCode) < 400
22+
)
1723

1824
return (
1925
<div>
@@ -34,7 +40,7 @@ export function RestOperation({ operation }: Props) {
3440
{operation['x-codeSamples'] && operation['x-codeSamples'].length > 0 && (
3541
<RestCodeSamples slug={operation.slug} xCodeSamples={operation['x-codeSamples']} />
3642
)}
37-
<RestResponse responses={operation.responses} />
43+
<RestResponse responses={nonErrorResponses} />
3844
{(operation.notes.length > 0 || operation['x-github'].enabledForGitHubApps) && (
3945
<RestNotes
4046
notes={operation.notes}
@@ -44,7 +50,7 @@ export function RestOperation({ operation }: Props) {
4450
{previews && (
4551
<RestPreviewNotice slug={operation.slug} previews={operation['x-github'].previews} />
4652
)}
47-
<RestResponse responses={operation.responses} variant="error" />
53+
<RestStatusCodes heading={t('rest.reference.status_codes')} responses={operation.responses} />
4854
</div>
4955
)
5056
}

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
</>

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)