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: Reconnect Auth Fail Fix - embed-widget #2023

Merged
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
1 change: 1 addition & 0 deletions packages/app-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@deephaven/iris-grid": "file:../iris-grid",
"@deephaven/jsapi-bootstrap": "file:../jsapi-bootstrap",
"@deephaven/jsapi-components": "file:../jsapi-components",
"@deephaven/jsapi-shim": "file:../jsapi-shim",
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
"@deephaven/jsapi-types": "1.0.0-dev0.34.0",
"@deephaven/jsapi-utils": "file:../jsapi-utils",
"@deephaven/log": "file:../log",
Expand Down
4 changes: 2 additions & 2 deletions packages/app-utils/src/components/AppBootstrap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ it('should log in automatically when the anonymous handler is supported', async
});

expect(screen.queryByTestId('auth-base-loading')).toBeNull();
expect(screen.queryByTestId('connection-bootstrap-loading')).not.toBeNull();
expect(screen.queryByText(mockChildText)).toBeNull();
expect(screen.queryByTestId('connection-bootstrap-loading')).toBeNull();
expect(screen.queryByText(mockChildText)).not.toBeNull();
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
expect(mockChannel.postMessage).toHaveBeenCalledWith(
expect.objectContaining({
message: BROADCAST_LOGIN_MESSAGE,
Expand Down
56 changes: 44 additions & 12 deletions packages/app-utils/src/components/ConnectionBootstrap.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useState } from 'react';
import { LoadingOverlay } from '@deephaven/components';
import { BasicModal } from '@deephaven/components';
import {
ObjectFetcherContext,
sanitizeVariableDescriptor,
Expand Down Expand Up @@ -29,8 +29,10 @@ export function ConnectionBootstrap({
}: ConnectionBootstrapProps): JSX.Element {
const api = useApi();
const client = useClient();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
const [error, setError] = useState<unknown>();
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
const [connection, setConnection] = useState<dh.IdeConnection>();
const [authFailedState, setIsAuthFailedState] = useState<boolean>(false);
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
useEffect(
function initConnection() {
let isCanceled = false;
Expand Down Expand Up @@ -60,21 +62,47 @@ export function ConnectionBootstrap({
function listenForShutdown() {
if (connection == null) return;

// handles the shutdown event
function handleShutdown(event: CustomEvent): void {
const { detail } = event;
log.info('Shutdown', `${JSON.stringify(detail)}`);
setError(`Server shutdown: ${detail ?? 'Unknown reason'}`);
}

const removerFn = connection.addEventListener(
api.IdeConnection.EVENT_SHUTDOWN,
handleShutdown
);

return removerFn;
},
[api, connection]
);

useEffect(
function listenForAuthFailed() {
if (connection == null) return;
// handles the auth failed event
function handleAuthFailed(event: CustomEvent): void {
const { detail } = event;
log.warn(
'Reconnect authentication failed',
`${JSON.stringify(detail)}`
);
setError(
`Reconnect authentication failed: ${detail ?? 'Unknown reason'}`
);
setIsAuthFailedState(true);
}
const authFailed = connection.addEventListener(
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
api.CoreClient.EVENT_RECONNECT_AUTH_FAILED,
handleAuthFailed
);

return authFailed;
},
[api, connection]
);

const objectFetcher = useCallback(
async (descriptor: dh.ide.VariableDescriptor) => {
assertNotNull(connection, 'No connection available to fetch object with');
Expand All @@ -83,20 +111,24 @@ export function ConnectionBootstrap({
[connection]
);

if (connection == null || error != null) {
return (
<LoadingOverlay
data-testid="connection-bootstrap-loading"
isLoading={connection == null}
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
errorMessage={error != null ? `${error}` : undefined}
/>
);
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
function handleRefresh(): void {
log.info('Refreshing application');
window.location.reload();
}

return (
<ConnectionContext.Provider value={connection}>
<ConnectionContext.Provider value={connection ?? null}>
<ObjectFetcherContext.Provider value={objectFetcher}>
{children}
<>
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
{children}
<BasicModal
confirmButtonText="Refresh"
onConfirm={handleRefresh}
isOpen={authFailedState}
headerText="Authentication failed"
bodyText="Credentials are invalid. Please refresh your browser to try and reconnect."
/>
</>
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
</ObjectFetcherContext.Provider>
</ConnectionContext.Provider>
);
Expand Down
36 changes: 3 additions & 33 deletions packages/code-studio/src/main/AppMainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ interface AppMainContainerProps {

interface AppMainContainerState {
contextActions: ContextAction[];
isAuthFailed: boolean;
isDisconnected: boolean;
isPanelsMenuShown: boolean;
isResetLayoutPromptShown: boolean;
Expand Down Expand Up @@ -245,7 +244,6 @@ export class AppMainContainer extends Component<
isGlobal: true,
},
],
isAuthFailed: false,
isDisconnected: false,
isPanelsMenuShown: false,
isResetLayoutPromptShown: false,
Expand Down Expand Up @@ -647,11 +645,6 @@ export class AppMainContainer extends Component<
this.setState({ isDisconnected: false });
}

handleReconnectAuthFailed(): void {
log.warn('Reconnect authentication failed');
this.setState({ isAuthFailed: true });
}

/**
* 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 @@ -736,10 +729,6 @@ export class AppMainContainer extends Component<
dh.IdeConnection.EVENT_RECONNECT,
this.handleReconnect
);
connection.addEventListener(
dh.CoreClient.EVENT_RECONNECT_AUTH_FAILED,
this.handleReconnectAuthFailed
);
}

stopListeningForDisconnect(): void {
Expand All @@ -756,10 +745,6 @@ export class AppMainContainer extends Component<
dh.IdeConnection.EVENT_RECONNECT,
this.handleReconnect
);
connection.removeEventListener(
dh.CoreClient.EVENT_RECONNECT_AUTH_FAILED,
this.handleReconnectAuthFailed
);
}

/**
Expand Down Expand Up @@ -856,7 +841,6 @@ export class AppMainContainer extends Component<
const { canUsePanels } = permissions;
const {
contextActions,
isAuthFailed,
isDisconnected,
isPanelsMenuShown,
isResetLayoutPromptShown,
Expand Down Expand Up @@ -950,7 +934,7 @@ export class AppMainContainer extends Component<
icon={
<span className="fa-layers">
<FontAwesomeIcon icon={vsGear} transform="grow-3" />
{isDisconnected && !isAuthFailed && (
{isDisconnected && (
<>
<FontAwesomeIcon
icon={dhSquareFilled}
Expand All @@ -966,11 +950,7 @@ export class AppMainContainer extends Component<
)}
</span>
}
tooltip={
isDisconnected && !isAuthFailed
? 'Server disconnected'
: 'User Settings'
}
tooltip="Server disconnected"
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>
</div>
Expand Down Expand Up @@ -1015,10 +995,7 @@ export class AppMainContainer extends Component<
onChange={this.handleImportLayoutFiles}
data-testid="input-import-layout"
/>
<DebouncedModal
isOpen={isDisconnected && !isAuthFailed}
debounceMs={1000}
>
<DebouncedModal isOpen={isDisconnected} debounceMs={1000}>
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
<InfoModal
icon={vsDebugDisconnect}
title={
Expand Down Expand Up @@ -1046,13 +1023,6 @@ export class AppMainContainer extends Component<
: 'Do you want to reset your layout? Any unsaved notebooks will be lost.'
}
/>
<BasicModal
confirmButtonText="Refresh"
onConfirm={AppMainContainer.handleRefresh}
isOpen={isAuthFailed}
headerText="Authentication failed"
bodyText="Credentials are invalid. Please refresh your browser to try and reconnect."
/>
</div>
);
}
Expand Down
14 changes: 0 additions & 14 deletions packages/embed-widget/src/index.scss

This file was deleted.

1 change: 0 additions & 1 deletion packages/embed-widget/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { store } from '@deephaven/redux';
import '@deephaven/components/scss/BaseStyleSheet.scss';
import { LoadingOverlay, preloadTheme } from '@deephaven/components';
import { ApiBootstrap } from '@deephaven/jsapi-bootstrap';
import './index.scss';
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved

preloadTheme();

Expand Down
3 changes: 2 additions & 1 deletion tests/notebook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { pasteInMonaco } from './utils';
test.describe.configure({ mode: 'serial' });

test('test creating a file, saving it, reloading the page, closing it, re-opening it, running it, then deleting it', async ({
page, browserName
page,
browserName,
}) => {
await page.goto('');

Expand Down
Loading