@@ -6,57 +6,83 @@ import {Button, Disclosure} from '@gravity-ui/uikit';
66
77import { registerError } from '../../utils/registerError' ;
88import { Illustration } from '../Illustration' ;
9+ import { useComponent } from '../ComponentsProvider/ComponentsProvider' ;
910import i18n from './i18n' ;
1011import './ErrorBoundary.scss' ;
1112
1213const b = cn ( 'ydb-error-boundary' ) ;
1314
15+ export function ErrorBoundary ( { children} : { children ?: ReactNode } ) {
16+ const ErrorBoundaryComponent = useComponent ( 'ErrorBoundary' ) ;
17+ return < ErrorBoundaryComponent > { children } </ ErrorBoundaryComponent > ;
18+ }
19+
1420interface ErrorBoundaryProps {
1521 children ?: ReactNode ;
1622 useRetry ?: boolean ;
1723 onReportProblem ?: ( error ?: Error ) => void ;
1824}
1925
20- export const ErrorBoundary = ( { children, useRetry = true , onReportProblem} : ErrorBoundaryProps ) => {
26+ export function ErrorBoundaryInner ( {
27+ children,
28+ useRetry = true ,
29+ onReportProblem,
30+ } : ErrorBoundaryProps ) {
2131 return (
2232 < ErrorBoundaryBase
2333 onError = { ( error , info ) => {
2434 registerError ( error , info . componentStack , 'error-boundary' ) ;
2535 } }
2636 fallbackRender = { ( { error, resetErrorBoundary} ) => {
2737 return (
28- < div className = { b ( null ) } >
29- < Illustration name = "error" className = { b ( 'illustration' ) } />
30- < div className = { b ( 'content' ) } >
31- < h2 className = { b ( 'error-title' ) } > { i18n ( 'error-title' ) } </ h2 >
32- < div className = { b ( 'error-description' ) } >
33- { i18n ( 'error-description' ) }
34- </ div >
35- < Disclosure
36- summary = { i18n ( 'show-details' ) }
37- className = { b ( 'show-details' ) }
38- size = "m"
39- >
40- < pre className = { b ( 'error-details' ) } > { error . stack } </ pre >
41- </ Disclosure >
42- < div className = { b ( 'actions' ) } >
43- { useRetry && (
44- < Button view = "outlined" onClick = { resetErrorBoundary } >
45- { i18n ( 'button-reset' ) }
46- </ Button >
47- ) }
48- { onReportProblem && (
49- < Button view = "outlined" onClick = { ( ) => onReportProblem ( error ) } >
50- { i18n ( 'report-problem' ) }
51- </ Button >
52- ) }
53- </ div >
54- </ div >
55- </ div >
38+ < ErrorBoundaryFallback
39+ error = { error }
40+ useRetry = { useRetry }
41+ resetErrorBoundary = { resetErrorBoundary }
42+ onReportProblem = { onReportProblem }
43+ />
5644 ) ;
5745 } }
5846 >
5947 { children }
6048 </ ErrorBoundaryBase >
6149 ) ;
62- } ;
50+ }
51+
52+ interface ErrorBoundaryFallbackProps {
53+ error : Error ;
54+ useRetry ?: boolean ;
55+ resetErrorBoundary : ( ) => void ;
56+ onReportProblem ?: ( error ?: Error ) => void ;
57+ }
58+ export function ErrorBoundaryFallback ( {
59+ error,
60+ resetErrorBoundary,
61+ useRetry,
62+ onReportProblem,
63+ } : ErrorBoundaryFallbackProps ) {
64+ return (
65+ < div className = { b ( ) } >
66+ < Illustration name = "error" className = { b ( 'illustration' ) } />
67+ < div className = { b ( 'content' ) } >
68+ < h2 className = { b ( 'error-title' ) } > { i18n ( 'error-title' ) } </ h2 >
69+ < div className = { b ( 'error-description' ) } > { i18n ( 'error-description' ) } </ div >
70+ < Disclosure summary = { i18n ( 'show-details' ) } className = { b ( 'show-details' ) } size = "m" >
71+ < pre className = { b ( 'error-details' ) } > { error . stack } </ pre >
72+ </ Disclosure >
73+ < div className = { b ( 'actions' ) } >
74+ { useRetry && (
75+ < Button view = "outlined" onClick = { resetErrorBoundary } >
76+ { i18n ( 'button-reset' ) }
77+ </ Button >
78+ ) }
79+ { onReportProblem && (
80+ < Button view = "outlined" onClick = { ( ) => onReportProblem ( error ) } >
81+ { i18n ( 'report-problem' ) }
82+ </ Button >
83+ ) }
84+ </ div >
85+ </ div >
86+ </ div >
87+ ) ;
88+ }
0 commit comments