Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DH-17292 Handle disconnect from GridWidgetPlugin #2086

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion packages/dashboard-core-plugins/src/GridWidgetPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ import { type dh } from '@deephaven/jsapi-types';
import { useApi } from '@deephaven/jsapi-bootstrap';
import {
IrisGrid,
IrisGridModel,
IrisGridModelFactory,
type IrisGridModel,
} from '@deephaven/iris-grid';
import { useSelector } from 'react-redux';
import { getSettings, RootState } from '@deephaven/redux';
import { LoadingOverlay } from '@deephaven/components';
import { getErrorMessage } from '@deephaven/utils';

export function GridWidgetPlugin(
props: WidgetComponentProps<dh.Table>
): JSX.Element | null {
const dh = useApi();
const settings = useSelector(getSettings<RootState>);
const [model, setModel] = useState<IrisGridModel>();
const [error, setError] = useState<unknown>();

const { fetch } = props;

useEffect(() => {
let cancelled = false;
async function init() {
setError(undefined);
const table = await fetch();
const newModel = await IrisGridModelFactory.makeModel(dh, table);
if (!cancelled) {
Expand All @@ -36,6 +40,36 @@ export function GridWidgetPlugin(
};
}, [dh, fetch]);

useEffect(
function startListeningModel() {
if (!model) {
return;
}

// If the table inside a widget is disconnected, then don't bother trying to listen to reconnect, just close it and show a message
// Widget closes the table already when it is disconnected, so no need to close it again
function handleDisconnect() {
setError(new Error('Model disconnected'));
mofojed marked this conversation as resolved.
Show resolved Hide resolved
setModel(undefined);
}

model.addEventListener(IrisGridModel.EVENT.DISCONNECT, handleDisconnect);

return () => {
model.removeEventListener(
IrisGridModel.EVENT.DISCONNECT,
handleDisconnect
);
};
},
[model]
);

const errorMessage = getErrorMessage(error);
if (errorMessage != null) {
return <LoadingOverlay errorMessage={errorMessage} isLoading={false} />;
}

return model ? <IrisGrid model={model} settings={settings} /> : null;
}

Expand Down
Loading