Add onSelectedVersion callback so it can be handled in any way the caller wishes
This commit is contained in:
parent
327cc307b3
commit
6f8a70834b
@ -50,7 +50,7 @@ const sourceUrl = `${
|
|||||||
docsInfoConfig.packageUrl
|
docsInfoConfig.packageUrl
|
||||||
}/blob/@0xproject/web3-wrapper%40${selectedVersion}/packages/web3-wrapper`;
|
}/blob/@0xproject/web3-wrapper%40${selectedVersion}/packages/web3-wrapper`;
|
||||||
|
|
||||||
import * as typeDocJson from './json/web3_wrapper_typedoc_output.json';
|
import * as typeDocJson from './json/0.2.0.json';
|
||||||
const docAgnosticFormat = docsInfo.convertToDocAgnosticFormat(typeDocJson);
|
const docAgnosticFormat = docsInfo.convertToDocAgnosticFormat(typeDocJson);
|
||||||
|
|
||||||
render(
|
render(
|
||||||
@ -61,7 +61,12 @@ render(
|
|||||||
docsInfo={docsInfo}
|
docsInfo={docsInfo}
|
||||||
docAgnosticFormat={docAgnosticFormat}
|
docAgnosticFormat={docAgnosticFormat}
|
||||||
sourceUrl={sourceUrl}
|
sourceUrl={sourceUrl}
|
||||||
|
onVersionSelected={onVersionSelected}
|
||||||
/>
|
/>
|
||||||
</MuiThemeProvider>,
|
</MuiThemeProvider>,
|
||||||
document.getElementById('app'),
|
document.getElementById('app'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function onVersionSelected(semver: string) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
@ -48,9 +48,10 @@ export interface DocumentationProps {
|
|||||||
selectedVersion: string;
|
selectedVersion: string;
|
||||||
availableVersions: string[];
|
availableVersions: string[];
|
||||||
docsInfo: DocsInfo;
|
docsInfo: DocsInfo;
|
||||||
|
sourceUrl: string;
|
||||||
|
onVersionSelected: (semver: string) => void;
|
||||||
docAgnosticFormat?: DocAgnosticFormat;
|
docAgnosticFormat?: DocAgnosticFormat;
|
||||||
sidebarHeader?: React.ReactNode;
|
sidebarHeader?: React.ReactNode;
|
||||||
sourceUrl: string;
|
|
||||||
topBarHeight?: number;
|
topBarHeight?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +126,7 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
|
|||||||
sidebarHeader={this.props.sidebarHeader}
|
sidebarHeader={this.props.sidebarHeader}
|
||||||
topLevelMenu={this.props.docsInfo.getMenu(this.props.selectedVersion)}
|
topLevelMenu={this.props.docsInfo.getMenu(this.props.selectedVersion)}
|
||||||
menuSubsectionsBySection={menuSubsectionsBySection}
|
menuSubsectionsBySection={menuSubsectionsBySection}
|
||||||
|
onVersionSelected={this.props.onVersionSelected}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,6 +18,7 @@ export interface NestedSidebarMenuProps {
|
|||||||
onMenuItemClick?: () => void;
|
onMenuItemClick?: () => void;
|
||||||
selectedVersion?: string;
|
selectedVersion?: string;
|
||||||
versions?: string[];
|
versions?: string[];
|
||||||
|
onVersionSelected?: (semver: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NestedSidebarMenuState {}
|
export interface NestedSidebarMenuState {}
|
||||||
@ -69,6 +70,7 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N
|
|||||||
<VersionDropDown
|
<VersionDropDown
|
||||||
selectedVersion={this.props.selectedVersion}
|
selectedVersion={this.props.selectedVersion}
|
||||||
versions={this.props.versions}
|
versions={this.props.versions}
|
||||||
|
onVersionSelected={this.props.onVersionSelected}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -8,6 +8,7 @@ import { utils } from '../utils/utils';
|
|||||||
export interface VersionDropDownProps {
|
export interface VersionDropDownProps {
|
||||||
selectedVersion: string;
|
selectedVersion: string;
|
||||||
versions: string[];
|
versions: string[];
|
||||||
|
onVersionSelected: (semver: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VersionDropDownState {}
|
export interface VersionDropDownState {}
|
||||||
@ -33,14 +34,6 @@ export class VersionDropDown extends React.Component<VersionDropDownProps, Versi
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
private _updateSelectedVersion(e: any, index: number, semver: string) {
|
private _updateSelectedVersion(e: any, index: number, semver: string) {
|
||||||
let path = window.location.pathname;
|
this.props.onVersionSelected(semver);
|
||||||
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}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,6 @@ export const utils = {
|
|||||||
const id = name.replace(/ /g, '-');
|
const id = name.replace(/ /g, '-');
|
||||||
return id;
|
return id;
|
||||||
},
|
},
|
||||||
getCurrentBaseUrl() {
|
|
||||||
const port = window.location.port;
|
|
||||||
const hasPort = !_.isUndefined(port);
|
|
||||||
const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`;
|
|
||||||
return baseUrl;
|
|
||||||
},
|
|
||||||
getEtherScanLinkIfExists(addressOrTxHash: string, networkId: number, suffix: EtherscanLinkSuffixes): string {
|
getEtherScanLinkIfExists(addressOrTxHash: string, networkId: number, suffix: EtherscanLinkSuffixes): string {
|
||||||
const networkName = constants.NETWORK_NAME_BY_ID[networkId];
|
const networkName = constants.NETWORK_NAME_BY_ID[networkId];
|
||||||
if (_.isUndefined(networkName)) {
|
if (_.isUndefined(networkName)) {
|
||||||
|
@ -38,6 +38,7 @@ interface TopBarProps {
|
|||||||
docsInfo?: DocsInfo;
|
docsInfo?: DocsInfo;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
isNightVersion?: boolean;
|
isNightVersion?: boolean;
|
||||||
|
onVersionSelected?: (semver: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TopBarState {
|
interface TopBarState {
|
||||||
@ -320,6 +321,7 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
|
|||||||
onMenuItemClick={this._onMenuButtonClick.bind(this)}
|
onMenuItemClick={this._onMenuButtonClick.bind(this)}
|
||||||
selectedVersion={this.props.docsVersion}
|
selectedVersion={this.props.docsVersion}
|
||||||
versions={this.props.availableDocVersions}
|
versions={this.props.availableDocVersions}
|
||||||
|
onVersionSelected={this.props.onVersionSelected}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -13,6 +13,7 @@ import { configs } from 'ts/utils/configs';
|
|||||||
import { constants } from 'ts/utils/constants';
|
import { constants } from 'ts/utils/constants';
|
||||||
import { docUtils } from 'ts/utils/doc_utils';
|
import { docUtils } from 'ts/utils/doc_utils';
|
||||||
import { Translate } from 'ts/utils/translate';
|
import { Translate } from 'ts/utils/translate';
|
||||||
|
import { utils } from 'ts/utils/utils';
|
||||||
|
|
||||||
const ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH = '0.32.4';
|
const ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH = '0.32.4';
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
|
|||||||
menuSubsectionsBySection={menuSubsectionsBySection}
|
menuSubsectionsBySection={menuSubsectionsBySection}
|
||||||
docsInfo={this.props.docsInfo}
|
docsInfo={this.props.docsInfo}
|
||||||
translate={this.props.translate}
|
translate={this.props.translate}
|
||||||
|
onVersionSelected={this._onVersionSelected.bind(this)}
|
||||||
/>
|
/>
|
||||||
<Documentation
|
<Documentation
|
||||||
selectedVersion={this.props.docsVersion}
|
selectedVersion={this.props.docsVersion}
|
||||||
@ -89,6 +91,7 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
|
|||||||
sidebarHeader={<SidebarHeader title={this.props.docsInfo.displayName} />}
|
sidebarHeader={<SidebarHeader title={this.props.docsInfo.displayName} />}
|
||||||
sourceUrl={sourceUrl}
|
sourceUrl={sourceUrl}
|
||||||
topBarHeight={60}
|
topBarHeight={60}
|
||||||
|
onVersionSelected={this._onVersionSelected.bind(this)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -141,4 +144,15 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
|
|||||||
const sourceUrl = `${url}/blob/${tagPrefix}%40${this.props.docsVersion}/packages${pkg}`;
|
const sourceUrl = `${url}/blob/${tagPrefix}%40${this.props.docsVersion}/packages${pkg}`;
|
||||||
return sourceUrl;
|
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}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,4 +270,10 @@ export const utils = {
|
|||||||
window.onload = () => resolve();
|
window.onload = () => resolve();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
getCurrentBaseUrl() {
|
||||||
|
const port = window.location.port;
|
||||||
|
const hasPort = !_.isUndefined(port);
|
||||||
|
const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`;
|
||||||
|
return baseUrl;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user