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 From d725de72861c6a6218c7f4822a339175a2da7403 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Dec 2017 17:28:20 +0100 Subject: Create types sectionName constant --- packages/website/ts/containers/connect_documentation.tsx | 3 ++- packages/website/ts/containers/zero_ex_js_documentation.tsx | 3 ++- packages/website/ts/pages/documentation/method_signature.tsx | 3 ++- packages/website/ts/utils/constants.ts | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/website/ts/containers/connect_documentation.tsx b/packages/website/ts/containers/connect_documentation.tsx index 3b181a814..5e0a59e2d 100644 --- a/packages/website/ts/containers/connect_documentation.tsx +++ b/packages/website/ts/containers/connect_documentation.tsx @@ -10,6 +10,7 @@ import { import {Dispatcher} from 'ts/redux/dispatcher'; import {State} from 'ts/redux/reducer'; import {DocsInfoConfig, WebsitePaths} from 'ts/types'; +import {constants} from 'ts/utils/constants'; import {typeDocUtils} from 'ts/utils/typedoc_utils'; /* tslint:disable:no-var-requires */ @@ -22,7 +23,7 @@ const connectDocSections = { installation: 'installation', httpClient: 'httpClient', webSocketOrderbookChannel: 'webSocketOrderbookChannel', - types: 'types', + types: constants.TYPES_SECTION_NAME, }; const docsInfoConfig: DocsInfoConfig = { diff --git a/packages/website/ts/containers/zero_ex_js_documentation.tsx b/packages/website/ts/containers/zero_ex_js_documentation.tsx index 2f2c49167..8e40a3fbc 100644 --- a/packages/website/ts/containers/zero_ex_js_documentation.tsx +++ b/packages/website/ts/containers/zero_ex_js_documentation.tsx @@ -10,6 +10,7 @@ import { import {Dispatcher} from 'ts/redux/dispatcher'; import {State} from 'ts/redux/reducer'; import {DocsInfoConfig, WebsitePaths} from 'ts/types'; +import {constants} from 'ts/utils/constants'; import {typeDocUtils} from 'ts/utils/typedoc_utils'; /* tslint:disable:no-var-requires */ @@ -34,7 +35,7 @@ const zeroExJsDocSections = { etherToken: 'etherToken', proxy: 'proxy', orderWatcher: 'orderWatcher', - types: 'types', + types: constants.TYPES_SECTION_NAME, }; const docsInfoConfig: DocsInfoConfig = { diff --git a/packages/website/ts/pages/documentation/method_signature.tsx b/packages/website/ts/pages/documentation/method_signature.tsx index 14b91ab5d..366d4c13e 100644 --- a/packages/website/ts/pages/documentation/method_signature.tsx +++ b/packages/website/ts/pages/documentation/method_signature.tsx @@ -3,6 +3,7 @@ import * as React from 'react'; import {DocsInfo} from 'ts/pages/documentation/docs_info'; import {Type} from 'ts/pages/documentation/type'; import {Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod} from 'ts/types'; +import {constants} from 'ts/utils/constants'; interface MethodSignatureProps { method: TypescriptMethod|SolidityMethod; @@ -19,7 +20,7 @@ const defaultProps = { }; export const MethodSignature: React.SFC = (props: MethodSignatureProps) => { - const sectionName = 'types'; + const sectionName = constants.TYPES_SECTION_NAME; const parameters = renderParameters( props.method, props.docsInfo, sectionName, props.typeDefinitionByName, ); diff --git a/packages/website/ts/utils/constants.ts b/packages/website/ts/utils/constants.ts index 761d00ef7..facaf5dd6 100644 --- a/packages/website/ts/utils/constants.ts +++ b/packages/website/ts/utils/constants.ts @@ -46,6 +46,7 @@ export const constants = { UNAVAILABLE_STATUS: 503, TAKER_FEE: new BigNumber(0), TESTNET_NAME: 'Kovan', + TYPES_SECTION_NAME: 'types', PROJECT_URL_ETHFINEX: 'https://www.bitfinex.com/ethfinex', PROJECT_URL_RADAR_RELAY: 'https://radarrelay.com', PROJECT_URL_PARADEX: 'https://paradex.io', -- cgit