File tree Expand file tree Collapse file tree 5 files changed +128
-2
lines changed Expand file tree Collapse file tree 5 files changed +128
-2
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ export function RestOperation({ operation }: Props) {
48
48
{ previews && (
49
49
< RestPreviewNotice slug = { operation . slug } previews = { operation [ 'x-github' ] . previews } />
50
50
) }
51
+ < RestResponse responses = { operation . responses } variant = "error" />
51
52
</ div >
52
53
)
53
54
}
Original file line number Diff line number Diff line change 1
1
import { CodeResponse } from './types'
2
2
import { CodeBlock } from './CodeBlock'
3
+ import { useTranslation } from 'components/hooks/useTranslation'
4
+ import { RestResponseTable } from './RestResponseTable'
3
5
4
6
type Props = {
5
7
responses : Array < CodeResponse >
8
+ variant ?: 'non-error' | 'error'
6
9
}
7
10
8
- export function RestResponse ( { responses } : Props ) {
11
+ export function RestResponse ( props : Props ) {
12
+ const { responses, variant = 'non-error' } = props
13
+ const { t } = useTranslation ( 'products' )
14
+
15
+ if ( ! responses || responses . length === 0 ) {
16
+ return null
17
+ }
18
+
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
+
9
39
return (
10
40
< >
11
- { responses . map ( ( response : CodeResponse , index : number ) => {
41
+ { filteredResponses . map ( ( response , index ) => {
12
42
return (
13
43
< div key = { `${ response . httpStatusMessage } -${ index } }` } >
14
44
< h4 dangerouslySetInnerHTML = { { __html : response . description } } />
Original file line number Diff line number Diff line change
1
+ .restResponseTable {
2
+ table-layout : fixed !important ;
3
+
4
+ thead {
5
+ tr {
6
+ border-top : none ;
7
+
8
+ th {
9
+ border : 0 ;
10
+ font-weight : normal ;
11
+ }
12
+
13
+ th :first-child {
14
+ width : 25% ;
15
+ }
16
+
17
+ th :nth-child (2 ) {
18
+ width : 75% ;
19
+ }
20
+ }
21
+ }
22
+
23
+ tr :nth-child (2 n ) {
24
+ background : none !important ;
25
+ }
26
+
27
+ td {
28
+ padding : 0.75rem 0.5rem !important ;
29
+ border : 0 !important ;
30
+ vertical-align : top ;
31
+ width : 100% ;
32
+ }
33
+
34
+ tbody {
35
+ tr td :first-child {
36
+ width : 30% ;
37
+ font-weight : bold ;
38
+ }
39
+
40
+ tr td :nth-child (2 ) {
41
+ width : 70% ;
42
+ }
43
+
44
+ table tr td :not (:first-child ) {
45
+ font-weight : normal ;
46
+ }
47
+ }
48
+ }
Original file line number Diff line number Diff line change
1
+ import cx from 'classnames'
2
+ import { CodeResponse } from './types'
3
+ import { useTranslation } from 'components/hooks/useTranslation'
4
+ import styles from './RestResponseTable.module.scss'
5
+
6
+ type Props = {
7
+ heading : string
8
+ responses : Array < CodeResponse >
9
+ }
10
+
11
+ export function RestResponseTable ( { heading, responses } : Props ) {
12
+ const { t } = useTranslation ( 'products' )
13
+
14
+ return (
15
+ < >
16
+ < h4 > { heading } </ h4 >
17
+ < table className = { cx ( styles . restResponseTable ) } >
18
+ < thead >
19
+ < tr className = "text-left" >
20
+ < th > { t ( 'rest.reference.http_status_code' ) } </ th >
21
+ < th > { t ( 'rest.reference.description' ) } </ th >
22
+ </ tr >
23
+ </ thead >
24
+ < 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
+ } ) }
41
+ </ tbody >
42
+ </ table >
43
+ </ >
44
+ )
45
+ }
Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ products:
113
113
notes : Notes
114
114
parameters : Parameters
115
115
response : Response
116
+ error_codes : Error Codes
117
+ http_status_code : HTTP Status Code
116
118
code_sample : Code sample
117
119
code_samples : Code samples
118
120
preview_notice : Preview notice
You can’t perform that action at this time.
0 commit comments