Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EuiErrorBoundary: converted to Typescript #2690

Merged
merged 11 commits into from
Dec 26, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- 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 `EuiErroBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690))
ffknob marked this conversation as resolved.
Show resolved Hide resolved
- 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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('EuiErrorBoundary', () => {
test('is rendered without an error', () => {
const component = takeMountedSnapshot(
mount(
<EuiErrorBoundary {...requiredProps}>
<EuiErrorBoundary {...requiredProps} hasError={false}>
<GoodComponent />
</EuiErrorBoundary>
)
Expand All @@ -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(
<EuiErrorBoundary {...requiredProps}>
<EuiErrorBoundary
{...requiredProps}
error={new Error(errorMessage)}
hasError={true}>
<BadComponent />
</EuiErrorBoundary>
).text();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
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 {
ffknob marked this conversation as resolved.
Show resolved Hide resolved
stack?: any;
}

interface EuiErrorBoundaryState {
hasError: boolean;
error?: Error;
}

export type EuiErrorBoundaryProps = EuiErrorBoundaryState & CommonProps & {};
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved

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,
Expand Down