-
Notifications
You must be signed in to change notification settings - Fork 841
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
Add React ^16.0 as a peerDependency, add EuiErrorBoundary #198
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85a3403
Add React 16 as a peer dependency.
cjcenizal 9d12ce1
Export test module.
cjcenizal dd8c4a6
Add EuiErrorBoundary.
cjcenizal b220aa8
Fix test template requiredProps import.
cjcenizal 9267cce
Update CHANGELOG.
cjcenizal bc3a76b
Move react and react-router to devDependencies.
cjcenizal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
EuiErrorBoundary, | ||
} from '../../../../src/components'; | ||
|
||
const BadComponent = () => { | ||
throw new Error('There was a terrible error!'); | ||
}; | ||
|
||
export default () => ( | ||
<EuiErrorBoundary> | ||
<BadComponent /> | ||
</EuiErrorBoundary> | ||
); |
35 changes: 35 additions & 0 deletions
35
src-docs/src/views/error_boundary/error_boundary_example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { | ||
GuideSectionTypes, | ||
} from '../../components'; | ||
|
||
import { | ||
EuiCode, | ||
} from '../../../../src/components'; | ||
|
||
import ErrorBoundary from './error_boundary'; | ||
const errorBoundarySource = require('!!raw-loader!./error_boundary'); | ||
const errorBoundaryHtml = renderToHtml(ErrorBoundary); | ||
|
||
export const ErrorBoundaryExample = { | ||
title: 'ErrorBoundary', | ||
sections: [{ | ||
title: 'ErrorBoundary', | ||
source: [{ | ||
type: GuideSectionTypes.JS, | ||
code: errorBoundarySource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: errorBoundaryHtml, | ||
}], | ||
text: ( | ||
<p> | ||
Use <EuiCode>EuiErrorBoundary</EuiCode> to prevent errors from taking down the entire app. | ||
</p> | ||
), | ||
demo: <ErrorBoundary />, | ||
}], | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/components/error_boundary/__snapshots__/error_boundary.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiErrorBoundary is rendered with an error 1`] = ` | ||
<div | ||
aria-label="aria-label" | ||
class="testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
> | ||
<div | ||
class="euiErrorBoundary__text" | ||
> | ||
<div | ||
class="euiText euiText--extraSmall" | ||
> | ||
<h1> | ||
Error | ||
</h1> | ||
<p> | ||
Error: Terrible error! | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`EuiErrorBoundary is rendered without an error 1`] = ` | ||
<div> | ||
No error | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.euiErrorBoundary { | ||
$color1: transparentize($euiColorDanger, .75); | ||
$color2: transparentize($euiColorDanger, .95); | ||
|
||
background: repeating-linear-gradient( | ||
45deg, | ||
$color1, | ||
$color1 1px, | ||
$color2 1px, | ||
$color2 20px | ||
); | ||
overflow: auto; | ||
padding: $euiSize; | ||
} | ||
|
||
.euiErrorBoundary__text { | ||
background-color: $euiColorEmptyShade; | ||
padding: $euiSizeS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import 'error_boundary'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
EuiText, | ||
} from '../text'; | ||
|
||
export class EuiErrorBoundary extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
hasError: false, | ||
error: undefined, | ||
}; | ||
} | ||
|
||
componentDidCatch(error) { | ||
// Display fallback UI | ||
this.setState({ | ||
hasError: true, | ||
error | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
children, | ||
...rest | ||
} = this.props; | ||
|
||
if (this.state.hasError) { | ||
// You can render any custom fallback UI | ||
return ( | ||
<div className="euiErrorBoundary" {...rest}> | ||
<div className="euiErrorBoundary__text"> | ||
<EuiText size="xs"> | ||
<h1>Error</h1> | ||
<p> | ||
{this.state.error && this.state.error.toString()} | ||
</p> | ||
</EuiText> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
return children; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move
react
andreact-router
fromdependencies
todevDependencies
too, because at present these modules get installed when I do a regular install of@elastic/eui
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.