Add onSelectedVersion callback so it can be handled in any way the caller wishes

This commit is contained in:
Fabio Berger
2018-03-07 13:25:15 +01:00
parent 327cc307b3
commit 6f8a70834b
9 changed files with 35 additions and 17 deletions

View File

@@ -18,6 +18,7 @@ export interface NestedSidebarMenuProps {
onMenuItemClick?: () => void;
selectedVersion?: string;
versions?: string[];
onVersionSelected?: (semver: string) => void;
}
export interface NestedSidebarMenuState {}
@@ -69,6 +70,7 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N
<VersionDropDown
selectedVersion={this.props.selectedVersion}
versions={this.props.versions}
onVersionSelected={this.props.onVersionSelected}
/>
</div>
)}

View File

@@ -8,6 +8,7 @@ import { utils } from '../utils/utils';
export interface VersionDropDownProps {
selectedVersion: string;
versions: string[];
onVersionSelected: (semver: string) => void;
}
export interface VersionDropDownState {}
@@ -33,14 +34,6 @@ export class VersionDropDown extends React.Component<VersionDropDownProps, Versi
return items;
}
private _updateSelectedVersion(e: any, index: number, 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}`;
this.props.onVersionSelected(semver);
}
}

View File

@@ -30,12 +30,6 @@ export const utils = {
const id = name.replace(/ /g, '-');
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 {
const networkName = constants.NETWORK_NAME_BY_ID[networkId];
if (_.isUndefined(networkName)) {