Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
olexii4 committed Aug 29, 2023
1 parent 5a7a22e commit 5946753
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ describe('Common steps, check running workspaces limit', () => {
title: 'Restart',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Debug mode',
callback: expect.any(Function),
}),
],
});
await waitFor(() => expect(mockOnError).toHaveBeenCalledWith(expectAlertItem));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,6 @@ class CommonStepCheckRunningWorkspacesLimit extends ProgressStep<Props, State> {
title: 'Restart',
callback: () => this.handleRestart(key),
},
{
title: 'Restart in Debug mode',
callback: () => this.handleRestart(key, LoaderTab.Logs),
},
],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('Creating steps, applying a devfile', () => {
children: 'Failed to resolve the devfile.',
actionCallbacks: [
expect.objectContaining({
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
Expand Down Expand Up @@ -224,6 +224,7 @@ describe('Creating steps, applying a devfile', () => {
expect(prepareDevfile).toHaveBeenCalledWith(
expect.objectContaining({
attributes: {
'controller.devfile.io/storage-type': 'ephemeral',
defaultDevfile: true,
},
}),
Expand Down Expand Up @@ -303,6 +304,7 @@ describe('Creating steps, applying a devfile', () => {
expect(prepareDevfile).toHaveBeenCalledWith(
expect.objectContaining({
attributes: {
'controller.devfile.io/storage-type': 'ephemeral',
defaultDevfile: true,
},
}),
Expand Down Expand Up @@ -448,7 +450,7 @@ describe('Creating steps, applying a devfile', () => {
),
actionCallbacks: [
expect.objectContaining({
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
Expand Down Expand Up @@ -506,11 +508,11 @@ describe('Creating steps, applying a devfile', () => {
await waitFor(() => expect(mockCreateWorkspaceFromDevfile).toHaveBeenCalledTimes(2));
});

test('action callback to continue with the default devfile', async () => {
test('action callback to continue with default devfile', async () => {
// this deferred object will help run the callback at the right time
const deferred = getDefer();

const continueActionTitle = 'Continue with the default devfile';
const continueActionTitle = 'Continue with default devfile';
mockOnError.mockImplementationOnce(async (alertItem: AlertItem) => {
const continueAction = alertItem.actionCallbacks?.find(action =>
action.title.startsWith(continueActionTitle),
Expand Down Expand Up @@ -573,7 +575,7 @@ describe('Creating steps, applying a devfile', () => {
children: `Workspace hasn't been created in the last 20 seconds.`,
actionCallbacks: [
expect.objectContaining({
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { TimeLimit } from '../../../TimeLimit';
import { configureProjectRemotes } from './getGitRemotes';
import { getProjectFromLocation } from './getProjectFromLocation';
import { prepareDevfile } from './prepareDevfile';
import { DEVWORKSPACE_STORAGE_TYPE_ATTR } from '../../../../../services/devfileApi/devWorkspace/spec/template';

export class CreateWorkspaceError extends Error {
constructor(message: string) {
Expand Down Expand Up @@ -232,13 +233,19 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
}

// factory resolving failed in the previous step
// hence we have to proceed with the default devfile
// hence we have to proceed with default devfile
if (factoryResolver === undefined) {
if (devfile === undefined) {
if (defaultDevfile === undefined) {
throw new Error('Failed to resolve the default devfile.');
}
this.updateCurrentDevfile(defaultDevfile);
const _devfile = cloneDeep(defaultDevfile);
// sets ephemeral storage type
if (!_devfile.attributes) {
_devfile.attributes = {};
}
_devfile.attributes[DEVWORKSPACE_STORAGE_TYPE_ATTR] = 'ephemeral';
this.updateCurrentDevfile(_devfile);
} else {
try {
await this.createWorkspaceFromDevfile(devfile);
Expand All @@ -251,7 +258,7 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
}

// the user devfile is invalid and caused creation error
// so we have to proceed with the default devfile
// so we have to proceed with default devfile
if (continueWithDefaultDevfile === true) {
if (defaultDevfile === undefined) {
throw new Error('Failed to resolve the default devfile.');
Expand All @@ -260,6 +267,12 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
if (devfile === undefined) {
const _devfile = cloneDeep(defaultDevfile);

// sets ephemeral storage type
if (!_devfile.attributes) {
_devfile.attributes = {};
}
_devfile.attributes[DEVWORKSPACE_STORAGE_TYPE_ATTR] = 'ephemeral';

if (factoryResolverConverted?.devfileV2 !== undefined) {
const { metadata, projects } = factoryResolverConverted.devfileV2;
_devfile.projects = projects;
Expand All @@ -271,7 +284,7 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
return false;
}

// proceed with the default devfile
// proceed with default devfile
try {
await this.createWorkspaceFromDevfile(devfile);
} catch (e) {
Expand Down Expand Up @@ -375,7 +388,7 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
),
actionCallbacks: [
{
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: () => this.handleContinueWithDefaultDevfile(key),
},
{
Expand All @@ -392,7 +405,7 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
children: helpers.errors.getMessage(error),
actionCallbacks: [
{
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: () => this.handleContinueWithDefaultDevfile(key),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('Creating steps, fetching a devfile', () => {
),
actionCallbacks: [
expect.objectContaining({
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
Expand All @@ -163,11 +163,11 @@ describe('Creating steps, fetching a devfile', () => {
expect(mockOnRestart).not.toHaveBeenCalled();
});

test('action callback to continue with the default devfile"', async () => {
test('action callback to continue with default devfile"', async () => {
// this deferred object will help run the callback at the right time
const deferred = getDefer();

const actionTitle = 'Continue with the default devfile';
const actionTitle = 'Continue with default devfile';
mockOnError.mockImplementationOnce((alertItem: AlertItem) => {
const action = alertItem.actionCallbacks?.find(action =>
action.title.startsWith(actionTitle),
Expand Down Expand Up @@ -266,7 +266,7 @@ describe('Creating steps, fetching a devfile', () => {
children: `Devfile hasn't been resolved in the last ${TIMEOUT_TO_RESOLVE_SEC} seconds.`,
actionCallbacks: [
expect.objectContaining({
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('Creating steps, fetching a devfile', () => {
title: 'Warning',
actionCallbacks: [
expect.objectContaining({
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
Expand All @@ -356,11 +356,11 @@ describe('Creating steps, fetching a devfile', () => {
expect(mockOnNextStep).not.toHaveBeenCalled();
});

test('action "Continue with the default devfile"', async () => {
test('action "Continue with default devfile"', async () => {
// this deferred object will help run the callback at the right time
const deferred = getDefer();

const actionTitle = 'Continue with the default devfile';
const actionTitle = 'Continue with default devfile';
mockOnError.mockImplementationOnce((alertItem: AlertItem) => {
const action = alertItem.actionCallbacks?.find(_action =>
_action.title.startsWith(actionTitle),
Expand Down Expand Up @@ -595,7 +595,7 @@ describe('Creating steps, fetching a devfile', () => {
'The Dashboard reached a limit of reloads while trying to resolve a devfile in a private repo. Please contact admin to check if OAuth is configured correctly.',
actionCallbacks: [
expect.objectContaining({
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
),
actionCallbacks: [
{
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: () => this.handleDefaultDevfile(key),
},
{
Expand All @@ -354,7 +354,7 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
),
actionCallbacks: [
{
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: () => this.handleDefaultDevfile(key),
},
{
Expand All @@ -371,7 +371,7 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
children: helpers.errors.getMessage(error),
actionCallbacks: [
{
title: 'Continue with the default devfile',
title: 'Continue with default devfile',
callback: () => this.handleDefaultDevfile(key),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ describe('Starting steps, initializing', () => {
title: 'Restart',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Debug mode',
callback: expect.any(Function),
}),
],
});
await waitFor(() => expect(mockOnError).toHaveBeenCalledWith(expectAlertItem));
Expand Down Expand Up @@ -300,10 +296,6 @@ describe('Starting steps, initializing', () => {
title: 'Restart',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Debug mode',
callback: expect.any(Function),
}),
],
});
await waitFor(() => expect(mockOnError).toHaveBeenCalledWith(expectAlertItem));
Expand Down Expand Up @@ -401,10 +393,6 @@ describe('Starting steps, initializing', () => {
title: 'Restart',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Debug mode',
callback: expect.any(Function),
}),
],
});
await waitFor(() => expect(mockOnError).toHaveBeenCalledWith(expectAlertItem));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ class StartingStepInitialize extends ProgressStep<Props, State> {
title: 'Restart',
callback: () => this.handleRestart(key, LoaderTab.Progress),
},
{
title: 'Restart in Debug mode',
callback: () => this.handleRestart(key, LoaderTab.Logs),
},
],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ describe('Starting steps, opening an editor', () => {
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Safe mode',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Debug mode',
title: 'Restart with default devfile',
callback: expect.any(Function),
}),
],
Expand Down Expand Up @@ -179,11 +175,7 @@ describe('Starting steps, opening an editor', () => {
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Safe mode',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Debug mode',
title: 'Restart with default devfile',
callback: expect.any(Function),
}),
],
Expand Down Expand Up @@ -364,11 +356,7 @@ describe('Starting steps, opening an editor', () => {
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Safe mode',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Restart in Debug mode',
title: 'Restart with default devfile',
callback: expect.any(Function),
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { ProgressStepTitle } from '../../StepTitle';
import { TimeLimit } from '../../TimeLimit';
import {
applyRestartDefaultLocation,
applyRestartInDebugModeLocation,
applyRestartInSafeModeLocation,
} from '../StartWorkspace/prepareRestart';

Expand Down Expand Up @@ -169,19 +168,12 @@ class StartingStepOpenWorkspace extends ProgressStep<Props, State> {
},
},
{
title: 'Restart in Safe mode',
title: 'Restart with default devfile',
callback: () => {
applyRestartInSafeModeLocation(this.props.history.location);
this.handleRestart(key, LoaderTab.Progress);
},
},
{
title: 'Restart in Debug mode',
callback: () => {
applyRestartInDebugModeLocation(this.props.history.location);
this.handleRestart(key, LoaderTab.Logs);
},
},
],
};
}
Expand Down
Loading

0 comments on commit 5946753

Please sign in to comment.