diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-08 23:19:39 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-03-08 23:19:39 +0800 |
commit | 8057f4a678f5e4c00241ec9b15bd9d4dfc3588df (patch) | |
tree | ad08f11e6e2ac0d8fea0708652e3defe3ad89df6 /packages | |
parent | f9ec8a0828b7f75276491e496a4ae62e5301a6f3 (diff) | |
download | dexon-0x-contracts-8057f4a678f5e4c00241ec9b15bd9d4dfc3588df.tar dexon-0x-contracts-8057f4a678f5e4c00241ec9b15bd9d4dfc3588df.tar.gz dexon-0x-contracts-8057f4a678f5e4c00241ec9b15bd9d4dfc3588df.tar.bz2 dexon-0x-contracts-8057f4a678f5e4c00241ec9b15bd9d4dfc3588df.tar.lz dexon-0x-contracts-8057f4a678f5e4c00241ec9b15bd9d4dfc3588df.tar.xz dexon-0x-contracts-8057f4a678f5e4c00241ec9b15bd9d4dfc3588df.tar.zst dexon-0x-contracts-8057f4a678f5e4c00241ec9b15bd9d4dfc3588df.zip |
Add back strict null checks to react-shared package and fix issues
Diffstat (limited to 'packages')
5 files changed, 30 insertions, 13 deletions
diff --git a/packages/react-shared/src/ts/components/markdown_section.tsx b/packages/react-shared/src/ts/components/markdown_section.tsx index 682b6ef8f..95dc83eaf 100644 --- a/packages/react-shared/src/ts/components/markdown_section.tsx +++ b/packages/react-shared/src/ts/components/markdown_section.tsx @@ -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, diff --git a/packages/react-shared/src/ts/components/nested_sidebar_menu.tsx b/packages/react-shared/src/ts/components/nested_sidebar_menu.tsx index f562b3113..2225bd197 100644 --- a/packages/react-shared/src/ts/components/nested_sidebar_menu.tsx +++ b/packages/react-shared/src/ts/components/nested_sidebar_menu.tsx @@ -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(); + } } } diff --git a/packages/react-shared/src/ts/components/section_header.tsx b/packages/react-shared/src/ts/components/section_header.tsx index 90fabf9ff..e782783f3 100644 --- a/packages/react-shared/src/ts/components/section_header.tsx +++ b/packages/react-shared/src/ts/components/section_header.tsx @@ -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} diff --git a/packages/react-shared/src/ts/utils/utils.ts b/packages/react-shared/src/ts/utils/utils.ts index ebe896bbc..9e848392f 100644 --- a/packages/react-shared/src/ts/utils/utils.ts +++ b/packages/react-shared/src/ts/utils/utils.ts @@ -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; diff --git a/packages/react-shared/tsconfig.json b/packages/react-shared/tsconfig.json index 44055a037..de87aa45b 100644 --- a/packages/react-shared/tsconfig.json +++ b/packages/react-shared/tsconfig.json @@ -4,7 +4,6 @@ "outDir": "./lib/", "jsx": "react", "baseUrl": "./", - "strictNullChecks": false, "paths": { "*": ["node_modules/@types/*", "*"] } |