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

feat: JS API reconnect #1149

Merged
merged 7 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
3 changes: 3 additions & 0 deletions __mocks__/dh-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,9 @@ class IdeConnection extends DeephavenObject {
}
}

IdeConnection.EVENT_DISCONNECT = 'disconnect';
IdeConnection.EVENT_RECONNECT = 'reconnect';

class IdeSession extends DeephavenObject {
constructor(language) {
super();
Expand Down
22 changes: 13 additions & 9 deletions packages/code-studio/src/main/AppInit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ function AppInit(props: AppInitProps) {
setServerConfigValues,
} = props;

// General error means the app is dead and is unlikely to recover
const [error, setError] = useState<unknown>();
// Disconnect error may be temporary, so just show an error overlaid on the app
const [disconnectError, setDisconnectError] = useState<unknown>();
const [isFontLoading, setIsFontLoading] = useState(true);

const initClient = useCallback(async () => {
Expand All @@ -175,14 +178,12 @@ function AppInit(props: AppInitProps) {
? // Fall back to the old API for anonymous auth if the new API is not supported
createConnection()
: coreClient.getAsIdeConnection());
connection.addEventListener(
dh.IdeConnection.HACK_CONNECTION_FAILURE,
event => {
const { detail } = event;
log.error('Connection failure', `${JSON.stringify(detail)}`);
setError(`Unable to connect: ${detail.details ?? 'Unknown Error'}`);
}
);
connection.addEventListener(dh.IdeConnection.EVENT_SHUTDOWN, event => {
const { detail } = event;
log.info('Shutdown', `${JSON.stringify(detail)}`);
setError(`Server shutdown: ${detail ?? 'Unknown reason'}`);
setDisconnectError(null);
});

const sessionWrapper = await loadSessionWrapper(connection);
const name = 'user';
Expand Down Expand Up @@ -318,7 +319,10 @@ function AppInit(props: AppInitProps) {

const isLoading = (workspace == null && error == null) || isFontLoading;
const isLoaded = !isLoading && error == null;
const errorMessage = error != null ? `${error}` : null;
const errorMessage =
error != null || disconnectError != null
? `${error ?? disconnectError}`
: null;

return (
<>
Expand Down
58 changes: 57 additions & 1 deletion packages/code-studio/src/main/AppMainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
Popper,
ContextAction,
Button,
InfoModal,
LoadingSpinner,
} from '@deephaven/components';
import {
IrisGridModel,
Expand Down Expand Up @@ -60,7 +62,12 @@ import {
SessionConfig,
getDashboardConnection,
} from '@deephaven/dashboard-core-plugins';
import { vsGear, dhShapes, dhPanels } from '@deephaven/icons';
import {
vsGear,
dhShapes,
dhPanels,
vsDebugDisconnect,
} from '@deephaven/icons';
import dh, {
IdeConnection,
IdeSession,
Expand Down Expand Up @@ -149,6 +156,7 @@ interface AppMainContainerProps {

interface AppMainContainerState {
contextActions: ContextAction[];
isDisconnected: boolean;
isPanelsMenuShown: boolean;
isSettingsMenuShown: boolean;
widgets: VariableDefinition[];
Expand Down Expand Up @@ -203,6 +211,8 @@ export class AppMainContainer extends Component<
this.hydratePandas = this.hydratePandas.bind(this);
this.hydrateDefault = this.hydrateDefault.bind(this);
this.openNotebookFromURL = this.openNotebookFromURL.bind(this);
this.handleDisconnect = this.handleDisconnect.bind(this);
this.handleReconnect = this.handleReconnect.bind(this);

this.importElement = React.createRef();

Expand Down Expand Up @@ -232,6 +242,7 @@ export class AppMainContainer extends Component<
isGlobal: true,
},
],
isDisconnected: false,
isPanelsMenuShown: false,
isSettingsMenuShown: false,
widgets: [],
Expand All @@ -240,6 +251,7 @@ export class AppMainContainer extends Component<

componentDidMount(): void {
this.initWidgets();
this.startListeningForDisconnect();

window.addEventListener(
'beforeunload',
Expand All @@ -256,6 +268,7 @@ export class AppMainContainer extends Component<

componentWillUnmount(): void {
this.deinitWidgets();
this.stopListeningForDisconnect();

window.removeEventListener(
'beforeunload',
Expand Down Expand Up @@ -534,6 +547,14 @@ export class AppMainContainer extends Component<
}
}

handleDisconnect() {
this.setState({ isDisconnected: true });
}

handleReconnect() {
this.setState({ isDisconnected: false });
}

/**
* Import the provided file and set it in the workspace data (which should then load it in the dashboard)
* @param file JSON file to import
Expand Down Expand Up @@ -630,6 +651,30 @@ export class AppMainContainer extends Component<
return PluginUtils.loadComponentPlugin(pluginName);
}

startListeningForDisconnect() {
const { connection } = this.props;
connection.addEventListener(
dh.IdeConnection.EVENT_DISCONNECT,
this.handleDisconnect
);
connection.addEventListener(
dh.IdeConnection.EVENT_RECONNECT,
this.handleReconnect
);
}

stopListeningForDisconnect() {
const { connection } = this.props;
connection.removeEventListener(
dh.IdeConnection.EVENT_DISCONNECT,
this.handleDisconnect
);
connection.removeEventListener(
dh.IdeConnection.EVENT_RECONNECT,
this.handleReconnect
);
}

hydrateDefault(
props: {
metadata?: { type?: VariableTypeUnion; id?: string; name?: string };
Expand Down Expand Up @@ -743,6 +788,7 @@ export class AppMainContainer extends Component<
const { canUsePanels } = permissions;
const {
contextActions,
isDisconnected,
isPanelsMenuShown,
isSettingsMenuShown,
widgets,
Expand Down Expand Up @@ -882,6 +928,16 @@ export class AppMainContainer extends Component<
style={{ display: 'none' }}
onChange={this.handleImportLayoutFiles}
/>
<InfoModal
isOpen={isDisconnected}
icon={vsDebugDisconnect}
title={
<>
<LoadingSpinner /> Attempting to reconnect...
</>
}
subtitle="Please check your network connection."
/>
</div>
);
}
Expand Down
27 changes: 27 additions & 0 deletions packages/components/src/modal/InfoModal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@import '../../scss/custom.scss';

$info-modal-icon-font-size: 120px;
$info-modal-message-header: 24px;
$info-modal-padding-bottom: 18px;

.info-modal {
text-align: center;
padding-bottom: $info-modal-padding-bottom;
.message-icon {
font-size: $info-modal-icon-font-size;
text-align: center;
line-height: 1;
.svg-inline--fa {
font-size: inherit;
}
}
.message-header {
font-size: $info-modal-message-header;
.svg-inline--fa {
font-size: inherit;
}
}
.message-content {
font-style: italic;
}
}
42 changes: 42 additions & 0 deletions packages/components/src/modal/InfoModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { IconProp } from '@fortawesome/fontawesome-svg-core';
import Modal from './Modal';
import ModalBody from './ModalBody';
import './InfoModal.scss';

type InfoModalProps = {
className?: string;
icon?: IconProp;
title: React.ReactNode;
subtitle?: React.ReactNode;
isOpen: boolean;
};

function InfoModal({
className,
icon,
isOpen,
subtitle,
title,
}: InfoModalProps): JSX.Element {
return (
<Modal isOpen={isOpen} className={className}>
<ModalBody>
<div className="info-modal">
{icon != null && (
<div className="message-icon">
<FontAwesomeIcon icon={icon} />
</div>
)}
<div className="message-header">{title}</div>
{subtitle != null && (
<div className="message-content">{subtitle}</div>
)}
</div>
</ModalBody>
</Modal>
);
}

export default InfoModal;
1 change: 1 addition & 0 deletions packages/components/src/modal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as InfoModal } from './InfoModal';
export { default as Modal } from './Modal';
export { default as ModalBody } from './ModalBody';
export { default as ModalHeader } from './ModalHeader';
Expand Down
17 changes: 17 additions & 0 deletions packages/dashboard-core-plugins/src/panels/ConsolePanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@
.error-message pre {
color: $danger;
}

.iris-panel-console {
&.disconnected {
.console-history-result-in-progress {
display: none;
}
.csv-overlay {
display: none;
}
.csv-input-bar {
display: none;
}
.console-input-wrapper {
display: none;
}
}
}
Loading