* Add error response variant * Add response table styles * Already filtered * Don't need these styles * Fallback to http code status messsage * Add translation strings * Proper heading level Co-authored-by: Grace Park <gracepark@github.com> * Match table styling with params table * Typing unnecessary Co-authored-by: Peter Bengtsson <mail@peterbe.com> * Typing unnecessary Co-authored-by: Peter Bengtsson <mail@peterbe.com> * Work with the status code as a number * Move error responses to operation end * Make RestResponseTable a standalone component Co-authored-by: Grace Park <gracepark@github.com> Co-authored-by: Peter Bengtsson <mail@peterbe.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import cx from 'classnames'
|
|
import { CodeResponse } from './types'
|
|
import { useTranslation } from 'components/hooks/useTranslation'
|
|
import styles from './RestResponseTable.module.scss'
|
|
|
|
type Props = {
|
|
heading: string
|
|
responses: Array<CodeResponse>
|
|
}
|
|
|
|
export function RestResponseTable({ heading, responses }: Props) {
|
|
const { t } = useTranslation('products')
|
|
|
|
return (
|
|
<>
|
|
<h4>{heading}</h4>
|
|
<table className={cx(styles.restResponseTable)}>
|
|
<thead>
|
|
<tr className="text-left">
|
|
<th>{t('rest.reference.http_status_code')}</th>
|
|
<th>{t('rest.reference.description')}</th>
|
|
</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>
|
|
)
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</>
|
|
)
|
|
}
|