-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display deephaven.ui widget errors in a panel so user can see t…
…hem (#436) - Widget can now emit a `documentError` on the server to indicate there was an error rendering the document - Client listens for `documentError` and will display the error message in a panel along with a Reload button to reload the widget - Updated `@deephaven/*` packages to 0.76.0, which includes the `ErrorView` and is also in deephaven-core 0.34.1 - Fixes #437 - Fixes #85 - Tested with a `ui_boom` and `ui_boom_counter` components: ```python from deephaven import ui @ui.component def ui_boom(): raise Exception("BOOM!") @ui.component def ui_boom_counter(): value, set_value = ui.use_state(0) if value > 5: raise ValueError("BOOM! Value is bigger than 5.") return ui.button(f"Count is {value}", on_press=lambda: set_value(value + 1)) boom = ui_boom() boom_counter = ui_boom_counter() ```
- Loading branch information
Showing
19 changed files
with
4,212 additions
and
13,270 deletions.
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
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 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,18 @@ | ||
from enum import Enum | ||
|
||
|
||
class ErrorCode(int, Enum): | ||
""" | ||
ErrorCode is a list of error codes that can be returned by the server. | ||
""" | ||
|
||
# General errors | ||
UNKNOWN = 0 | ||
""" | ||
An unknown error occurred on the server. | ||
""" | ||
|
||
DOCUMENT_ERROR = 1 | ||
""" | ||
There was an error when rendering the document. | ||
""" |
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,12 @@ | ||
import React from 'react'; | ||
import { usePanelContentOverlay } from './usePanelContentOverlay'; | ||
|
||
/** A panel that uses the ReactPanelContentOverlayContext and if that content is set, renders it in a view with a partially transparent background */ | ||
export function ReactPanelContentOverlay(): JSX.Element | null { | ||
const overlayContent = usePanelContentOverlay(); | ||
return overlayContent != null ? ( | ||
<div className="dh-react-panel-overlay">{overlayContent}</div> | ||
) : null; | ||
} | ||
|
||
export default ReactPanelContentOverlay; |
7 changes: 7 additions & 0 deletions
7
plugins/ui/src/js/src/layout/ReactPanelContentOverlayContext.tsx
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,7 @@ | ||
import { createContext } from 'react'; | ||
|
||
/** Context that defined a ReactNode to overlay on top of the content in a ReactPanel */ | ||
export const ReactPanelContentOverlayContext = | ||
createContext<React.ReactNode | null>(null); | ||
|
||
export default ReactPanelContentOverlayContext; |
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 { useContext } from 'react'; | ||
import { ReactPanelContentOverlayContext } from './ReactPanelContentOverlayContext'; | ||
|
||
/** | ||
* Gets the overlay content from the nearest panel context. | ||
* @returns The overlay content or null if not in a panel | ||
*/ | ||
export function usePanelContentOverlay(): React.ReactNode | null { | ||
return useContext(ReactPanelContentOverlayContext); | ||
} | ||
|
||
export default usePanelContentOverlay; |
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,31 @@ | ||
import React from 'react'; | ||
import { Button, ErrorView } from '@deephaven/components'; | ||
import { vsRefresh } from '@deephaven/icons'; | ||
import { WidgetError } from './WidgetTypes'; | ||
|
||
/** Component that takes a WidgetError and displays the contents in an ErrorView, and has a button to reload the widget from a fresh state. */ | ||
function WidgetErrorView({ | ||
error, | ||
onReload: onReset, | ||
}: { | ||
error: WidgetError; | ||
onReload: () => void; | ||
}): JSX.Element { | ||
const displayMessage = `${error.message.trim()}\n\n${ | ||
error.stack ?? '' | ||
}`.trim(); | ||
return ( | ||
<div className="ui-widget-error-view"> | ||
<div className="widget-error-view-content"> | ||
<ErrorView message={displayMessage} type={error.type} isExpanded /> | ||
</div> | ||
<div className="widget-error-view-footer"> | ||
<Button kind="tertiary" icon={vsRefresh} onClick={onReset}> | ||
Reload | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default WidgetErrorView; |
Oops, something went wrong.