aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/pages/documentation/doc_page.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/website/ts/pages/documentation/doc_page.tsx')
-rw-r--r--packages/website/ts/pages/documentation/doc_page.tsx52
1 files changed, 39 insertions, 13 deletions
diff --git a/packages/website/ts/pages/documentation/doc_page.tsx b/packages/website/ts/pages/documentation/doc_page.tsx
index 2c8f1c103..1281219c6 100644
--- a/packages/website/ts/pages/documentation/doc_page.tsx
+++ b/packages/website/ts/pages/documentation/doc_page.tsx
@@ -1,23 +1,27 @@
+import { DocAgnosticFormat, DocsInfo, Documentation, DoxityDocObj } from '@0xproject/react-docs';
+import { MenuSubsectionsBySection } from '@0xproject/react-shared';
import findVersions = require('find-versions');
import * as _ from 'lodash';
import * as React from 'react';
import DocumentTitle = require('react-document-title');
import semverSort = require('semver-sort');
+import { SidebarHeader } from 'ts/components/sidebar_header';
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, DocPackages, DoxityDocObj, Environments, MenuSubsectionsBySection } from 'ts/types';
+import { DocPackages, Environments } 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';
+import { utils } from 'ts/utils/utils';
+const ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH = '0.32.4';
+
+const isDevelopment = configs.ENVIRONMENT === Environments.DEVELOPMENT;
const docIdToS3BucketName: { [id: string]: string } = {
- [DocPackages.ZeroExJs]: '0xjs-docs-jsons',
+ [DocPackages.ZeroExJs]: isDevelopment ? 'staging-0xjs-docs-jsons' : '0xjs-docs-jsons',
[DocPackages.SmartContracts]: 'smart-contracts-docs-json',
- [DocPackages.Connect]:
- configs.ENVIRONMENT === Environments.DEVELOPMENT ? 'staging-connect-docs-jsons' : 'connect-docs-jsons',
+ [DocPackages.Connect]: isDevelopment ? 'staging-connect-docs-jsons' : 'connect-docs-jsons',
};
const docIdToSubpackageName: { [id: string]: string } = {
@@ -77,15 +81,17 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
menuSubsectionsBySection={menuSubsectionsBySection}
docsInfo={this.props.docsInfo}
translate={this.props.translate}
+ onVersionSelected={this._onVersionSelected.bind(this)}
/>
<Documentation
- location={this.props.location}
- docsVersion={this.props.docsVersion}
- availableDocVersions={this.props.availableDocVersions}
+ selectedVersion={this.props.docsVersion}
+ availableVersions={this.props.availableDocVersions}
docsInfo={this.props.docsInfo}
docAgnosticFormat={this.state.docAgnosticFormat}
- menuSubsectionsBySection={menuSubsectionsBySection}
+ sidebarHeader={<SidebarHeader title={this.props.docsInfo.displayName} />}
sourceUrl={sourceUrl}
+ topBarHeight={60}
+ onVersionSelected={this._onVersionSelected.bind(this)}
/>
</div>
);
@@ -110,7 +116,7 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
const versionFileNameToFetch = versionToFileName[versionToFetch];
const versionDocObj = await docUtils.getJSONDocFileAsync(versionFileNameToFetch, docsJsonRoot);
- const docAgnosticFormat = this.props.docsInfo.convertToDocAgnosticFormat(versionDocObj as DoxityDocObj);
+ const docAgnosticFormat = this.props.docsInfo.convertToDocAgnosticFormat(versionDocObj);
if (!this._isUnmounted) {
this.setState({
@@ -120,13 +126,33 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
}
private _getSourceUrl() {
const url = this.props.docsInfo.packageUrl;
- const pkg = docIdToSubpackageName[this.props.docsInfo.id];
+ let 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}`;
+ // HACK: The following three lines exist for backward compatibility reasons
+ // Before exporting types from other packages as part of the 0x.js interface,
+ // all TypeDoc generated paths omitted the topLevel `0x.js` segment. Now it
+ // adds it, and for that reason, we need to make sure we don't add it twice in
+ // the source links we generate.
+ const semvers = semverSort.desc([this.props.docsVersion, ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH]);
+ const isVersionAfterTopLevelPathChange = semvers[0] !== ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH;
+ pkg = this.props.docsInfo.id === DocPackages.ZeroExJs && isVersionAfterTopLevelPathChange ? '' : `/${pkg}`;
+
+ const sourceUrl = `${url}/blob/${tagPrefix}%40${this.props.docsVersion}/packages${pkg}`;
return sourceUrl;
}
+ private _onVersionSelected(semver: string) {
+ 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 = utils.getCurrentBaseUrl();
+ window.location.href = `${baseUrl}${path}/${semver}${window.location.hash}`;
+ }
}