diff options
author | Fabio Berger <me@fabioberger.com> | 2018-02-28 06:29:22 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-02-28 06:29:22 +0800 |
commit | 97fcfb7f6c62aefa3f3a736f7783529d4e3e0018 (patch) | |
tree | 8b7d202ecceb6f467c94c7a4ce95049b5700b88f /packages/website/ts/pages/documentation/doc_page.tsx | |
parent | ecba95250d0bfc5b4ab0950ef490a4f262672e6c (diff) | |
download | dexon-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/documentation/doc_page.tsx')
-rw-r--r-- | packages/website/ts/pages/documentation/doc_page.tsx | 31 |
1 files changed, 25 insertions, 6 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; + } } |