forked from deephaven/deephaven-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't render objects/children of panels if there's a widget error (
deephaven#577) - In that case the children are unlikely to render correctly anyway - Have a `WidgetStatus` context that passes the widget status down - `ReactPanel` checks the context and only displays the content if there's no error with the widget - Tested with DHE branch `bender_DH-16737-vplus` against dev-vplus
- Loading branch information
Showing
14 changed files
with
509 additions
and
21,683 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
plugins/ui/src/js/src/layout/ReactPanelContentOverlayContext.tsx
This file was deleted.
Oops, something went wrong.
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,59 @@ | ||
import Log from '@deephaven/log'; | ||
import React, { Component, ReactNode } from 'react'; | ||
import WidgetErrorView from '../widget/WidgetErrorView'; | ||
|
||
const log = Log.module('ReactPanelErrorBoundary'); | ||
|
||
export interface ReactPanelErrorBoundaryProps { | ||
/** Children to catch errors from. Error will reset when the children have been updated. */ | ||
children: ReactNode; | ||
} | ||
|
||
export interface ReactPanelErrorBoundaryState { | ||
/** Currently displayed error. Reset when children are updated. */ | ||
error?: Error; | ||
} | ||
|
||
/** | ||
* Error boundary for catching render errors in React. Displays an error message until the children have updated. | ||
*/ | ||
export class ReactPanelErrorBoundary extends Component< | ||
ReactPanelErrorBoundaryProps, | ||
ReactPanelErrorBoundaryState | ||
> { | ||
static getDerivedStateFromError(error: Error): ReactPanelErrorBoundaryState { | ||
return { error }; | ||
} | ||
|
||
constructor(props: ReactPanelErrorBoundaryProps) { | ||
super(props); | ||
this.state = { error: undefined }; | ||
} | ||
|
||
componentDidUpdate( | ||
prevProps: Readonly<ReactPanelErrorBoundaryProps>, | ||
prevState: Readonly<ReactPanelErrorBoundaryState> | ||
): void { | ||
const { children } = this.props; | ||
if (prevProps.children !== children && prevState.error != null) { | ||
log.debug( | ||
'ReactPanelErrorBoundary clearing previous error', | ||
prevState.error, | ||
children | ||
); | ||
this.setState({ error: undefined }); | ||
} | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void { | ||
log.error('Error caught by ErrorBoundary', error, errorInfo); | ||
} | ||
|
||
render(): ReactNode { | ||
const { children } = this.props; | ||
const { error } = this.state; | ||
return error != null ? <WidgetErrorView error={error} /> : children; | ||
} | ||
} | ||
|
||
export default ReactPanelErrorBoundary; |
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,28 @@ | ||
import { WidgetDescriptor } from '@deephaven/dashboard'; | ||
import { createContext } from 'react'; | ||
|
||
export type WidgetStatusLoading = { | ||
status: 'loading'; | ||
descriptor: WidgetDescriptor; | ||
}; | ||
|
||
export type WidgetStatusError = { | ||
status: 'error'; | ||
descriptor: WidgetDescriptor; | ||
error: NonNullable<unknown>; | ||
}; | ||
|
||
export type WidgetStatusReady = { | ||
status: 'ready'; | ||
descriptor: WidgetDescriptor; | ||
}; | ||
|
||
export type WidgetStatus = | ||
| WidgetStatusLoading | ||
| WidgetStatusError | ||
| WidgetStatusReady; | ||
|
||
/** Status of the widget within this context */ | ||
export const WidgetStatusContext = createContext<WidgetStatus | null>(null); | ||
|
||
export default WidgetStatusContext; |
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
import { useContextOrThrow } from '@deephaven/react-hooks'; | ||
import { WidgetStatus, WidgetStatusContext } from './WidgetStatusContext'; | ||
|
||
/** | ||
* Gets the widget status from the closest WidgetStatusContext. | ||
* @returns Widget status or throws an error if WidgetStatusContext is not set | ||
*/ | ||
export function useWidgetStatus(): WidgetStatus { | ||
return useContextOrThrow(WidgetStatusContext); | ||
} | ||
|
||
export default useWidgetStatus; |
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
Oops, something went wrong.