Skip to content

Commit

Permalink
fix: Code refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Aug 2, 2023
1 parent bd384a3 commit 9edb086
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { ToggleBarsContext } from '../../../../contexts/ToggleBars';
import { WorkspaceParams } from '../../../../Routes/routes';
import { delay } from '../../../../services/helpers/delay';
import { DisposableCollection } from '../../../../services/helpers/disposable';
import { findTargetWorkspace } from '../../../../services/helpers/factoryFlow/findTargetWorkspace';
import { buildHomeLocation, buildIdeLoaderLocation } from '../../../../services/helpers/location';
import { AlertItem, DevWorkspaceStatus, LoaderTab } from '../../../../services/helpers/types';
Expand All @@ -33,7 +31,7 @@ import {
selectAllWorkspaces,
selectRunningWorkspaces,
} from '../../../../store/Workspaces/selectors';
import { MIN_STEP_DURATION_MS, TIMEOUT_TO_STOP_SEC } from '../../const';
import { TIMEOUT_TO_STOP_SEC } from '../../const';
import { ProgressStep, ProgressStepProps, ProgressStepState } from '../../ProgressStep';
import { ProgressStepTitle } from '../../StepTitle';
import { TimeLimit } from '../../TimeLimit';
Expand All @@ -53,8 +51,6 @@ class CommonStepCheckRunningWorkspacesLimit extends ProgressStep<Props, State> {
static contextType = ToggleBarsContext;
readonly context: React.ContextType<typeof ToggleBarsContext>;

protected readonly toDispose = new DisposableCollection();

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

Expand All @@ -69,8 +65,6 @@ class CommonStepCheckRunningWorkspacesLimit extends ProgressStep<Props, State> {
}

public async componentDidUpdate() {
this.toDispose.dispose();

this.init();
}

Expand Down Expand Up @@ -130,8 +124,6 @@ class CommonStepCheckRunningWorkspacesLimit extends ProgressStep<Props, State> {
* The resolved boolean indicates whether to go to the next step or not
*/
protected async runStep(): Promise<boolean> {
await delay(MIN_STEP_DURATION_MS);

const { runningWorkspacesLimit } = this.props;
const { shouldStop, redundantWorkspaceUID } = this.state;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import isEqual from 'lodash/isEqual';
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import devfileApi from '../../../../../services/devfileApi';
import { delay } from '../../../../../services/helpers/delay';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import {
buildFactoryParams,
FactoryParams,
Expand All @@ -38,7 +36,7 @@ import * as WorkspacesStore from '../../../../../store/Workspaces';
import { selectDevWorkspaceWarnings } from '../../../../../store/Workspaces/devWorkspaces/selectors';
import { selectAllWorkspaces } from '../../../../../store/Workspaces/selectors';
import ExpandableWarning from '../../../../ExpandableWarning';
import { MIN_STEP_DURATION_MS, TIMEOUT_TO_CREATE_SEC } from '../../../const';
import { TIMEOUT_TO_CREATE_SEC } from '../../../const';
import { ProgressStep, ProgressStepProps, ProgressStepState } from '../../../ProgressStep';
import { ProgressStepTitle } from '../../../StepTitle';
import { TimeLimit } from '../../../TimeLimit';
Expand Down Expand Up @@ -68,7 +66,6 @@ export type State = ProgressStepState & {

class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
protected readonly name = 'Applying devfile';
protected readonly toDispose = new DisposableCollection();

constructor(props: Props) {
super(props);
Expand All @@ -85,8 +82,6 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
}

public componentDidUpdate() {
this.toDispose.dispose();

this.init();
}

Expand Down Expand Up @@ -207,8 +202,6 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
}

protected async runStep(): Promise<boolean> {
await delay(MIN_STEP_DURATION_MS);

const { factoryResolverConverted, factoryResolver, defaultDevfile } = this.props;
const { shouldCreate, devfile, warning, continueWithDefaultDevfile } = this.state;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { AlertVariant } from '@patternfly/react-core';
import { isEqual } from 'lodash';
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { delay } from '../../../../../services/helpers/delay';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import {
buildFactoryParams,
FactoryParams,
Expand All @@ -39,7 +37,7 @@ import * as WorkspacesStore from '../../../../../store/Workspaces';
import * as DevWorkspacesStore from '../../../../../store/Workspaces/devWorkspaces';
import { selectDevWorkspaceWarnings } from '../../../../../store/Workspaces/devWorkspaces/selectors';
import { selectAllWorkspaces } from '../../../../../store/Workspaces/selectors';
import { MIN_STEP_DURATION_MS, TIMEOUT_TO_CREATE_SEC } from '../../../const';
import { TIMEOUT_TO_CREATE_SEC } from '../../../const';
import { ProgressStep, ProgressStepProps, ProgressStepState } from '../../../ProgressStep';
import { ProgressStepTitle } from '../../../StepTitle';
import { TimeLimit } from '../../../TimeLimit';
Expand All @@ -59,7 +57,6 @@ export type State = ProgressStepState & {

class CreatingStepApplyResources extends ProgressStep<Props, State> {
protected readonly name = 'Applying resources';
protected readonly toDispose = new DisposableCollection();

constructor(props: Props) {
super(props);
Expand All @@ -76,8 +73,6 @@ class CreatingStepApplyResources extends ProgressStep<Props, State> {
}

public componentDidUpdate() {
this.toDispose.dispose();

this.init();
}

Expand Down Expand Up @@ -172,8 +167,6 @@ class CreatingStepApplyResources extends ProgressStep<Props, State> {
}

protected async runStep(): Promise<boolean> {
await delay(MIN_STEP_DURATION_MS);

const { devWorkspaceResources } = this.props;
const { factoryParams, shouldCreate, resources, warning } = this.state;
const { cheEditor, factoryId, sourceUrl, storageType, policiesCreate } = factoryParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { AlertVariant } from '@patternfly/react-core';
import { isEqual } from 'lodash';
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { delay } from '../../../../services/helpers/delay';
import {
buildFactoryParams,
FactoryParams,
Expand All @@ -30,17 +29,9 @@ import {
selectFactoryResolverConverted,
} from '../../../../store/FactoryResolver/selectors';
import { selectAllWorkspaces } from '../../../../store/Workspaces/selectors';
import { MIN_STEP_DURATION_MS } from '../../const';
import { ProgressStep, ProgressStepProps, ProgressStepState } from '../../ProgressStep';
import { ProgressStepTitle } from '../../StepTitle';

export class WorkspacesNameConflictError extends Error {
constructor(message: string | undefined) {
super(message);
this.name = 'RunningWorkspacesExceededError';
}
}

export type Props = MappedProps &
ProgressStepProps & {
searchParams: URLSearchParams;
Expand Down Expand Up @@ -71,8 +62,6 @@ class CreatingStepCheckExistingWorkspaces extends ProgressStep<Props, State> {
}

public componentDidUpdate() {
this.toDispose.dispose();

this.init();
}

Expand Down Expand Up @@ -140,8 +129,6 @@ class CreatingStepCheckExistingWorkspaces extends ProgressStep<Props, State> {
}

protected async runStep(): Promise<boolean> {
await delay(MIN_STEP_DURATION_MS);

const { devWorkspaceResources, factoryResolver, factoryResolverConverted } = this.props;
const { factoryParams, shouldCreate } = this.state;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
*/

import React from 'react';
import { delay } from '../../../../services/helpers/delay';
import { DisposableCollection } from '../../../../services/helpers/disposable';
import {
buildFactoryParams,
FactoryParams,
} from '../../../../services/helpers/factoryFlow/buildFactoryParams';
import { AlertItem } from '../../../../services/helpers/types';
import { MIN_STEP_DURATION_MS } from '../../const';
import { ProgressStep, ProgressStepProps, ProgressStepState } from '../../ProgressStep';
import { ProgressStepTitle } from '../../StepTitle';

Expand All @@ -31,7 +28,6 @@ export type State = ProgressStepState & {

export default class CreatingStepCreateWorkspace extends ProgressStep<Props, State> {
protected readonly name = 'Creating a workspace';
protected readonly toDispose = new DisposableCollection();

constructor(props: Props) {
super(props);
Expand All @@ -47,7 +43,6 @@ export default class CreatingStepCreateWorkspace extends ProgressStep<Props, Sta
}

protected async runStep(): Promise<boolean> {
await delay(MIN_STEP_DURATION_MS);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {
buildFactoryParams,
FactoryParams,
} from '../../../../../services/helpers/factoryFlow/buildFactoryParams';
import { delay } from '../../../../../services/helpers/delay';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import { getEnvironment, isDevEnvironment } from '../../../../../services/helpers/environment';
import { AlertItem } from '../../../../../services/helpers/types';
import OAuthService, { isOAuthResponse } from '../../../../../services/oauth';
Expand All @@ -33,7 +31,7 @@ import {
} from '../../../../../store/FactoryResolver/selectors';
import { selectAllWorkspaces } from '../../../../../store/Workspaces/selectors';
import ExpandableWarning from '../../../../ExpandableWarning';
import { MIN_STEP_DURATION_MS, TIMEOUT_TO_RESOLVE_SEC } from '../../../const';
import { TIMEOUT_TO_RESOLVE_SEC } from '../../../const';
import { ProgressStep, ProgressStepProps, ProgressStepState } from '../../../ProgressStep';
import { ProgressStepTitle } from '../../../StepTitle';
import { TimeLimit } from '../../../TimeLimit';
Expand Down Expand Up @@ -70,7 +68,6 @@ export type State = ProgressStepState & {

class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
protected readonly name = 'Looking for devfile';
protected readonly toDispose = new DisposableCollection();

constructor(props: Props) {
super(props);
Expand All @@ -88,8 +85,6 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
}

public componentDidUpdate() {
this.toDispose.dispose();

this.init();
}

Expand Down Expand Up @@ -182,8 +177,6 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
}

protected async runStep(): Promise<boolean> {
await delay(MIN_STEP_DURATION_MS);

const { factoryParams, shouldResolve, useDefaultDevfile } = this.state;
const { factoryResolver, factoryResolverConverted } = this.props;
const { sourceUrl } = factoryParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ import {
buildFactoryParams,
FactoryParams,
} from '../../../../../services/helpers/factoryFlow/buildFactoryParams';
import { delay } from '../../../../../services/helpers/delay';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import { AlertItem } from '../../../../../services/helpers/types';
import { AppState } from '../../../../../store';
import * as DevfileRegistriesStore from '../../../../../store/DevfileRegistries';
import { selectDevWorkspaceResources } from '../../../../../store/DevfileRegistries/selectors';
import { selectAllWorkspaces } from '../../../../../store/Workspaces/selectors';
import { MIN_STEP_DURATION_MS, TIMEOUT_TO_RESOLVE_SEC } from '../../../const';
import { TIMEOUT_TO_RESOLVE_SEC } from '../../../const';
import { ProgressStep, ProgressStepProps, ProgressStepState } from '../../../ProgressStep';
import { ProgressStepTitle } from '../../../StepTitle';
import { TimeLimit } from '../../../TimeLimit';
Expand All @@ -42,7 +40,6 @@ export type State = ProgressStepState & {

class CreatingStepFetchResources extends ProgressStep<Props, State> {
protected readonly name = 'Fetching pre-built resources';
protected readonly toDispose = new DisposableCollection();

constructor(props: Props) {
super(props);
Expand All @@ -59,8 +56,6 @@ class CreatingStepFetchResources extends ProgressStep<Props, State> {
}

public componentDidUpdate() {
this.toDispose.dispose();

this.init();
}

Expand Down Expand Up @@ -136,8 +131,6 @@ class CreatingStepFetchResources extends ProgressStep<Props, State> {
}

protected async runStep(): Promise<boolean> {
await delay(MIN_STEP_DURATION_MS);

const { devWorkspaceResources } = this.props;
const { factoryParams, shouldResolve } = this.state;
const { sourceUrl } = factoryParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ import {
FactoryParams,
PoliciesCreate,
} from '../../../../services/helpers/factoryFlow/buildFactoryParams';
import { delay } from '../../../../services/helpers/delay';
import { DisposableCollection } from '../../../../services/helpers/disposable';
import { AlertItem } from '../../../../services/helpers/types';
import { AppState } from '../../../../store';
import { selectAllWorkspacesLimit } from '../../../../store/ClusterConfig/selectors';
import { selectInfrastructureNamespaces } from '../../../../store/InfrastructureNamespaces/selectors';
import { selectAllWorkspaces } from '../../../../store/Workspaces/selectors';
import { MIN_STEP_DURATION_MS } from '../../const';
import { ProgressStep, ProgressStepProps, ProgressStepState } from '../../ProgressStep';
import { ProgressStepTitle } from '../../StepTitle';

Expand All @@ -43,7 +40,6 @@ export type State = ProgressStepState & {

class CreatingStepInitialize extends ProgressStep<Props, State> {
protected readonly name = 'Initializing';
protected readonly toDispose = new DisposableCollection();

constructor(props: Props) {
super(props);
Expand Down Expand Up @@ -71,8 +67,6 @@ class CreatingStepInitialize extends ProgressStep<Props, State> {
}

public componentDidUpdate() {
this.toDispose.dispose();

this.init();
}

Expand All @@ -91,8 +85,6 @@ class CreatingStepInitialize extends ProgressStep<Props, State> {
}

protected async runStep(): Promise<boolean> {
await delay(MIN_STEP_DURATION_MS);

const { useDevworkspaceResources, sourceUrl, errorCode, policiesCreate, remotes } =
this.state.factoryParams;

Expand Down
Loading

0 comments on commit 9edb086

Please sign in to comment.