import Button from '@atlaskit/button/new'; import Heading from '@atlaskit/heading'; import Modal, { ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog'; import type { FunctionComponent } from 'react'; import React, { memo, useState } from 'react'; import { Element, Link } from 'react-scroll'; import type { SerializedDocument, SerializedEnumType, SerializedObjectType, SerializedScalar, SerializedUnionType, // We only import types here // eslint-disable-next-line node/no-unpublished-import } from '@atlassian/clientside-extensions-schema'; import useDiscovery from './debug/useDiscovery'; import { Blinker, BlinkerContainer, GRID_SIZE, HeadCell, HeadingWrapper, HeadRow, Table, TableCell, TableRow } from './styled'; export type ExtensionPointInfoProps = { name: string; schemaDocuments: { schema: SerializedDocument; contextSchema: SerializedDocument }; }; const LinkToElement = ({ to }: { to: string }) => { // TODO: is there a way to get the clean type from the schema? // We are removing the e.g. "!" required syntax that is a suffix of the schema type const cleanTo = to.replace(/[^a-zA-Z0-9]/g, ''); return ( // eslint-disable-next-line jsx-a11y/anchor-is-valid, @typescript-eslint/ban-ts-comment // @ts-ignore: react-scroll types are not up to date with the latest react version {to} ); }; const TypeRenderer: FunctionComponent<{ objectType: SerializedObjectType }> = ({ objectType }) => ( <>

{objectType.description}

Name Type Required Description {objectType.descriptors.map((descriptor) => ( {descriptor.name} {descriptor.required ? 'true' : 'false'} {descriptor.description} ))}
); const EnumTypeRenderer = ({ enumType }: { enumType: SerializedEnumType }) => ( <> {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */} {/* @ts-ignore: react-scroll types are not up to date with the latest react version*/} {enumType.name} {enumType.description ? (

{enumType.description}

) : (

Enum type with the following values: {enumType.values.join(', ')}

)} ); const UnionTypeRenderer = ({ unionType }: { unionType: SerializedUnionType }) => ( <> {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */} {/* @ts-ignore: react-scroll types are not up to date with the latest react version*/} {unionType.name} {unionType.description ? (

{unionType.description}

) : (

Union of the following types:{' '} {unionType.types.map((_type, i) => ( {i === 0 ? '' : ', '} ))}

)} ); const ScalarRenderer = ({ scalar }: { scalar: SerializedScalar }) => ( <> {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */} {/* @ts-ignore: react-scroll types are not up to date with the latest react version*/} {scalar.name}

{scalar.description}

); const SchemasRenderer = ({ schemaDocuments: { schema, contextSchema } }: Omit) => { const { objectTypes: { Schema: attributesDocument, ...attributeObjectTypes } = { Schema: null }, scalars: attributeScalars, enumTypes: attributesEnumTypes, unionTypes: attributesUnionTypes, } = schema || {}; const { objectTypes: { ContextSchema: contextDocument, ...contextObjectTypes } = { ContextSchema: null }, scalars: contextScalars, enumTypes: contextEnumTypes, unionTypes: contextUnionTypes, } = contextSchema || {}; const objectTypeEntries: SerializedObjectType[] = Object.values({ ...attributeObjectTypes, ...contextObjectTypes }); const scalars: SerializedScalar[] = Object.values({ ...attributeScalars, ...contextScalars }); const enumTypes: SerializedEnumType[] = Object.values({ ...attributesEnumTypes, ...contextEnumTypes }); const unionTypes: SerializedUnionType[] = Object.values({ ...attributesUnionTypes, ...contextUnionTypes }); return ( <> Attributes {attributesDocument ? ( <>

List of attributes supported by this extension point.

) : (

No attributes information provided for this extension point.

)} Context {contextDocument ? ( <>

List of values provided by this extension point as context.

) : (

No context information provided for this extension point.

)} Types reference {objectTypeEntries && objectTypeEntries.map((objectType) => ( {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */} {/* @ts-ignore: react-scroll types are not up to date with the latest react version*/} {objectType.name} ))} {enumTypes && enumTypes.map((enumType) => )} {unionTypes && unionTypes.map((unionType) => )} {scalars && scalars.map((scalar) => )} ); }; const bodyStyles: React.CSSProperties = { // Styles required for the react-scroll to work when scrolling is animated overflowY: 'auto', overflowX: 'hidden', // The rest of the styles are copied from the @atlaskit/modal-dialog/dist/esm/modal-body.js padding: GRID_SIZE * 3, flex: '1 1 auto', }; const CustomModalBody: React.FC<{ children: React.ReactNode }> = ({ children }) => { return (
{children}
); }; const ExtensionPointInfo: React.FC = ({ name, schemaDocuments }) => { const [showExtensionPointInfo] = useDiscovery(); const [dialogOpen, setDialogState] = useState(false); const closeDialog = () => setDialogState(false); return !showExtensionPointInfo ? null : ( setDialogState(true)} /> {dialogOpen && ( {`Extension point: ${name}`} {/* eslint-disable-next-line jsx-a11y/no-autofocus */} )} ); }; export default memo(ExtensionPointInfo);