diff --git a/docs/shared/ApiDoc/EnumDetails.js b/docs/shared/ApiDoc/EnumDetails.js index 7c7587cc0cc..a0f7966f55e 100644 --- a/docs/shared/ApiDoc/EnumDetails.js +++ b/docs/shared/ApiDoc/EnumDetails.js @@ -47,6 +47,7 @@ export function EnumDetails({ mr="1" as={Text} since + link id={`${item.displayName.toLowerCase()}-member-${member.displayName.toLowerCase()}`} /> { @@ -41,16 +41,9 @@ export function FunctionSignature({ paramSignature = "\n " + paramSignature + "\n"; } - const genericSignature = - typeParameters?.length ? - `<${typeParameters.map((p) => p.name).join(", ")}>` - : ""; - const signature = `${arrow ? "" : "function "}${ name ? displayName : "" - }${genericSignature}(${paramSignature})${arrow ? " =>" : ":"} ${ - returnType.type - }`; + }(${paramSignature})${arrow ? " =>" : ":"} ${returnType}`; return highlight ? @@ -72,20 +65,24 @@ export function ReturnType({ canonicalReference }) { const getItem = useApiDocContext(); const item = getItem(canonicalReference); + const interfaceReference = getInterfaceReference( + item.returnType, + item, + getItem + ); return ( <> {item.comment?.returns} - {item.returnType.type} + {item.returnType} - {item.returnType.primaryCanonicalReference?.endsWith(":interface") ? + {interfaceReference ?
Show/hide child attributes
@@ -156,8 +153,7 @@ export function FunctionDetails({ )} {( - result === false || - (result === undefined && item.returnType.type === "void") + result === false || (result === undefined && item.returnType === "void") ) ? null : <> diff --git a/docs/shared/ApiDoc/ParameterTable.js b/docs/shared/ApiDoc/ParameterTable.js index 40be1a6f8f1..44bd51feada 100644 --- a/docs/shared/ApiDoc/ParameterTable.js +++ b/docs/shared/ApiDoc/ParameterTable.js @@ -3,7 +3,12 @@ import { useMDXComponents } from "@mdx-js/react"; import PropTypes from "prop-types"; import React from "react"; import { GridItem, Text } from "@chakra-ui/react"; -import { PropertySignatureTable, useApiDocContext } from "."; +import { + PropertySignatureTable, + SectionHeading, + getInterfaceReference, + useApiDocContext, +} from "."; import { ResponsiveGrid } from "./ResponsiveGrid"; export function ParameterTable({ canonicalReference }) { @@ -20,10 +25,11 @@ export function ParameterTable({ canonicalReference }) { Description {item.parameters.map((parameter) => { - const interfaceReference = - parameter.primaryCanonicalReference?.endsWith(":interface") ? - parameter.primaryCanonicalReference - : undefined; + const interfaceReference = getInterfaceReference( + parameter.type, + item, + getItem + ); const id = `${item.displayName.toLowerCase()}-parameters-${parameter.name.toLowerCase()}`; return ( @@ -62,8 +68,7 @@ export function ParameterTable({ canonicalReference }) { Show/hide child attributes diff --git a/docs/shared/ApiDoc/PropertySignatureTable.js b/docs/shared/ApiDoc/PropertySignatureTable.js index 309dab9c5fc..40fa53b3df6 100644 --- a/docs/shared/ApiDoc/PropertySignatureTable.js +++ b/docs/shared/ApiDoc/PropertySignatureTable.js @@ -19,7 +19,6 @@ export function PropertySignatureTable({ display = "parent", customOrder = [], idPrefix = "", - genericNames, }) { const MDX = useMDXComponents(); const getItem = useApiDocContext(); @@ -37,29 +36,6 @@ export function PropertySignatureTable({ ); } - const replaceGenericNames = React.useMemo(() => { - if (!genericNames) return (str) => str; - - const replacements = {}; - item.typeParameters.forEach((p, i) => { - if (genericNames[i] === p.name) return; - replacements[p.name] = genericNames[i]; - }); - if (!Object.values(replacements).length) return (str) => str; - - const genericReplacementRegex = new RegExp( - `\\b(${Object.keys(replacements).join("|")})\\b`, - "g" - ); - function replace(match) { - console.log({ match, replacement: replacements[match] }); - return replacements[match] || match; - } - return function replaceGenericNames(str) { - return str.replace(genericReplacementRegex, replace); - }; - }); - return ( <> {item.childrenIncomplete ? @@ -79,7 +55,7 @@ export function PropertySignatureTable({ : null} {Object.entries(groupedProperties).map( ([groupName, sortedProperties]) => ( - + <> {groupName ? {groupName} : null} @@ -103,6 +79,7 @@ export function PropertySignatureTable({ : null } suffix={property.optional ? (optional) : null} + link={!!idPrefix} id={ idPrefix ? `${idPrefix}-${property.displayName.toLowerCase()}` @@ -117,7 +94,7 @@ export function PropertySignatureTable({ parameterTypes arrow /> - : replaceGenericNames(property.type)} + : property.type} @@ -132,7 +109,7 @@ export function PropertySignatureTable({ ))} - + ) )} @@ -147,5 +124,4 @@ PropertySignatureTable.propTypes = { display: PropTypes.oneOf(["parent", "child"]), customOrder: PropTypes.arrayOf(PropTypes.string), idPrefix: PropTypes.string, - genericNames: PropTypes.arrayOf(PropTypes.string), }; diff --git a/docs/shared/ApiDoc/getInterfaceReference.js b/docs/shared/ApiDoc/getInterfaceReference.js new file mode 100644 index 00000000000..b9b9202ae92 --- /dev/null +++ b/docs/shared/ApiDoc/getInterfaceReference.js @@ -0,0 +1,8 @@ +export function getInterfaceReference(type, item, getItem) { + const baseType = type.replace(/\b(Partial|Omit|Promise) r.text === baseType)?.canonicalReference, + false + ); + return reference?.kind === "Interface" ? reference : null; +} diff --git a/docs/shared/ApiDoc/index.js b/docs/shared/ApiDoc/index.js index 87e85357bbf..06728b10116 100644 --- a/docs/shared/ApiDoc/index.js +++ b/docs/shared/ApiDoc/index.js @@ -15,4 +15,5 @@ export { ParameterTable } from "./ParameterTable"; export { PropertyDetails } from "./PropertyDetails"; export { EnumDetails } from "./EnumDetails"; export { ManualTuple } from "./Tuple"; +export { getInterfaceReference } from "./getInterfaceReference"; export { SourceLink } from "./SourceLink"; diff --git a/netlify.toml b/netlify.toml index b282882484b..67879a8b0ba 100644 --- a/netlify.toml +++ b/netlify.toml @@ -13,7 +13,7 @@ npm run docmodel cd ../ rm -rf monodocs - git clone https://github.com/apollographql/docs --branch pr/parse-ts --single-branch monodocs + git clone https://github.com/apollographql/docs --branch main --single-branch monodocs cd monodocs npm i cp -r ../docs local