Skip to content

Commit

Permalink
Show a warning notification on fetch token error when starting a work…
Browse files Browse the repository at this point in the history
…space
  • Loading branch information
vinokurig committed Aug 30, 2024
1 parent 4b863a8 commit e244491
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ import {
import { ProgressStepTitle } from '@/components/WorkspaceProgress/StepTitle';
import { TimeLimit } from '@/components/WorkspaceProgress/TimeLimit';
import workspaceStatusIs from '@/components/WorkspaceProgress/workspaceStatusIs';
import { lazyInject } from '@/inversify.config';
import { WorkspaceParams } from '@/Routes/routes';
import { AppAlerts } from '@/services/alerts/appAlerts';
import { findTargetWorkspace } from '@/services/helpers/factoryFlow/findTargetWorkspace';
import { AlertItem, DevWorkspaceStatus, LoaderTab } from '@/services/helpers/types';
import { Workspace, WorkspaceAdapter } from '@/services/workspace-adapter';
import { AppState } from '@/store';
import { selectApplications } from '@/store/ClusterInfo/selectors';
import { selectStartTimeout } from '@/store/ServerConfig/selectors';
import * as WorkspaceStore from '@/store/Workspaces';
import { selectDevWorkspaceWarnings } from '@/store/Workspaces/devWorkspaces/selectors';
import { selectAllWorkspaces } from '@/store/Workspaces/selectors';

export type Props = MappedProps &
Expand All @@ -47,15 +50,20 @@ export type Props = MappedProps &
export type State = ProgressStepState & {
shouldStart: boolean; // should the loader start a workspace?
shouldUpdateWithDefaultDevfile: boolean;
warning: string | undefined;
};

class StartingStepStartWorkspace extends ProgressStep<Props, State> {
protected readonly name = 'Waiting for workspace to start';

@lazyInject(AppAlerts)
private readonly appAlerts: AppAlerts;

constructor(props: Props) {
super(props);

this.state = {
warning: undefined,
shouldStart: true,
name: this.name,
shouldUpdateWithDefaultDevfile: false,
Expand Down Expand Up @@ -112,6 +120,15 @@ class StartingStepStartWorkspace extends ProgressStep<Props, State> {
return true;
}

if (
workspace !== undefined &&
nextWorkspace !== undefined &&
this.props.devWorkspaceWarnings[workspace.uid] !==
nextProps.devWorkspaceWarnings[nextWorkspace.uid]
) {
return true;
}

return false;
}

Expand All @@ -132,6 +149,15 @@ class StartingStepStartWorkspace extends ProgressStep<Props, State> {
});
}

if (workspace !== undefined) {
const warning = this.props.devWorkspaceWarnings[workspace.uid];
if (warning) {
this.setState({
warning,
});
}
}

this.prepareAndRun();
}

Expand Down Expand Up @@ -169,6 +195,15 @@ class StartingStepStartWorkspace extends ProgressStep<Props, State> {
);
}

if (this.state.warning !== undefined) {
this.appAlerts.showAlert({
key: 'start-workspace-warning',
title: `WARNING: ${this.state.warning}`,
variant: AlertVariant.warning,
});
return true;
}

if (this.state.shouldUpdateWithDefaultDevfile) {
await this.props.updateWorkspaceWithDefaultDevfile(workspace);
this.setState({ shouldUpdateWithDefaultDevfile: false });
Expand Down Expand Up @@ -298,6 +333,7 @@ const mapStateToProps = (state: AppState) => ({
allWorkspaces: selectAllWorkspaces(state),
applications: selectApplications(state),
startTimeout: selectStartTimeout(state),
devWorkspaceWarnings: selectDevWorkspaceWarnings(state),
});

const connector = connect(mapStateToProps, WorkspaceStore.actionCreators, null, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('OAuth service', () => {
try {
await OAuthService.refreshTokenIfProjectExists(devWorkspace);
} catch (e: any) {
fail('it should not reach here');
// ignore
}

expect(refreshFactoryOauthTokenSpy).toHaveBeenCalledWith('origin:project');
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('OAuth service', () => {
try {
await OAuthService.refreshTokenIfProjectExists(devWorkspace);
} catch (e: any) {
fail('it should not reach here');
// ignore
}

expect(refreshFactoryOauthTokenSpy).toHaveBeenCalledWith('origin:project');
Expand Down
4 changes: 1 addition & 3 deletions packages/dashboard-frontend/src/services/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ export class OAuthService {
response.data.attributes.oauth_authentication_url,
redirectUrl.toString(),
);
// Interrupt the workspace start. The workspace should start again after the authentication.
throw e;
}
// Skip other exceptions to proceed the workspace start.
throw e;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,16 @@ export const actionCreators: ActionCreators = {
return;
}
try {
await OAuthService.refreshTokenIfProjectExists(workspace);
try {
await OAuthService.refreshTokenIfProjectExists(workspace);
} catch (e: any) {
// Do not interrupt the workspace start, but show a warning notification.
dispatch({
type: Type.UPDATE_WARNING,
workspace: workspace,
warning: e.response.data.message,
});
}
await dispatch({ type: Type.REQUEST_DEVWORKSPACE, check: AUTHORIZED });
if (!(await selectAsyncIsAuthorized(getState()))) {
const error = selectSanityCheckError(getState());
Expand Down

0 comments on commit e244491

Please sign in to comment.