aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/pages
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-02-28 06:29:22 +0800
committerFabio Berger <me@fabioberger.com>2018-02-28 06:29:22 +0800
commit97fcfb7f6c62aefa3f3a736f7783529d4e3e0018 (patch)
tree8b7d202ecceb6f467c94c7a4ce95049b5700b88f /packages/website/ts/pages
parentecba95250d0bfc5b4ab0950ef490a4f262672e6c (diff)
downloaddexon-sol-tools-97fcfb7f6c62aefa3f3a736f7783529d4e3e0018.tar
dexon-sol-tools-97fcfb7f6c62aefa3f3a736f7783529d4e3e0018.tar.gz
dexon-sol-tools-97fcfb7f6c62aefa3f3a736f7783529d4e3e0018.tar.bz2
dexon-sol-tools-97fcfb7f6c62aefa3f3a736f7783529d4e3e0018.tar.lz
dexon-sol-tools-97fcfb7f6c62aefa3f3a736f7783529d4e3e0018.tar.xz
dexon-sol-tools-97fcfb7f6c62aefa3f3a736f7783529d4e3e0018.tar.zst
dexon-sol-tools-97fcfb7f6c62aefa3f3a736f7783529d4e3e0018.zip
Move more configs into docsInfo and remove logic that does not belong there elsewhere
Diffstat (limited to 'packages/website/ts/pages')
-rw-r--r--packages/website/ts/pages/documentation/doc_page.tsx31
-rw-r--r--packages/website/ts/pages/documentation/docs_info.ts20
-rw-r--r--packages/website/ts/pages/documentation/documentation.tsx15
-rw-r--r--packages/website/ts/pages/documentation/method_block.tsx4
-rw-r--r--packages/website/ts/pages/documentation/source_link.tsx13
-rw-r--r--packages/website/ts/pages/shared/nested_sidebar_menu.tsx10
-rw-r--r--packages/website/ts/pages/shared/version_drop_down.tsx15
7 files changed, 69 insertions, 39 deletions
diff --git a/packages/website/ts/pages/documentation/doc_page.tsx b/packages/website/ts/pages/documentation/doc_page.tsx
index 306ad8542..2c8f1c103 100644
--- a/packages/website/ts/pages/documentation/doc_page.tsx
+++ b/packages/website/ts/pages/documentation/doc_page.tsx
@@ -7,19 +7,25 @@ import { TopBar } from 'ts/components/top_bar/top_bar';
import { DocsInfo } from 'ts/pages/documentation/docs_info';
import { Documentation } from 'ts/pages/documentation/documentation';
import { Dispatcher } from 'ts/redux/dispatcher';
-import { DocAgnosticFormat, DoxityDocObj, Environments, MenuSubsectionsBySection } from 'ts/types';
+import { DocAgnosticFormat, DocPackages, DoxityDocObj, Environments, MenuSubsectionsBySection } from 'ts/types';
import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
import { docUtils } from 'ts/utils/doc_utils';
import { Translate } from 'ts/utils/translate';
-const displayNameToS3BucketName: { [displayName: string]: string } = {
- '0x.js': configs.ENVIRONMENT === Environments.DEVELOPMENT ? 'staging-0xjs-docs-jsons' : '0xjs-docs-jsons',
- '0x Smart Contracts': 'smart-contracts-docs-json',
- '0x Connect':
+const docIdToS3BucketName: { [id: string]: string } = {
+ [DocPackages.ZeroExJs]: '0xjs-docs-jsons',
+ [DocPackages.SmartContracts]: 'smart-contracts-docs-json',
+ [DocPackages.Connect]:
configs.ENVIRONMENT === Environments.DEVELOPMENT ? 'staging-connect-docs-jsons' : 'connect-docs-jsons',
};
+const docIdToSubpackageName: { [id: string]: string } = {
+ [DocPackages.ZeroExJs]: '0x.js',
+ [DocPackages.Connect]: 'connect',
+ [DocPackages.SmartContracts]: 'contracts',
+};
+
export interface DocPageProps {
location: Location;
dispatcher: Dispatcher;
@@ -58,6 +64,7 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
const menuSubsectionsBySection = _.isUndefined(this.state.docAgnosticFormat)
? {}
: this.props.docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat);
+ const sourceUrl = this._getSourceUrl();
return (
<div>
<DocumentTitle title={`${this.props.docsInfo.displayName} Documentation`} />
@@ -78,12 +85,13 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
docsInfo={this.props.docsInfo}
docAgnosticFormat={this.state.docAgnosticFormat}
menuSubsectionsBySection={menuSubsectionsBySection}
+ sourceUrl={sourceUrl}
/>
</div>
);
}
private async _fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists?: string): Promise<void> {
- const s3BucketName = displayNameToS3BucketName[this.props.docsInfo.displayName];
+ const s3BucketName = docIdToS3BucketName[this.props.docsInfo.id];
const docsJsonRoot = `${constants.S3_BUCKET_ROOT}/${s3BucketName}`;
const versionToFileName = await docUtils.getVersionToFileNameAsync(docsJsonRoot);
const versions = _.keys(versionToFileName);
@@ -110,4 +118,15 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
});
}
}
+ private _getSourceUrl() {
+ const url = this.props.docsInfo.packageUrl;
+ const pkg = docIdToSubpackageName[this.props.docsInfo.id];
+ let tagPrefix = pkg;
+ const packagesWithNamespace = ['connect'];
+ if (_.includes(packagesWithNamespace, pkg)) {
+ tagPrefix = `@0xproject/${pkg}`;
+ }
+ const sourceUrl = `${url}/blob/${tagPrefix}%40${this.props.docsVersion}/packages/${pkg}`;
+ return sourceUrl;
+ }
}
diff --git a/packages/website/ts/pages/documentation/docs_info.ts b/packages/website/ts/pages/documentation/docs_info.ts
index f90b39e1f..31e151fe8 100644
--- a/packages/website/ts/pages/documentation/docs_info.ts
+++ b/packages/website/ts/pages/documentation/docs_info.ts
@@ -1,31 +1,37 @@
import compareVersions = require('compare-versions');
import * as _ from 'lodash';
import {
+ ContractsByVersionByNetworkId,
DocAgnosticFormat,
DocsInfoConfig,
DocsMenu,
DoxityDocObj,
MenuSubsectionsBySection,
SectionsMap,
+ SupportedDocJson,
TypeDocNode,
} from 'ts/types';
+import { doxityUtils } from 'ts/utils/doxity_utils';
+import { typeDocUtils } from 'ts/utils/typedoc_utils';
export class DocsInfo {
+ public id: string;
+ public type: SupportedDocJson;
public displayName: string;
public packageUrl: string;
- public subPackageName?: string;
- public websitePath: string;
public menu: DocsMenu;
public sections: SectionsMap;
public sectionNameToMarkdown: { [sectionName: string]: string };
+ public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
private _docsInfo: DocsInfoConfig;
constructor(config: DocsInfoConfig) {
+ this.id = config.id;
+ this.type = config.type;
this.displayName = config.displayName;
this.packageUrl = config.packageUrl;
- this.subPackageName = config.subPackageName;
- this.websitePath = config.websitePath;
this.sections = config.sections;
this.sectionNameToMarkdown = config.sectionNameToMarkdown;
+ this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId;
this._docsInfo = config;
}
public isPublicType(typeName: string): boolean {
@@ -104,6 +110,10 @@ export class DocsInfo {
return _.includes(this._docsInfo.visibleConstructors, sectionName);
}
public convertToDocAgnosticFormat(docObj: DoxityDocObj | TypeDocNode): DocAgnosticFormat {
- return this._docsInfo.convertToDocAgnosticFormatFn(docObj, this);
+ if (this.type === SupportedDocJson.Doxity) {
+ return doxityUtils.convertToDocAgnosticFormat(docObj as DoxityDocObj);
+ } else {
+ return typeDocUtils.convertToDocAgnosticFormat(docObj as TypeDocNode, this);
+ }
}
}
diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx
index 74d5afb54..9fe599b6d 100644
--- a/packages/website/ts/pages/documentation/documentation.tsx
+++ b/packages/website/ts/pages/documentation/documentation.tsx
@@ -24,6 +24,7 @@ import {
Property,
SolidityMethod,
Styles,
+ SupportedDocJson,
TypeDefinitionByName,
TypescriptMethod,
} from 'ts/types';
@@ -49,6 +50,7 @@ export interface DocumentationProps {
docsInfo: DocsInfo;
docAgnosticFormat?: DocAgnosticFormat;
menuSubsectionsBySection: MenuSubsectionsBySection;
+ sourceUrl: string;
}
interface DocumentationState {}
@@ -107,7 +109,6 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
title={this.props.docsInfo.displayName}
topLevelMenu={this.props.docsInfo.getMenu(this.props.docsVersion)}
menuSubsectionsBySection={this.props.menuSubsectionsBySection}
- docPath={this.props.docsInfo.websitePath}
/>
</div>
</div>
@@ -246,7 +247,13 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
);
}
private _renderNetworkBadgesIfExists(sectionName: string) {
- const networkToAddressByContractName = configs.CONTRACT_ADDRESS[this.props.docsVersion];
+ if (this.props.docsInfo.type !== SupportedDocJson.Doxity) {
+ return null;
+ }
+
+ const networkToAddressByContractName = this.props.docsInfo.contractsByVersionByNetworkId[
+ this.props.docsVersion
+ ];
const badges = _.map(
networkToAddressByContractName,
(addressByContractName: AddressByContractName, networkName: string) => {
@@ -294,8 +301,7 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
<SourceLink
version={this.props.docsVersion}
source={property.source}
- baseUrl={this.props.docsInfo.packageUrl}
- subPackageName={this.props.docsInfo.subPackageName}
+ sourceUrl={this.props.sourceUrl}
/>
)}
{property.comment && <Comment comment={property.comment} className="py2" />}
@@ -316,6 +322,7 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
typeDefinitionByName={typeDefinitionByName}
libraryVersion={this.props.docsVersion}
docsInfo={this.props.docsInfo}
+ sourceUrl={this.props.sourceUrl}
/>
);
}
diff --git a/packages/website/ts/pages/documentation/method_block.tsx b/packages/website/ts/pages/documentation/method_block.tsx
index 1bc6aa4f4..d2c96bf8c 100644
--- a/packages/website/ts/pages/documentation/method_block.tsx
+++ b/packages/website/ts/pages/documentation/method_block.tsx
@@ -15,6 +15,7 @@ interface MethodBlockProps {
libraryVersion: string;
typeDefinitionByName: TypeDefinitionByName;
docsInfo: DocsInfo;
+ sourceUrl: string;
}
interface MethodBlockState {
@@ -80,8 +81,7 @@ export class MethodBlock extends React.Component<MethodBlockProps, MethodBlockSt
<SourceLink
version={this.props.libraryVersion}
source={(method as TypescriptMethod).source}
- baseUrl={this.props.docsInfo.packageUrl}
- subPackageName={this.props.docsInfo.subPackageName}
+ sourceUrl={this.props.sourceUrl}
/>
)}
{method.comment && <Comment comment={method.comment} className="py2" />}
diff --git a/packages/website/ts/pages/documentation/source_link.tsx b/packages/website/ts/pages/documentation/source_link.tsx
index 6588ee39e..31f80aba3 100644
--- a/packages/website/ts/pages/documentation/source_link.tsx
+++ b/packages/website/ts/pages/documentation/source_link.tsx
@@ -5,22 +5,13 @@ import { colors } from 'ts/utils/colors';
interface SourceLinkProps {
source: Source;
- baseUrl: string;
+ sourceUrl: string;
version: string;
- subPackageName: string;
}
-const packagesWithNamespace = ['connect'];
-
export function SourceLink(props: SourceLinkProps) {
const src = props.source;
- const url = props.baseUrl;
- const pkg = props.subPackageName;
- let tagPrefix = pkg;
- if (_.includes(packagesWithNamespace, pkg)) {
- tagPrefix = `@0xproject/${pkg}`;
- }
- const sourceCodeUrl = `${url}/blob/${tagPrefix}%40${props.version}/packages/${pkg}/${src.fileName}#L${src.line}`;
+ const sourceCodeUrl = `${props.sourceUrl}/${src.fileName}#L${src.line}`;
return (
<div className="pt2" style={{ fontSize: 14 }}>
<a href={sourceCodeUrl} target="_blank" className="underline" style={{ color: colors.grey }}>
diff --git a/packages/website/ts/pages/shared/nested_sidebar_menu.tsx b/packages/website/ts/pages/shared/nested_sidebar_menu.tsx
index ba794ee9f..1a08ca9f9 100644
--- a/packages/website/ts/pages/shared/nested_sidebar_menu.tsx
+++ b/packages/website/ts/pages/shared/nested_sidebar_menu.tsx
@@ -16,7 +16,6 @@ interface NestedSidebarMenuProps {
onMenuItemClick?: () => void;
selectedVersion?: string;
versions?: string[];
- docPath?: string;
}
interface NestedSidebarMenuState {}
@@ -69,13 +68,8 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N
<div>
{this._renderEmblem()}
{!_.isUndefined(this.props.versions) &&
- !_.isUndefined(this.props.selectedVersion) &&
- !_.isUndefined(this.props.docPath) && (
- <VersionDropDown
- selectedVersion={this.props.selectedVersion}
- versions={this.props.versions}
- docPath={this.props.docPath}
- />
+ !_.isUndefined(this.props.selectedVersion) && (
+ <VersionDropDown selectedVersion={this.props.selectedVersion} versions={this.props.versions} />
)}
<div className="pl1">{navigation}</div>
</div>
diff --git a/packages/website/ts/pages/shared/version_drop_down.tsx b/packages/website/ts/pages/shared/version_drop_down.tsx
index b922e1048..3b331af9b 100644
--- a/packages/website/ts/pages/shared/version_drop_down.tsx
+++ b/packages/website/ts/pages/shared/version_drop_down.tsx
@@ -6,7 +6,6 @@ import * as React from 'react';
interface VersionDropDownProps {
selectedVersion: string;
versions: string[];
- docPath: string;
}
interface VersionDropDownState {}
@@ -31,7 +30,17 @@ export class VersionDropDown extends React.Component<VersionDropDownProps, Versi
});
return items;
}
- private _updateSelectedVersion(e: any, index: number, value: string) {
- window.location.href = `${this.props.docPath}/${value}${window.location.hash}`;
+ private _updateSelectedVersion(e: any, index: number, semver: string) {
+ const port = window.location.port;
+ const hasPort = !_.isUndefined(port);
+ let path = window.location.pathname;
+ const lastChar = path[path.length - 1];
+ if (_.isFinite(_.parseInt(lastChar))) {
+ const pathSections = path.split('/');
+ pathSections.pop();
+ path = pathSections.join('/');
+ }
+ const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}${path}`;
+ window.location.href = `${baseUrl}/${semver}${window.location.hash}`;
}
}