From 3e91773cd94162fca1855638a76d7bd2f510558a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Dec 2017 17:28:06 +0100 Subject: Add sectionName prefix to all anchor links in order to fix method name collisions between sections --- .../website/ts/pages/documentation/documentation.tsx | 14 +++++++++++--- .../ts/pages/documentation/event_definition.tsx | 4 +++- packages/website/ts/pages/documentation/interface.tsx | 10 ++++++++-- .../website/ts/pages/documentation/method_block.tsx | 6 ++++-- .../ts/pages/documentation/method_signature.tsx | 19 +++++++++++++++---- packages/website/ts/pages/documentation/type.tsx | 9 ++++++++- .../ts/pages/documentation/type_definition.tsx | 11 +++++++++-- .../website/ts/pages/shared/nested_sidebar_menu.tsx | 11 ++++++----- 8 files changed, 64 insertions(+), 20 deletions(-) (limited to 'packages') diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx index a40889872..4d3607d76 100644 --- a/packages/website/ts/pages/documentation/documentation.tsx +++ b/packages/website/ts/pages/documentation/documentation.tsx @@ -195,6 +195,7 @@ export class Documentation extends const typeDefs = _.map(sortedTypes, customType => { return ( { @@ -217,6 +218,7 @@ export class Documentation extends ); @@ -311,14 +313,19 @@ export class Documentation extends ); } - private renderProperty(property: Property): React.ReactNode { + private renderProperty(sectionName: string, property: Property): React.ReactNode { return (
- {property.name}: + {property.name}: + {property.source && ); diff --git a/packages/website/ts/pages/documentation/interface.tsx b/packages/website/ts/pages/documentation/interface.tsx index e671db2b8..1a6b562fe 100644 --- a/packages/website/ts/pages/documentation/interface.tsx +++ b/packages/website/ts/pages/documentation/interface.tsx @@ -7,6 +7,7 @@ import {CustomType, TypeDocTypes} from 'ts/types'; interface InterfaceProps { type: CustomType; + sectionName: string; docsInfo: DocsInfo; } @@ -17,9 +18,14 @@ export function Interface(props: InterfaceProps) { {property.name}:{' '} {property.type.typeDocType !== TypeDocTypes.Reflection ? - : + : - {is.keyName}: + {is.keyName}: ); properties.push(( diff --git a/packages/website/ts/pages/documentation/method_block.tsx b/packages/website/ts/pages/documentation/method_block.tsx index 5163e03ac..60dfc17db 100644 --- a/packages/website/ts/pages/documentation/method_block.tsx +++ b/packages/website/ts/pages/documentation/method_block.tsx @@ -18,6 +18,7 @@ import {typeDocUtils} from 'ts/utils/typedoc_utils'; interface MethodBlockProps { method: SolidityMethod|TypescriptMethod; + sectionName: string; libraryVersion: string; typeDefinitionByName: TypeDefinitionByName; docsInfo: DocsInfo; @@ -54,7 +55,7 @@ export class MethodBlock extends React.Component
@@ -82,6 +83,7 @@ export class MethodBlock extends React.Component diff --git a/packages/website/ts/pages/documentation/method_signature.tsx b/packages/website/ts/pages/documentation/method_signature.tsx index df3b61814..14b91ab5d 100644 --- a/packages/website/ts/pages/documentation/method_signature.tsx +++ b/packages/website/ts/pages/documentation/method_signature.tsx @@ -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 = (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 ( {props.method.callPath}{methodName}{typeParameterIfExists}({paramString}) @@ -34,6 +40,7 @@ export const MethodSignature: React.SFC = (props: MethodSi {props.method.returnType && @@ -45,7 +52,8 @@ export const MethodSignature: React.SFC = (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 = ( @@ -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 `} diff --git a/packages/website/ts/pages/documentation/type.tsx b/packages/website/ts/pages/documentation/type.tsx index 0516a5c68..6182b147a 100644 --- a/packages/website/ts/pages/documentation/type.tsx +++ b/packages/website/ts/pages/documentation/type.tsx @@ -37,6 +37,7 @@ const typeToSection: {[typeName: string]: string} = { interface TypeProps { type: TypeDef; docsInfo: DocsInfo; + sectionName: string; typeDefinitionByName?: TypeDefinitionByName; } @@ -66,6 +67,7 @@ export function Type(props: TypeProps): any { [] @@ -76,6 +78,7 @@ export function Type(props: TypeProps): any { @@ -100,6 +103,7 @@ export function Type(props: TypeProps): any { @@ -144,7 +148,9 @@ export function Type(props: TypeProps): any { (props.docsInfo.isPublicType(typeName as string) || !_.isUndefined(sectionNameIfExists))) { const id = Math.random().toString(); - const typeDefinitionAnchorId = _.isUndefined(sectionNameIfExists) ? typeName : sectionNameIfExists; + const typeDefinitionAnchorId = _.isUndefined(sectionNameIfExists) ? + `${props.sectionName}-${typeName}` : + sectionNameIfExists; let typeDefinition; if (props.typeDefinitionByName) { typeDefinition = props.typeDefinitionByName[typeName as string]; @@ -177,6 +183,7 @@ export function Type(props: TypeProps): any { className="typeTooltip" > ); @@ -85,9 +87,14 @@ export class TypeDefinition extends React.Component {customType.name} ={' '} {customType.type.typeDocType !== TypeDocTypes.Reflection ? - : + : {_.map(entityNames, entityName => { - const id = utils.getIdFromName(entityName); + const name = `${menuItemName}-${entityName}`; + const id = utils.getIdFromName(name); return (
  • @@ -154,8 +155,8 @@ export class NestedSidebarMenu extends React.Component ); } - private onMenuItemClick(menuItemName: string): void { - const id = utils.getIdFromName(menuItemName); + private onMenuItemClick(name: string): void { + const id = utils.getIdFromName(name); utils.setUrlHash(id); this.props.onMenuItemClick(); } -- cgit v1.2.3