import * as React from 'react'; import classNames from 'classnames'; import hljs from 'highlight.js'; import { getUdfDocs } from '../../actions/DocActions'; import usePromiseResult from '../../hooks/usePromiseResult'; import { UdfArgumentSpec, UdfCategory, UdfMethodSpec } from '../../types/DocTypes'; import Text, { TextSizes } from '../../uikit/Text'; import { renderFromPromiseResult } from '../../utils/PromiseResultUtils'; import styles from './UdfDocsView.module.css'; /* TODO: - Set up page for other non-UDF documentation (eg have UDF header, probably change URL to be just `/docs`) - Ability to link to individual function's position on page, have hover button on each UDF title that navigates to the UDF's URL - TOC at side - Render markdown (or at least simple subsets?) in the docs */ interface UdfDocProps { udf: UdfMethodSpec; } const UdfDoc = ({ udf }: UdfDocProps) => { const argumentAsParam = (arg: UdfArgumentSpec): string => { const defaultPart = arg.default != null ? ` = ${arg.default}` : ''; return `${arg.name}: ${arg.type}${defaultPart}`; }; const params = udf.argument_specs.map(argumentAsParam).join(', '); const hasAnyArgDocs = udf.argument_specs.some((spec) => spec.doc != null); const mainDoc = udf.doc != null && {udf.doc}; const argDocs = udf.argument_specs.map( (spec) => spec.doc != null && ( {spec.name}: {spec.doc} ) ); const argDocsTitle = hasAnyArgDocs && Parameters; const noDocsNotice = udf.doc == null && !hasAnyArgDocs && No documentation yet!; // We need to add the `def` prefix and `: ...` suffix to ensure highlight.js recognizes this as a function // declaration, but we don't actually want to display them, so we remove them from the processed HTML. const methodSignature = hljs.highlight('python', `def ${udf.name}(${params}) -> ${udf.return_type}: ...`, true); const methodSignatureRawHtml = methodSignature.value .replace('def ', '') .replace(': ...', ''); return ( <>
          
        
{mainDoc} {argDocsTitle} {argDocs} {noDocsNotice}
); }; const renderUdfCategory = (category: UdfCategory) => { const categoryName = category.name || 'Other'; return (
{categoryName} {category.udfs.map((udf: UdfMethodSpec) => ( ))}
); }; const UdfDocsView = () => { const udfDocsResult = usePromiseResult(getUdfDocs); return renderFromPromiseResult(udfDocsResult, (udfDocs) => (
{udfDocs.map(renderUdfCategory)}
)); }; export default UdfDocsView;