-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loads the widget and displays it if there is a widget plugin that matches - Displays an error if no plugin is found that can display the type of widget, or a widget with that name is not found - Fixes #1629 Tested by installing the matplotlib, plotly-express python plugins, but only installing the plotly-express JS plugin (not the matplotlib JS plugin). Then ran the following snippet: ```python from deephaven.column import int_col, string_col from deephaven.plot import Figure, express as dx from deephaven import new_table import matplotlib.pyplot as plt t = new_table([ string_col("Categories", ["A", "B", "C"]), int_col("Values", [1, 3, 5]), ]) t_rollup = t.rollup(aggs=[], by=["Categories"], include_constituents=True) fig = Figure().plot_cat(series_name="Test", t=t, category="Categories", y="Values").show() dx_fig = dx.bar(table=t, x="Categories", y="Values") import matplotlib.pyplot as plt mpl_fig = plt.figure() ax = mpl_fig.subplots() ax.plot([1, 2, 3, 4], [4, 2, 6, 7]) ``` Then opened up pages to the following URLs to make sure the appeared correctly: 1. http://localhost:4030/?name=t - Table displayed correctly 2. http://localhost:4030/?name=t_rollup - Tree Table displayed correctly 3. http://localhost:4030/?name=fig - Deephaven Figure displayed correctly 4. http://localhost:4030/?name=dx_fig - Plotly-express figure displayed correctly 5. http://localhost:4030/?name=mpl_fig - Error displayed correctly about unknown type 6. http://localhost:4030/?name=err - Timeout error displayed 7. http://localhost:4030/ - Error saying no name provided --------- Co-authored-by: Matthew Runyon <mattrunyonstuff@gmail.com>
- Loading branch information
1 parent
bdc764e
commit 1b06675
Showing
47 changed files
with
700 additions
and
164 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,39 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import ErrorBoundary, { ErrorBoundaryProps } from './ErrorBoundary'; | ||
|
||
function ThrowComponent(): JSX.Element { | ||
throw new Error('Test error'); | ||
} | ||
|
||
function makeWrapper({ | ||
children = 'Hello World', | ||
className, | ||
onError = jest.fn(), | ||
fallback, | ||
}: Partial<ErrorBoundaryProps> = {}) { | ||
return render( | ||
<ErrorBoundary className={className} fallback={fallback} onError={onError}> | ||
{children} | ||
</ErrorBoundary> | ||
); | ||
} | ||
|
||
it('should render the children if there is no error', () => { | ||
const onError = jest.fn(); | ||
const { getByText } = makeWrapper({ onError }); | ||
expect(getByText('Hello World')).toBeInTheDocument(); | ||
expect(onError).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render the fallback if there is an error', () => { | ||
const onError = jest.fn(); | ||
const error = new Error('Test error'); | ||
const { getByText } = makeWrapper({ | ||
children: <ThrowComponent />, | ||
fallback: <div>Fallback</div>, | ||
onError, | ||
}); | ||
expect(getByText('Fallback')).toBeInTheDocument(); | ||
expect(onError).toHaveBeenCalledWith(error, expect.anything()); | ||
}); |
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,70 @@ | ||
import Log from '@deephaven/log'; | ||
import React, { Component, ReactNode } from 'react'; | ||
import LoadingOverlay from './LoadingOverlay'; | ||
|
||
const log = Log.module('ErrorBoundary'); | ||
|
||
export interface ErrorBoundaryProps { | ||
/** Children to catch errors from */ | ||
children: ReactNode; | ||
|
||
/** Classname to wrap the error message with */ | ||
className?: string; | ||
|
||
/** Callback for when an error occurs */ | ||
onError?: (error: Error, errorInfo: React.ErrorInfo) => void; | ||
|
||
/** Custom fallback element */ | ||
fallback?: ReactNode; | ||
} | ||
|
||
export interface ErrorBoundaryState { | ||
error?: Error; | ||
} | ||
|
||
/** | ||
* Error boundary for catching render errors in React. Displays an error message if an error is caught by default, or you can specify a fallback component to render. | ||
* https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary | ||
*/ | ||
export class ErrorBoundary extends Component< | ||
ErrorBoundaryProps, | ||
ErrorBoundaryState | ||
> { | ||
static getDerivedStateFromError(error: Error): ErrorBoundaryState { | ||
return { error }; | ||
} | ||
|
||
constructor(props: ErrorBoundaryProps) { | ||
super(props); | ||
this.state = { error: undefined }; | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void { | ||
const { onError } = this.props; | ||
log.error('Error caught by ErrorBoundary', error, errorInfo); | ||
onError?.(error, errorInfo); | ||
} | ||
|
||
render(): ReactNode { | ||
const { children, className, fallback } = this.props; | ||
const { error } = this.state; | ||
if (error != null) { | ||
if (fallback != null) { | ||
return fallback; | ||
} | ||
|
||
return ( | ||
<div className={className}> | ||
<LoadingOverlay | ||
errorMessage={`${error}`} | ||
isLoading={false} | ||
isLoaded={false} | ||
/> | ||
</div> | ||
); | ||
} | ||
return children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
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
Oops, something went wrong.