import cx from 'classnames' import { useTranslation } from '@/languages/components/useTranslation' import { ChildBodyParametersRows } from './ChildBodyParametersRows' import type { ChildParameter } from './types' type Props = { rowParams: ChildParameter slug: string numPreviews?: number isChild?: boolean rowIndex?: number bodyParamExpandCallback?: (target: HTMLDetailsElement) => void clickedBodyParameterName?: string | undefined } // Webhooks have these same properties in common that we describe separately in its // own section on the webhooks page: // // https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-object-common-properties // // Since there's more details for these particular properties, we chose not // show their child properties for each webhook and we also don't grab this // information from the schema. // // We use this list of common properties to make sure we don't try and request // the child properties for these specific properties. const NO_CHILD_WEBHOOK_PROPERTIES = [ 'action', 'enterprise', 'installation', 'organization', 'repository', 'sender', ] export function ParameterRow({ rowParams, slug, numPreviews = 0, isChild = false, rowIndex = 0, bodyParamExpandCallback, clickedBodyParameterName, }: Props) { const { t } = useTranslation(['parameter_table']) // This will be true if `rowParams` does not have a key called `default` // and it will be true if it does and its actual value is `undefined`. const hasDefault = rowParams.default !== undefined return ( <>
{rowParams.name}
{/* This whitespace is important otherwise, when the CSS is
ignored, the plain text becomes `foobar` if the HTML
was `foobar`.
*/}{' '}
{Array.isArray(rowParams.type) ? rowParams.type.join(' or ') : rowParams.type}
{/* Ditto about the important explicit whitespace */}{' '}
{rowParams.isRequired ? (
{t('required')}
) : null}
>
) : (
<>
{Array.isArray(rowParams.type) ? rowParams.type.join(' or ') : rowParams.type}
{/* Ditto about the important explicit whitespace */}{' '}
{rowParams.isRequired ? (
{t('required')}
) : null}
>
)}
{t('default')}:
{typeof rowParams.default === 'string'
? // In the schema, the default value for strings can
// potentially be the empty string so we handle this case
// in particular by rendering it as "". Otherwise we would
// display an empty code block which could be confusing.
rowParams.default || '""'
: JSON.stringify(rowParams.default)}
{rowParams.enum.length === 1
? t('single_enum_description')
: t('enum_description_title')}
:{' '}
{rowParams.enum.map((item, index, array) => (
{item === null ? null : item}
{index !== array.length - 1 && ','}{' '}
))}
{rowParams.name}
) : (
Properties of {rowParams.name}
)}