import cx from 'classnames' import { useTranslation } from 'components/hooks/useTranslation' import { KeyboardEventHandler } from 'react' import { ChildBodyParametersRows } from './ChildBodyParametersRows' import type { ChildParameter } from './types' type Props = { rowParams: ChildParameter slug: string numPreviews?: number isChild?: boolean rowIndex?: number bodyParamExpandCallback?: KeyboardEventHandler | undefined 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 = undefined, clickedBodyParameterName = undefined, }: Props) { const { t } = useTranslation(['parameter_table', 'products']) // 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 ( <>
0 && isChild ? 'pt-3 border-top color-border-muted' : ''}` )} >
{rowParams.name ? ( <> {rowParams.name} {Array.isArray(rowParams.type) ? rowParams.type.join(' or ') : rowParams.type} {rowParams.isRequired ? ( {t('required')} ) : null} ) : ( <> {Array.isArray(rowParams.type) ? rowParams.type.join(' or ') : rowParams.type} {rowParams.isRequired ? ( {t('required')} ) : null} )}
{numPreviews > 0 && ( {numPreviews > 1 ? ` ${t('see_preview_notices')}` : ` ${t('see_preview_notice')}`} )}
{hasDefault && (

{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 && rowParams.enum.length && (

{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.childParamsGroups && rowParams.childParamsGroups.length > 0 && ( )} {/* These conditions tell us: 1. the param is an object or array AND: 2. the param has no child param groups AND: 3. the param isn't one of the common webhook properties If all these are true, then that means we haven't yet loaded the nested parameters so we show a stub
element that triggers an API request to get the nested parameter data. */} {rowParams.type && (rowParams.type === 'object' || rowParams.type.includes('array of')) && rowParams.childParamsGroups && rowParams.childParamsGroups.length === 0 && !NO_CHILD_WEBHOOK_PROPERTIES.includes(rowParams.name) && (
)} ) }