import cx from 'classnames' import { useTranslation } from 'components/hooks/useTranslation' import { KeyboardEventHandler } from 'react' import { ParameterRow } from './ParameterRow' import { BodyParameter, ChildParameter, Parameter } from './types' import styles from './ParameterTable.module.scss' type Props = { slug: string numPreviews?: number heading?: string headers?: Array parameters?: Array bodyParameters: Array bodyParamExpandCallback?: KeyboardEventHandler | undefined clickedBodyParameterName?: string | undefined } export function ParameterTable({ slug, numPreviews = 0, heading = '', headers = [], parameters = [], bodyParameters, bodyParamExpandCallback = undefined, clickedBodyParameterName = '', }: Props) { const { t } = useTranslation(['parameter_table', 'products']) const queryParams = parameters.filter((param) => param.in === 'query') const pathParams = parameters.filter((param) => param.in === 'path') return ( <> {heading && (

{heading}

)} {headers.length > 0 && ( <> {headers.map((header, index) => ( ))} )} {pathParams.length > 0 && ( <> {pathParams.map((param, index) => ( ))} )} {queryParams.length > 0 && ( <> {queryParams.map((param, index) => ( ))} )} {bodyParameters.length > 0 && ( <> {/* webhooks don't have a 'Parameters' table heading text so we adjust the size of the body params heading in that case */} {bodyParameters.map((param, index) => ( ))} )}
{t('headers')}
{`${t('name')}, ${t('type')}, ${t('description')}`}
{t('path')}
{`${t('name')}, ${t('type')}, ${t('description')}`}
{t('query')}
{`${t('name')}, ${t('type')}, ${t('description')}`}
{t('body')}
{`${t('name')}, ${t('type')}, ${t('description')}`}
) }