From 49d6596878df2e356150579fdd6b4e55cdad0344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Franco=20Knob?= Date: Wed, 18 Dec 2019 10:07:02 -0300 Subject: [PATCH 1/7] Converts EuiErrorBoundary to Typescript --- 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} | 22 +++++++++++++++---- .../error_boundary/{index.js => index.ts} | 0 5 files changed, 19 insertions(+), 4 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} (67%) rename src/components/error_boundary/{index.js => index.ts} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9371f3bae2c..25765bb0bd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## [`master`](https://github.com/elastic/eui/tree/master) - Converted `EuiHighlight` to Typescript ([#2681](https://github.com/elastic/eui/pull/2681)) +- Converted `EuiErroBoundary` to Typescript ([#](https://github.com/elastic/eui/pull/)) **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 67% rename from src/components/error_boundary/error_boundary.js rename to src/components/error_boundary/error_boundary.tsx index c65452ecce9..430ef5559dc 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 { CommonProps } from '../common'; import PropTypes from 'prop-types'; import { EuiText } from '../text'; -export class EuiErrorBoundary extends Component { +interface Error { + stack?: any; +} + +interface ErrorState { + hasError: boolean; + error: Error | undefined; +} + +export type EuiErrorBoundaryProps = ErrorState & CommonProps & {}; + +export class EuiErrorBoundary extends Component<{}, EuiErrorBoundaryProps> { static propTypes = { children: PropTypes.node, }; - constructor(props) { + constructor(props: EuiErrorBoundaryProps) { super(props); - this.state = { + const errorState: ErrorState = { 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.js b/src/components/error_boundary/index.ts similarity index 100% rename from src/components/error_boundary/index.js rename to src/components/error_boundary/index.ts From 3bf60d8d149437c7d1c29c59811efa2d0a8ea759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Franco=20Knob?= Date: Wed, 18 Dec 2019 10:10:50 -0300 Subject: [PATCH 2/7] Adds PR number to the CHANGELOG line --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25765bb0bd9..79c82e59d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## [`master`](https://github.com/elastic/eui/tree/master) - Converted `EuiHighlight` to Typescript ([#2681](https://github.com/elastic/eui/pull/2681)) -- Converted `EuiErroBoundary` to Typescript ([#](https://github.com/elastic/eui/pull/)) +- Converted `EuiErroBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690)) **Bug fixes** From 42af42604eacac9c89b01343e8f0c4b14a8fee62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Knob?= Date: Wed, 18 Dec 2019 19:39:16 -0300 Subject: [PATCH 3/7] Fixes as requested in PR review --- .../error_boundary/error_boundary.test.tsx | 7 +++++-- src/components/error_boundary/error_boundary.tsx | 13 ++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/error_boundary/error_boundary.test.tsx b/src/components/error_boundary/error_boundary.test.tsx index 0183b0ecd72..7d3fe976819 100644 --- a/src/components/error_boundary/error_boundary.test.tsx +++ b/src/components/error_boundary/error_boundary.test.tsx @@ -17,7 +17,7 @@ describe('EuiErrorBoundary', () => { test('is rendered without an error', () => { const component = takeMountedSnapshot( mount( - + ) @@ -33,7 +33,10 @@ describe('EuiErrorBoundary', () => { // Because the error contains the stack trace, it's non-deterministic. So we'll just check that // it contains our error message. const errorText = mount( - + ).text(); diff --git a/src/components/error_boundary/error_boundary.tsx b/src/components/error_boundary/error_boundary.tsx index 430ef5559dc..182e5e4afd1 100644 --- a/src/components/error_boundary/error_boundary.tsx +++ b/src/components/error_boundary/error_boundary.tsx @@ -8,14 +8,17 @@ interface Error { stack?: any; } -interface ErrorState { +interface EuiErrorBoundaryState { hasError: boolean; - error: Error | undefined; + error?: Error; } -export type EuiErrorBoundaryProps = ErrorState & CommonProps & {}; +export type EuiErrorBoundaryProps = EuiErrorBoundaryState & CommonProps & {}; -export class EuiErrorBoundary extends Component<{}, EuiErrorBoundaryProps> { +export class EuiErrorBoundary extends Component< + EuiErrorBoundaryProps, + EuiErrorBoundaryState +> { static propTypes = { children: PropTypes.node, }; @@ -23,7 +26,7 @@ export class EuiErrorBoundary extends Component<{}, EuiErrorBoundaryProps> { constructor(props: EuiErrorBoundaryProps) { super(props); - const errorState: ErrorState = { + const errorState: EuiErrorBoundaryState = { hasError: false, error: undefined, }; From 306a68ce833266a7567f06649e66bd5f2681cdec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Franco=20Knob?= Date: Thu, 19 Dec 2019 16:00:24 -0300 Subject: [PATCH 4/7] Fixes as requested in the review --- CHANGELOG.md | 2 +- src/components/error_boundary/error_boundary.tsx | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79c82e59d60..288e2cc91d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## [`master`](https://github.com/elastic/eui/tree/master) - Converted `EuiHighlight` to Typescript ([#2681](https://github.com/elastic/eui/pull/2681)) -- Converted `EuiErroBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690)) +- Converted `EuiErrorBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690)) **Bug fixes** diff --git a/src/components/error_boundary/error_boundary.tsx b/src/components/error_boundary/error_boundary.tsx index 430ef5559dc..9e2be567b1b 100644 --- a/src/components/error_boundary/error_boundary.tsx +++ b/src/components/error_boundary/error_boundary.tsx @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { Component, HTMLAttributes } from 'react'; import { CommonProps } from '../common'; import PropTypes from 'prop-types'; @@ -13,9 +13,13 @@ interface ErrorState { error: Error | undefined; } -export type EuiErrorBoundaryProps = ErrorState & CommonProps & {}; +export type EuiErrorBoundaryProps = CommonProps & + HTMLAttributes; -export class EuiErrorBoundary extends Component<{}, EuiErrorBoundaryProps> { +export class EuiErrorBoundary extends Component< + {}, + EuiErrorBoundaryProps & ErrorState +> { static propTypes = { children: PropTypes.node, }; From f6742c96853dd4ffaec7dfdaef0814aec1982fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Franco=20Knob?= Date: Thu, 19 Dec 2019 18:10:34 -0300 Subject: [PATCH 5/7] Removes Error interface --- src/components/error_boundary/error_boundary.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/error_boundary/error_boundary.tsx b/src/components/error_boundary/error_boundary.tsx index b42ecf2e28e..8e00024215f 100644 --- a/src/components/error_boundary/error_boundary.tsx +++ b/src/components/error_boundary/error_boundary.tsx @@ -4,10 +4,6 @@ import PropTypes from 'prop-types'; import { EuiText } from '../text'; -interface Error { - stack?: any; -} - interface EuiErrorBoundaryState { hasError: boolean; error?: Error; From 6dfb9568128115b5190d7686c907c4d361f5a3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Knob?= Date: Sat, 21 Dec 2019 21:50:34 -0300 Subject: [PATCH 6/7] Fixes what was asked in the review --- CHANGELOG.md | 2 +- src/components/error_boundary/index.d.ts | 9 --------- src/components/index.d.ts | 1 - 3 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 src/components/error_boundary/index.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index d4cf717025b..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** @@ -18,7 +19,6 @@ - Converted `EuiFieldNumber` to Typescript ([#2685](https://github.com/elastic/eui/pull/2685)) - Converted `EuiFieldPassword` to Typescript ([#2683](https://github.com/elastic/eui/pull/2683)) - Converted `EuiHighlight` to Typescript ([#2681](https://github.com/elastic/eui/pull/2681)) -- Converted `EuiErrorBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690)) - Added `data-test-subj` property to the `EuiCodeEditor` component ([#2689](https://github.com/elastic/eui/pull/2689)) - Converted `EuiTextArea` to Typescript ([#2695](https://github.com/elastic/eui/pull/2695)) - Converted `EuiPage` and related child components to TypeScript ([#2669](https://github.com/elastic/eui/pull/2669)) 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/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 @@ /// /// /// -/// /// /// /// From dc19906a182e3902864f1534a77412efd9501a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Knob?= Date: Thu, 26 Dec 2019 18:14:47 -0300 Subject: [PATCH 7/7] Exports EuiErrorBoundaryProps --- src/components/error_boundary/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/error_boundary/index.ts b/src/components/error_boundary/index.ts index ef3275c00f7..17078e25e9c 100644 --- a/src/components/error_boundary/index.ts +++ b/src/components/error_boundary/index.ts @@ -1 +1 @@ -export { EuiErrorBoundary } from './error_boundary'; +export { EuiErrorBoundary, EuiErrorBoundaryProps } from './error_boundary';