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

Provide links to [stop/go to] running workspace when trying to start a workspace when workspace limit reached #607

Merged
merged 7 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* Red Hat, Inc. - initial API and implementation
*/

import common from '@eclipse-che/common';
import React from 'react';
import { Cancellation, pseudoCancellable } from 'real-cancellable-promise';
import { List, LoaderStep } from '../../components/Loader/Step';
Expand All @@ -24,8 +23,9 @@ export type LoaderStepProps = {
onRestart: () => void;
};
export type LoaderStepState = {
lastError?: string;
lastError?: unknown;
};

export abstract class AbstractLoaderStep<
P extends LoaderStepProps,
S extends LoaderStepState,
Expand Down Expand Up @@ -61,9 +61,8 @@ export abstract class AbstractLoaderStep<
const currentStep = loaderSteps.get(currentStepIndex).value;

currentStep.hasError = true;
const lastError = common.helpers.errors.getMessage(e);
this.setState({
lastError,
lastError: e,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import * as WorkspacesStore from '../../../../../store/Workspaces';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
Expand Down Expand Up @@ -84,7 +86,7 @@ class StepApplyDevfile extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError !== nextState.lastError) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -142,7 +144,10 @@ class StepApplyDevfile extends AbstractLoaderStep<Props, State> {
}

if (shouldCreate === false) {
throw new Error(this.state.lastError || 'The workspace creation unexpectedly failed.');
if (this.state.lastError instanceof Error) {
throw this.state.lastError;
}
throw new Error('The workspace creation unexpectedly failed.');
}

const devfile = factoryResolverConverted?.devfileV2;
Expand Down Expand Up @@ -211,7 +216,7 @@ class StepApplyDevfile extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-' + getRandomString(4),
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import * as FactoryResolverStore from '../../../../../store/FactoryResolver';
import * as WorkspacesStore from '../../../../../store/Workspaces';
Expand Down Expand Up @@ -91,7 +93,7 @@ class StepApplyResources extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError !== nextState.lastError) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -149,7 +151,10 @@ class StepApplyResources extends AbstractLoaderStep<Props, State> {
}

if (shouldCreate === false) {
throw new Error(this.state.lastError || 'The workspace creation unexpectedly failed.');
if (this.state.lastError instanceof Error) {
throw this.state.lastError;
}
throw new Error('The workspace creation unexpectedly failed.');
}

const resources = devWorkspaceResources[sourceUrl]?.resources;
Expand Down Expand Up @@ -210,7 +215,7 @@ class StepApplyResources extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-' + getRandomString(4),
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import React from 'react';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import { delay } from '../../../../../services/helpers/delay';
import { FactoryLoaderPage } from '../../../../../pages/Loader/Factory';
Expand Down Expand Up @@ -71,7 +72,7 @@ export default class StepCreateWorkspace extends AbstractLoaderStep<Props, State
key: 'factory-loader-' + getRandomString(4),
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import common from '@eclipse-che/common';
import { isEqual } from 'lodash';
import { helpers } from '@eclipse-che/common';
import { AlertVariant } from '@patternfly/react-core';
import { AppState } from '../../../../../store';
import * as FactoryResolverStore from '../../../../../store/FactoryResolver';
Expand Down Expand Up @@ -96,7 +97,7 @@ class StepFetchDevfile extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError !== nextState.lastError) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -170,7 +171,10 @@ class StepFetchDevfile extends AbstractLoaderStep<Props, State> {
}

if (shouldResolve === false) {
throw new Error(this.state.lastError || 'Failed to resolve the devfile.');
if (this.state.lastError instanceof Error) {
throw this.state.lastError;
}
throw new Error('Failed to resolve the devfile.');
}

// start resolving the devfile
Expand Down Expand Up @@ -243,7 +247,7 @@ class StepFetchDevfile extends AbstractLoaderStep<Props, State> {
oauthUrlTmp.toString() + '&redirect_after_login=' + redirectUrl.toString();
window.location.href = fullOauthUrl;
} catch (e) {
throw new Error(`Failed to open authentication page. ${common.helpers.errors.getMessage(e)}`);
throw new Error(`Failed to open authentication page. ${helpers.errors.getMessage(e)}`);
}
}

Expand Down Expand Up @@ -314,7 +318,7 @@ class StepFetchDevfile extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-fetch-devfile',
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import * as DevfileRegistriesStore from '../../../../../store/DevfileRegistries';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
Expand Down Expand Up @@ -84,7 +86,7 @@ class StepFetchResources extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError !== nextState.lastError) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -146,7 +148,10 @@ class StepFetchResources extends AbstractLoaderStep<Props, State> {
}

if (shouldResolve === false) {
throw new Error(lastError || 'Failed to fetch pre-built resources');
if (lastError instanceof Error) {
throw lastError;
}
throw new Error('Failed to fetch pre-built resources');
}

await this.props.requestResources(sourceUrl);
Expand Down Expand Up @@ -186,7 +191,7 @@ class StepFetchResources extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-fetch-resources',
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { generatePath } from 'react-router-dom';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import { selectInfrastructureNamespaces } from '../../../../../store/InfrastructureNamespaces/selectors';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
Expand Down Expand Up @@ -60,7 +62,7 @@ class StepInitialize extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError !== nextState.lastError) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -136,7 +138,7 @@ class StepInitialize extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-initialize',
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import { selectAllWorkspaces } from '../../../../../store/Workspaces/selectors';
import * as WorkspaceStore from '../../../../../store/Workspaces';
import { WorkspaceLoaderPage } from '../../../../../pages/Loader/Workspace';
import WorkspaceLoaderPage from '../../../../../pages/Loader/Workspace';
import { Workspace } from '../../../../../services/workspace-adapter';
import { DevWorkspaceStatus } from '../../../../../services/helpers/types';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
Expand Down Expand Up @@ -69,7 +71,7 @@ class StepInitialize extends AbstractLoaderStep<Props, State> {
return true;
}
// set the error for the current step
if (this.state.lastError !== nextState.lastError) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}
return false;
Expand Down Expand Up @@ -161,9 +163,9 @@ class StepInitialize extends AbstractLoaderStep<Props, State> {
key: 'ide-loader-initialize',
title: 'Failed to open the workspace',
variant: AlertVariant.danger,
children: lastError,
children: helpers.errors.getMessage(lastError),
error: lastError,
};

return (
<WorkspaceLoaderPage
alertItem={alertItem}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import common from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import { selectAllWorkspaces } from '../../../../../store/Workspaces/selectors';
import * as WorkspaceStore from '../../../../../store/Workspaces';
import { WorkspaceLoaderPage } from '../../../../../pages/Loader/Workspace';
import WorkspaceLoaderPage from '../../../../../pages/Loader/Workspace';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import { delay } from '../../../../../services/helpers/delay';
import { MIN_STEP_DURATION_MS, TIMEOUT_TO_GET_URL_SEC } from '../../../const';
Expand Down Expand Up @@ -69,7 +71,7 @@ class StepOpenWorkspace extends AbstractLoaderStep<Props, State> {
return true;
}
// set the error for the current step
if (this.state.lastError !== nextState.lastError) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}
return false;
Expand Down Expand Up @@ -147,7 +149,7 @@ class StepOpenWorkspace extends AbstractLoaderStep<Props, State> {
key: 'ide-loader-open-ide',
title: 'Failed to open the workspace',
variant: AlertVariant.danger,
children: lastError,
children: common.helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { AlertVariant } from '@patternfly/react-core';
import common from '@eclipse-che/common';
import { isEqual } from 'lodash';
import { AppState } from '../../../../../store';
import { selectAllWorkspaces, selectLogs } from '../../../../../store/Workspaces/selectors';
import * as WorkspaceStore from '../../../../../store/Workspaces';
import { WorkspaceLoaderPage } from '../../../../../pages/Loader/Workspace';
import WorkspaceLoaderPage from '../../../../../pages/Loader/Workspace';
import { DevWorkspaceStatus } from '../../../../../services/helpers/types';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import { delay } from '../../../../../services/helpers/delay';
Expand Down Expand Up @@ -77,7 +78,7 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
return true;
}
// set the error for the current step
if (this.state.lastError !== nextState.lastError) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}
return false;
Expand Down Expand Up @@ -165,14 +166,9 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
this.state.shouldStart &&
workspaceStatusIs(workspace, DevWorkspaceStatus.STOPPED, DevWorkspaceStatus.FAILED)
) {
try {
await this.props.startWorkspace(workspace);

// do not switch to the next step
return false;
} catch (e) {
throw new Error(common.helpers.errors.getMessage(e));
}
await this.props.startWorkspace(workspace);
// do not switch to the next step
return false;
}

// switch to the next step
Expand All @@ -198,7 +194,8 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
key: 'ide-loader-start-workspace',
title: 'Failed to open the workspace',
variant: AlertVariant.danger,
children: lastError,
children: common.helpers.errors.getMessage(lastError),
error: lastError,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import React from 'react';
import { Props, State } from '..';

export class WorkspaceLoaderPage extends React.PureComponent<Props, State> {
export default class WorkspaceLoaderPage extends React.PureComponent<Props, State> {
render(): React.ReactNode {
const { alertItem, currentStepId, steps, onRestart } = this.props;
const wizardSteps = steps.map(step => (
Expand Down
Loading