diff --git a/ivette/src/dome/src/renderer/errors.js b/ivette/src/dome/src/renderer/errors.js deleted file mode 100644 index ae951aa7ee0fe87c9be98dd687e9d0e769b63fa8..0000000000000000000000000000000000000000 --- a/ivette/src/dome/src/renderer/errors.js +++ /dev/null @@ -1,78 +0,0 @@ -// -------------------------------------------------------------------------- -// --- Managing Errors -// -------------------------------------------------------------------------- - -/** - @packageDocumentation - @module dome/errors -*/ - -import React from 'react' ; -import { Label } from 'dome/controls/labels' ; -import { Button } from 'dome/controls/buttons' ; - -// -------------------------------------------------------------------------- -// --- Error Boundaries -// -------------------------------------------------------------------------- - -/** - @summary React Error Boundaries. - @property {string} [label] - Default error box label - @property {function} [onError] - Alternative renderer - @description - Install an error boundary. In case of error, the default - rendering is a warning button that output on console the - catched error. - - An alternative rendering can be supplied - with `onError:(error,info) => React.Element`. - - */ -export class Catch extends React.Component -{ - - constructor(props) { - super(props); - this.state = { }; - this.logerr = this.logerr.bind(this); - this.reload = this.reload.bind(this); - } - - dumpError(error,info) { - } - - componentDidCatch(error, info) { - this.setState({ error, info }); - } - - logerr() { - const { error, info } = this.state ; - console.error('[dome] Catched error:',error,info); - } - - reload() { - this.setState({ error: undefined, info: undefined }); - } - - render() { - const { error, info } = this.state ; - if (error) { - const { onError, label='Error' } = this.props ; - if (typeof(onError)==='function') - return onError(error,info,this.reload); - else - return ( - <div> - <Button icon='WARNING' kind='warning' - title={error} - onClick={this.logerr} /> - <Button icon='RELOAD' onClick={this.reload} /> - <Label>{label}</Label> - </div> - ); - } - return this.props.children || null ; - } -} - -// -------------------------------------------------------------------------- diff --git a/ivette/src/dome/src/renderer/errors.tsx b/ivette/src/dome/src/renderer/errors.tsx new file mode 100644 index 0000000000000000000000000000000000000000..aebd9ec39ef3903c740957cfba9b9aefd5f7e0ab --- /dev/null +++ b/ivette/src/dome/src/renderer/errors.tsx @@ -0,0 +1,84 @@ +// -------------------------------------------------------------------------- +// --- Managing Errors +// -------------------------------------------------------------------------- + +/** + @packageDocumentation + @module dome/errors +*/ + +import React from 'react'; +import { Label } from 'dome/controls/labels'; +import { Button } from 'dome/controls/buttons'; + +// -------------------------------------------------------------------------- +// --- Error Boundaries +// -------------------------------------------------------------------------- + +/** + Alternative renderer in case of error. + @param reload - callback for re-rendering the faulty component + */ +export interface renderError { + (error: any, info: any, reload: () => void): JSX.Element; +} + +export interface CatchProps { + /** Name of the error boundary. */ + label?: string; + /** Alternative renderer callback in case of errors. */ + onError?: JSX.Element | renderError; +} + +interface CatchState { + error?: any; + info?: any; +} + +/** + React Error Boundaries. + */ +export class Catch extends React.Component<CatchProps, CatchState, {}> { + + constructor(props: CatchProps) { + super(props); + this.state = {}; + this.logerr = this.logerr.bind(this); + this.reload = this.reload.bind(this); + } + + componentDidCatch(error: any, info: any) { + this.setState({ error, info }); + } + + logerr() { + const { error, info } = this.state; + console.error('[dome] Catched error:', error, info); + } + + reload() { + this.setState({ error: undefined, info: undefined }); + } + + render() { + const { error, info } = this.state; + if (error) { + const { onError, label = 'Error' } = this.props; + if (typeof (onError) === 'function') + return onError(error, info, this.reload); + else + return ( + <div> + <Button icon='WARNING' kind='warning' + title={error} + onClick={this.logerr} /> + <Button icon='RELOAD' onClick={this.reload} /> + <Label>{label}</Label> + </div> + ); + } + return this.props.children || null; + } +} + +// -------------------------------------------------------------------------- diff --git a/ivette/src/frama-c/LabViews.tsx b/ivette/src/frama-c/LabViews.tsx index 52bc3151cac0951f6f9642dee1e7ceb83b05dc6b..fe74698d0346f10153cd61714e1086a9a3027761 100644 --- a/ivette/src/frama-c/LabViews.tsx +++ b/ivette/src/frama-c/LabViews.tsx @@ -329,7 +329,7 @@ const makeGridItem = (customize: any, onClose: any) => (comp: any) => { <Vfill className="labview-content"> <Hbox className="labview-titlebar"> <Hfill> - <Catch title={id}> + <Catch label={id}> <RenderItem id={`labview.title.${id}`}> <Label className="labview-handle" label={label} title={title} /> </RenderItem> @@ -338,7 +338,7 @@ const makeGridItem = (customize: any, onClose: any) => (comp: any) => { {CLOSING} </Hbox> <TitleContext.Provider value={{ id, label, title }}> - <Catch title={id}>{children}</Catch> + <Catch label={id}>{children}</Catch> </TitleContext.Provider> </Vfill> </Grids.GridItem>