Add sectionName prefix to all anchor links in order to fix method name collisions between sections

This commit is contained in:
Fabio Berger
2017-12-21 17:28:06 +01:00
parent 66cf60f9cb
commit 3e91773cd9
8 changed files with 64 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ import {Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod} from
interface MethodSignatureProps {
method: TypescriptMethod|SolidityMethod;
sectionName: string;
shouldHideMethodName?: boolean;
shouldUseArrowSyntax?: boolean;
typeDefinitionByName?: TypeDefinitionByName;
@@ -18,14 +19,19 @@ const defaultProps = {
};
export const MethodSignature: React.SFC<MethodSignatureProps> = (props: MethodSignatureProps) => {
const parameters = renderParameters(props.method, props.docsInfo, props.typeDefinitionByName);
const sectionName = 'types';
const parameters = renderParameters(
props.method, props.docsInfo, sectionName, props.typeDefinitionByName,
);
const paramString = _.reduce(parameters, (prev: React.ReactNode, curr: React.ReactNode) => {
return [prev, ', ', curr];
});
const methodName = props.shouldHideMethodName ? '' : props.method.name;
const typeParameterIfExists = _.isUndefined((props.method as TypescriptMethod).typeParameter) ?
undefined :
renderTypeParameter(props.method, props.docsInfo, props.typeDefinitionByName);
renderTypeParameter(
props.method, props.docsInfo, sectionName, props.typeDefinitionByName,
);
return (
<span>
{props.method.callPath}{methodName}{typeParameterIfExists}({paramString})
@@ -34,6 +40,7 @@ export const MethodSignature: React.SFC<MethodSignatureProps> = (props: MethodSi
{props.method.returnType &&
<Type
type={props.method.returnType}
sectionName={sectionName}
typeDefinitionByName={props.typeDefinitionByName}
docsInfo={props.docsInfo}
/>
@@ -45,7 +52,8 @@ export const MethodSignature: React.SFC<MethodSignatureProps> = (props: MethodSi
MethodSignature.defaultProps = defaultProps;
function renderParameters(
method: TypescriptMethod|SolidityMethod, docsInfo: DocsInfo, typeDefinitionByName?: TypeDefinitionByName,
method: TypescriptMethod|SolidityMethod, docsInfo: DocsInfo,
sectionName: string, typeDefinitionByName?: TypeDefinitionByName,
) {
const parameters = method.parameters;
const params = _.map(parameters, (p: Parameter) => {
@@ -53,6 +61,7 @@ function renderParameters(
const type = (
<Type
type={p.type}
sectionName={sectionName}
typeDefinitionByName={typeDefinitionByName}
docsInfo={docsInfo}
/>
@@ -67,7 +76,8 @@ function renderParameters(
}
function renderTypeParameter(
method: TypescriptMethod, docsInfo: DocsInfo, typeDefinitionByName?: TypeDefinitionByName,
method: TypescriptMethod, docsInfo: DocsInfo,
sectionName: string, typeDefinitionByName?: TypeDefinitionByName,
) {
const typeParameter = method.typeParameter;
const typeParam = (
@@ -75,6 +85,7 @@ function renderTypeParameter(
{`<${typeParameter.name} extends `}
<Type
type={typeParameter.type}
sectionName={sectionName}
typeDefinitionByName={typeDefinitionByName}
docsInfo={docsInfo}
/>