Add back strict null checks to react-shared package and fix issues

This commit is contained in:
Fabio Berger
2018-03-08 16:19:39 +01:00
parent f9ec8a0828
commit 8057f4a678
5 changed files with 30 additions and 13 deletions

View File

@@ -19,6 +19,12 @@ export interface MarkdownSectionProps {
githubLink?: string;
}
interface DefaultMarkdownSectionProps {
headerSize: HeaderSizes;
}
type PropsWithDefaults = MarkdownSectionProps & DefaultMarkdownSectionProps;
export interface MarkdownSectionState {
shouldShowAnchor: boolean;
}
@@ -34,7 +40,8 @@ export class MarkdownSection extends React.Component<MarkdownSectionProps, Markd
};
}
public render() {
const sectionName = this.props.sectionName;
const { sectionName, markdownContent, headerSize, githubLink } = this.props as PropsWithDefaults;
const id = utils.getIdFromName(sectionName);
return (
<div
@@ -47,7 +54,7 @@ export class MarkdownSection extends React.Component<MarkdownSectionProps, Markd
<div className="col lg-col-8 md-col-8 sm-col-12">
<span style={{ textTransform: 'capitalize', color: colors.grey700 }}>
<AnchorTitle
headerSize={this.props.headerSize}
headerSize={headerSize}
title={sectionName}
id={id}
shouldShowAnchor={this.state.shouldShowAnchor}
@@ -55,9 +62,9 @@ export class MarkdownSection extends React.Component<MarkdownSectionProps, Markd
</span>
</div>
<div className="col col-4 sm-hide xs-hide right-align pr3" style={{ height: 28 }}>
{!_.isUndefined(this.props.githubLink) && (
{!_.isUndefined(githubLink) && (
<a
href={this.props.githubLink}
href={githubLink}
target="_blank"
style={{ color: colors.linkBlue, textDecoration: 'none', lineHeight: 2.1 }}
>
@@ -68,7 +75,7 @@ export class MarkdownSection extends React.Component<MarkdownSectionProps, Markd
</div>
<hr style={{ border: `1px solid ${colors.lightestGrey}` }} />
<ReactMarkdown
source={this.props.markdownContent}
source={markdownContent}
escapeHtml={false}
renderers={{
code: MarkdownCodeBlock,

View File

@@ -65,7 +65,8 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N
<div>
{this.props.sidebarHeader}
{!_.isUndefined(this.props.versions) &&
!_.isUndefined(this.props.selectedVersion) && (
!_.isUndefined(this.props.selectedVersion) &&
!_.isUndefined(this.props.onVersionSelected) && (
<div style={{ maxWidth: maxWidthWithScrollbar }}>
<VersionDropDown
selectedVersion={this.props.selectedVersion}
@@ -150,6 +151,8 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N
private _onMenuItemClick(name: string): void {
const id = utils.getIdFromName(name);
utils.setUrlHash(id);
this.props.onMenuItemClick();
if (!_.isUndefined(this.props.onMenuItemClick)) {
this.props.onMenuItemClick();
}
}
}

View File

@@ -12,6 +12,12 @@ export interface SectionHeaderProps {
headerSize?: HeaderSizes;
}
interface DefaultSectionHeaderProps {
headerSize: HeaderSizes;
}
type PropsWithDefaults = SectionHeaderProps & DefaultSectionHeaderProps;
export interface SectionHeaderState {
shouldShowAnchor: boolean;
}
@@ -27,8 +33,10 @@ export class SectionHeader extends React.Component<SectionHeaderProps, SectionHe
};
}
public render() {
const sectionName = this.props.sectionName.replace(/-/g, ' ');
const id = utils.getIdFromName(sectionName);
const { sectionName, headerSize } = this.props as PropsWithDefaults;
const finalSectionName = this.props.sectionName.replace(/-/g, ' ');
const id = utils.getIdFromName(finalSectionName);
return (
<div
onMouseOver={this._setAnchorVisibility.bind(this, true)}
@@ -36,7 +44,7 @@ export class SectionHeader extends React.Component<SectionHeaderProps, SectionHe
>
<ScrollElement name={id}>
<AnchorTitle
headerSize={this.props.headerSize}
headerSize={headerSize}
title={
<span
style={{
@@ -47,7 +55,7 @@ export class SectionHeader extends React.Component<SectionHeaderProps, SectionHe
fontSize: 27,
}}
>
{sectionName}
{finalSectionName}
</span>
}
id={id}

View File

@@ -30,7 +30,7 @@ export const utils = {
const id = name.replace(/ /g, '-');
return id;
},
getEtherScanLinkIfExists(addressOrTxHash: string, networkId: number, suffix: EtherscanLinkSuffixes): string {
getEtherScanLinkIfExists(addressOrTxHash: string, networkId: number, suffix: EtherscanLinkSuffixes): string|undefined {
const networkName = constants.NETWORK_NAME_BY_ID[networkId];
if (_.isUndefined(networkName)) {
return undefined;