From cc2ee15b2feed01957b6d525a5b9199353a6708e Mon Sep 17 00:00:00 2001 From: ffknob Date: Thu, 26 Dec 2019 19:12:41 -0300 Subject: [PATCH] EuiErrorBoundary: converted to Typescript (#2690) * Converts EuiErrorBoundary to Typescript * Adds PR number to the CHANGELOG line * Fixes as requested in PR review * Fixes as requested in the review * Removes Error interface * Fixes what was asked in the review * Exports EuiErrorBoundaryProps --- CHANGELOG.md | 1 + ...t.js.snap => error_boundary.test.tsx.snap} | 0 ...undary.test.js => error_boundary.test.tsx} | 0 .../{error_boundary.js => error_boundary.tsx} | 24 +++++++++++++++---- src/components/error_boundary/index.d.ts | 9 ------- src/components/error_boundary/index.js | 1 - src/components/error_boundary/index.ts | 1 + src/components/index.d.ts | 1 - 8 files changed, 21 insertions(+), 16 deletions(-) rename src/components/error_boundary/__snapshots__/{error_boundary.test.js.snap => error_boundary.test.tsx.snap} (100%) rename src/components/error_boundary/{error_boundary.test.js => error_boundary.test.tsx} (100%) rename src/components/error_boundary/{error_boundary.js => error_boundary.tsx} (62%) delete mode 100644 src/components/error_boundary/index.d.ts delete mode 100644 src/components/error_boundary/index.js create mode 100644 src/components/error_boundary/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f1773902de..b33215da0fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Added `nested` glyph to `EuiIcon` ([#2707](https://github.com/elastic/eui/pull/2707)) - Added `tableLayout` prop to `EuiTable`, `EuiBasicTable` and `EuiInMemoryTable` to provide the option of auto layout ([#2697](https://github.com/elastic/eui/pull/2697)) +- Converted `EuiErrorBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690)) **Bug fixes** diff --git a/src/components/error_boundary/__snapshots__/error_boundary.test.js.snap b/src/components/error_boundary/__snapshots__/error_boundary.test.tsx.snap similarity index 100% rename from src/components/error_boundary/__snapshots__/error_boundary.test.js.snap rename to src/components/error_boundary/__snapshots__/error_boundary.test.tsx.snap diff --git a/src/components/error_boundary/error_boundary.test.js b/src/components/error_boundary/error_boundary.test.tsx similarity index 100% rename from src/components/error_boundary/error_boundary.test.js rename to src/components/error_boundary/error_boundary.test.tsx diff --git a/src/components/error_boundary/error_boundary.js b/src/components/error_boundary/error_boundary.tsx similarity index 62% rename from src/components/error_boundary/error_boundary.js rename to src/components/error_boundary/error_boundary.tsx index c65452ecce9..8e00024215f 100644 --- a/src/components/error_boundary/error_boundary.js +++ b/src/components/error_boundary/error_boundary.tsx @@ -1,23 +1,37 @@ -import React, { Component } from 'react'; +import React, { Component, HTMLAttributes } from 'react'; +import { CommonProps } from '../common'; import PropTypes from 'prop-types'; import { EuiText } from '../text'; -export class EuiErrorBoundary extends Component { +interface EuiErrorBoundaryState { + hasError: boolean; + error?: Error; +} + +export type EuiErrorBoundaryProps = CommonProps & + HTMLAttributes; + +export class EuiErrorBoundary extends Component< + EuiErrorBoundaryProps, + EuiErrorBoundaryState +> { static propTypes = { children: PropTypes.node, }; - constructor(props) { + constructor(props: EuiErrorBoundaryProps) { super(props); - this.state = { + const errorState: EuiErrorBoundaryState = { hasError: false, error: undefined, }; + + this.state = errorState; } - componentDidCatch(error) { + componentDidCatch(error: Error) { // Display fallback UI this.setState({ hasError: true, diff --git a/src/components/error_boundary/index.d.ts b/src/components/error_boundary/index.d.ts deleted file mode 100644 index c2a9592bbca..00000000000 --- a/src/components/error_boundary/index.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { HTMLAttributes, Component } from 'react'; -import { CommonProps } from '../common'; - -declare module '@elastic/eui' { - // eslint-disable-next-line react/prefer-stateless-function - export class EuiErrorBoundary extends Component< - CommonProps & HTMLAttributes - > {} -} diff --git a/src/components/error_boundary/index.js b/src/components/error_boundary/index.js deleted file mode 100644 index ef3275c00f7..00000000000 --- a/src/components/error_boundary/index.js +++ /dev/null @@ -1 +0,0 @@ -export { EuiErrorBoundary } from './error_boundary'; diff --git a/src/components/error_boundary/index.ts b/src/components/error_boundary/index.ts new file mode 100644 index 00000000000..17078e25e9c --- /dev/null +++ b/src/components/error_boundary/index.ts @@ -0,0 +1 @@ +export { EuiErrorBoundary, EuiErrorBoundaryProps } from './error_boundary'; diff --git a/src/components/index.d.ts b/src/components/index.d.ts index 3db682a3c7d..0841f75163c 100644 --- a/src/components/index.d.ts +++ b/src/components/index.d.ts @@ -1,7 +1,6 @@ /// /// /// -/// /// /// ///