From 2d00f2a55646fb7ec6afa8d28d8b2f494089c60b Mon Sep 17 00:00:00 2001 From: Oleksii Kurinnyi Date: Fri, 24 Dec 2021 17:39:14 +0200 Subject: [PATCH 01/20] refactor: rename convertWorkspace => constructWorkspace --- .../Navigation/__tests__/RecentList.spec.tsx | 4 +- .../src/Routes/__tests__/index.spec.tsx | 6 +- .../__tests__/FactoryLoader.spec.tsx | 14 ++-- .../GetStarted/__tests__/GetStarted.spec.tsx | 4 +- .../EditorTab/__tests__/index.spec.tsx | 6 +- .../WorkspaceDetails/EditorTab/index.tsx | 6 +- .../WorkspaceDetails/OverviewTab/index.tsx | 4 +- .../Toolbar/__tests__/index.spec.tsx | 4 +- .../WorkspacesList/__tests__/index.spec.tsx | 6 +- .../workspace-adapter/__tests__/index.spec.ts | 64 +++++++++---------- .../src/services/workspace-adapter/index.ts | 2 +- .../src/store/Workspaces/selectors.ts | 4 +- 12 files changed, 62 insertions(+), 62 deletions(-) diff --git a/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentList.spec.tsx b/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentList.spec.tsx index bfb8904f6..1ea9cc6ad 100644 --- a/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentList.spec.tsx +++ b/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentList.spec.tsx @@ -18,7 +18,7 @@ import { RenderResult, render, screen } from '@testing-library/react'; import { Store } from 'redux'; import NavigationRecentList from '../RecentList'; -import { convertWorkspace, Workspace } from '../../../services/workspace-adapter'; +import { constructWorkspace, Workspace } from '../../../services/workspace-adapter'; import { FakeStoreBuilder } from '../../../store/__mocks__/storeBuilder'; import { createHashHistory } from 'history'; import { createFakeCheWorkspace } from '../../../store/__mocks__/workspace'; @@ -30,7 +30,7 @@ jest.mock('react-tooltip', () => { }); const cheWorkspaces = [1, 2, 3].map(i => createFakeCheWorkspace('wksp-' + i, 'wksp-' + i)); -const workspaces = cheWorkspaces.map(workspace => convertWorkspace(workspace)); +const workspaces = cheWorkspaces.map(workspace => constructWorkspace(workspace)); describe('Navigation Recent List', () => { function renderComponent(store: Store, workspaces: Workspace[]): RenderResult { diff --git a/packages/dashboard-frontend/src/Routes/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/Routes/__tests__/index.spec.tsx index fd5b0fdda..bf5341fe1 100644 --- a/packages/dashboard-frontend/src/Routes/__tests__/index.spec.tsx +++ b/packages/dashboard-frontend/src/Routes/__tests__/index.spec.tsx @@ -27,7 +27,7 @@ import { buildWorkspacesLocation, } from '../../services/helpers/location'; import { IdeLoaderTab, WorkspaceDetailsTab } from '../../services/helpers/types'; -import { convertWorkspace, Workspace } from '../../services/workspace-adapter'; +import { constructWorkspace, Workspace } from '../../services/workspace-adapter'; import { CheWorkspaceBuilder } from '../../store/__mocks__/cheWorkspaceBuilder'; jest.mock('../../pages/GetStarted', () => { @@ -140,7 +140,7 @@ describe('Routes', () => { let workspace: Workspace; beforeEach(() => { - workspace = convertWorkspace(new CheWorkspaceBuilder().withNamespace('namespace').build()); + workspace = constructWorkspace(new CheWorkspaceBuilder().withNamespace('namespace').build()); }); it('should handle "/workspace/namespace/name"', async () => { @@ -184,7 +184,7 @@ describe('Routes', () => { let workspace: Workspace; beforeEach(() => { - workspace = convertWorkspace(new CheWorkspaceBuilder().withNamespace('namespace').build()); + workspace = constructWorkspace(new CheWorkspaceBuilder().withNamespace('namespace').build()); }); it('should handle "/ide/namespace/name"', async () => { diff --git a/packages/dashboard-frontend/src/containers/__tests__/FactoryLoader.spec.tsx b/packages/dashboard-frontend/src/containers/__tests__/FactoryLoader.spec.tsx index 3ca6f3372..c0114f6dd 100644 --- a/packages/dashboard-frontend/src/containers/__tests__/FactoryLoader.spec.tsx +++ b/packages/dashboard-frontend/src/containers/__tests__/FactoryLoader.spec.tsx @@ -22,7 +22,7 @@ import { createFakeCheWorkspace } from '../../store/__mocks__/workspace'; import { WorkspaceStatus } from '../../services/helpers/types'; import FactoryLoaderContainer, { LoadFactorySteps } from '../FactoryLoader'; import { AlertOptions } from '../../pages/IdeLoader'; -import { convertWorkspace, Devfile, WorkspaceAdapter } from '../../services/workspace-adapter'; +import { constructWorkspace, Devfile, WorkspaceAdapter } from '../../services/workspace-adapter'; import { DevWorkspaceBuilder } from '../../store/__mocks__/devWorkspaceBuilder'; import devfileApi from '../../services/devfileApi'; import { safeDump } from 'js-yaml'; @@ -71,7 +71,7 @@ jest.mock('../../store/Workspaces'); ) => async () => { createWorkspaceFromDevfileMock(devfile, namespace, infrastructureNamespace, attributes); - return convertWorkspace({ + return constructWorkspace({ id: 'id-wksp-test', attributes: attributes as che.WorkspaceAttributes, namespace, @@ -319,7 +319,7 @@ metadata: .withId('wrksp-test-id') .withName('wrksp-test-name') .build(); - const workspaceAdapter = convertWorkspace(workspace); + const workspaceAdapter = constructWorkspace(workspace); renderComponentV1(location, workspace); @@ -361,7 +361,7 @@ metadata: it('should resolve the factory, create a new workspace and open IDE', async () => { const location = 'http://test-location'; const workspace = createFakeWorkspaceWithRuntimeV1('id-wksp-test'); - const workspaceAdapter = convertWorkspace(workspace); + const workspaceAdapter = constructWorkspace(workspace); renderComponentV1(location, workspace); @@ -494,7 +494,7 @@ metadata: 'id-wksp-test', 'http://test-location/?policies.create=peruser', ); - const workspaceAdapter = convertWorkspace(workspace); + const workspaceAdapter = constructWorkspace(workspace); renderComponentV1(location, workspace); @@ -1035,7 +1035,7 @@ metadata: }); function renderComponentV2(url: string, workspace: devfileApi.DevWorkspace): RenderResult { - const wrks = convertWorkspace(workspace); + const wrks = constructWorkspace(workspace); (wrks.ref as devfileApi.DevWorkspace).metadata.annotations = { 'che.eclipse.org/devfile-source': safeDump({ factory: { params: 'url=http://test-location&policies.create=peruser' }, @@ -1057,7 +1057,7 @@ function renderComponentV2(url: string, workspace: devfileApi.DevWorkspace): Ren { v: '4.0', source: 'devfile.yaml', - devfile: convertWorkspace(workspace).devfile, + devfile: constructWorkspace(workspace).devfile, location: url.split('&')[0], scm_info: { clone_url: 'http://github.com/clone-url', diff --git a/packages/dashboard-frontend/src/pages/GetStarted/__tests__/GetStarted.spec.tsx b/packages/dashboard-frontend/src/pages/GetStarted/__tests__/GetStarted.spec.tsx index fdc237d64..932621d33 100644 --- a/packages/dashboard-frontend/src/pages/GetStarted/__tests__/GetStarted.spec.tsx +++ b/packages/dashboard-frontend/src/pages/GetStarted/__tests__/GetStarted.spec.tsx @@ -18,7 +18,7 @@ import React from 'react'; import GetStarted from '..'; import { FakeStoreBuilder } from '../../../store/__mocks__/storeBuilder'; import { BrandingData } from '../../../services/bootstrap/branding.constant'; -import { convertWorkspace, Devfile, Workspace } from '../../../services/workspace-adapter'; +import { constructWorkspace, Devfile, Workspace } from '../../../services/workspace-adapter'; import { CheWorkspaceBuilder } from '../../../store/__mocks__/cheWorkspaceBuilder'; const setWorkspaceQualifiedName = jest.fn(); @@ -45,7 +45,7 @@ jest.mock('../../../store/Workspaces/index', () => { (devfile, namespace, infrastructureNamespace, attributes) => async (): Promise => { createWorkspaceFromDevfileMock(devfile, namespace, infrastructureNamespace, attributes); - return convertWorkspace({ + return constructWorkspace({ id: 'id-wksp-test', attributes, namespace, diff --git a/packages/dashboard-frontend/src/pages/WorkspaceDetails/EditorTab/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/pages/WorkspaceDetails/EditorTab/__tests__/index.spec.tsx index 9138fa0e1..fd3a46fb0 100644 --- a/packages/dashboard-frontend/src/pages/WorkspaceDetails/EditorTab/__tests__/index.spec.tsx +++ b/packages/dashboard-frontend/src/pages/WorkspaceDetails/EditorTab/__tests__/index.spec.tsx @@ -19,7 +19,7 @@ import userEvent from '@testing-library/user-event'; import { dump } from 'js-yaml'; import devfileApi from '../../../../services/devfileApi'; import EditorTab from '..'; -import { Workspace, convertWorkspace } from '../../../../services/workspace-adapter'; +import { Workspace, constructWorkspace } from '../../../../services/workspace-adapter'; import { CheWorkspaceBuilder } from '../../../../store/__mocks__/cheWorkspaceBuilder'; import { DevWorkspaceBuilder } from '../../../../store/__mocks__/devWorkspaceBuilder'; import { FakeStoreBuilder } from '../../../../store/__mocks__/storeBuilder'; @@ -66,7 +66,7 @@ describe('Editor Tab', () => { workspaces: [cheWorkspace], }) .build(); - workspace = convertWorkspace(cheWorkspace); + workspace = constructWorkspace(cheWorkspace); component = getComponent(store, workspace); }); @@ -141,7 +141,7 @@ describe('Editor Tab', () => { workspaces: [devWorkspace], }) .build(); - workspace = convertWorkspace(devWorkspace); + workspace = constructWorkspace(devWorkspace); component = getComponent(store, workspace); }); diff --git a/packages/dashboard-frontend/src/pages/WorkspaceDetails/EditorTab/index.tsx b/packages/dashboard-frontend/src/pages/WorkspaceDetails/EditorTab/index.tsx index 5c7525a58..06004636f 100644 --- a/packages/dashboard-frontend/src/pages/WorkspaceDetails/EditorTab/index.tsx +++ b/packages/dashboard-frontend/src/pages/WorkspaceDetails/EditorTab/index.tsx @@ -29,7 +29,7 @@ import { safeLoad } from 'js-yaml'; import common from '@eclipse-che/common'; import DevfileEditor, { DevfileEditor as Editor } from '../../../components/DevfileEditor'; import EditorTools from './EditorTools'; -import { convertWorkspace, isCheWorkspace, Workspace } from '../../../services/workspace-adapter'; +import { constructWorkspace, isCheWorkspace, Workspace } from '../../../services/workspace-adapter'; import devfileApi, { isDevfileV2, isDevWorkspace } from '../../../services/devfileApi'; import { DevWorkspaceClient, @@ -245,7 +245,7 @@ export class EditorTab extends React.PureComponent { try { await this.checkForModifiedClusterDevWorkspace(); const devworkspace = this.props.workspace.ref as devfileApi.DevWorkspace; - const convertedDevWorkspace = convertWorkspace(devworkspace); + const convertedDevWorkspace = constructWorkspace(devworkspace); convertedDevWorkspace.devfile = devfile; // Store the devfile in here (convertedDevWorkspace.ref as devfileApi.DevWorkspace).metadata.annotations = { @@ -333,7 +333,7 @@ export class EditorTab extends React.PureComponent { if (!devfile) { return; } - const workspaceCopy = convertWorkspace(this.props.workspace.ref); + const workspaceCopy = constructWorkspace(this.props.workspace.ref); if (!devfile.metadata) { devfile.metadata = {}; } diff --git a/packages/dashboard-frontend/src/pages/WorkspaceDetails/OverviewTab/index.tsx b/packages/dashboard-frontend/src/pages/WorkspaceDetails/OverviewTab/index.tsx index 4ec3b954d..d8283a18a 100644 --- a/packages/dashboard-frontend/src/pages/WorkspaceDetails/OverviewTab/index.tsx +++ b/packages/dashboard-frontend/src/pages/WorkspaceDetails/OverviewTab/index.tsx @@ -16,7 +16,7 @@ import StorageTypeFormGroup from './StorageType'; import { WorkspaceNameFormGroup } from './WorkspaceName'; import InfrastructureNamespaceFormGroup from './InfrastructureNamespace'; import ProjectsFormGroup from './Projects'; -import { convertWorkspace, Workspace } from '../../../services/workspace-adapter'; +import { constructWorkspace, Workspace } from '../../../services/workspace-adapter'; import devfileApi, { isDevWorkspace } from '../../../services/devfileApi'; type Props = { @@ -105,7 +105,7 @@ export class OverviewTab extends React.Component { } private async onSave(devfile: che.WorkspaceDevfile | devfileApi.Devfile): Promise { - const workspaceCopy = convertWorkspace(this.props.workspace.ref); + const workspaceCopy = constructWorkspace(this.props.workspace.ref); workspaceCopy.devfile = devfile; await this.props.onSave(workspaceCopy); } diff --git a/packages/dashboard-frontend/src/pages/WorkspacesList/Toolbar/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/pages/WorkspacesList/Toolbar/__tests__/index.spec.tsx index 40eb141ee..1f6946902 100644 --- a/packages/dashboard-frontend/src/pages/WorkspacesList/Toolbar/__tests__/index.spec.tsx +++ b/packages/dashboard-frontend/src/pages/WorkspacesList/Toolbar/__tests__/index.spec.tsx @@ -17,7 +17,7 @@ import { render, screen, RenderResult, fireEvent } from '@testing-library/react' import userEvent from '@testing-library/user-event'; import WorkspacesListToolbar from '..'; import { createFakeCheWorkspace } from '../../../../store/__mocks__/workspace'; -import { convertWorkspace, Workspace } from '../../../../services/workspace-adapter'; +import { constructWorkspace, Workspace } from '../../../../services/workspace-adapter'; let workspaces: Workspace[]; let isSelectedAll: boolean; @@ -45,7 +45,7 @@ describe('Workspaces List Toolbar', () => { beforeEach(() => { workspaces = [0, 1, 2, 3, 4] .map(i => createFakeCheWorkspace('workspace-' + i, 'workspace-' + i)) - .map(workspace => convertWorkspace(workspace)); + .map(workspace => constructWorkspace(workspace)); isSelectedAll = false; isEnabledDelete = false; }); diff --git a/packages/dashboard-frontend/src/pages/WorkspacesList/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/pages/WorkspacesList/__tests__/index.spec.tsx index 78c455652..f0ffdb6f5 100644 --- a/packages/dashboard-frontend/src/pages/WorkspacesList/__tests__/index.spec.tsx +++ b/packages/dashboard-frontend/src/pages/WorkspacesList/__tests__/index.spec.tsx @@ -20,7 +20,7 @@ import WorkspacesList from '..'; import { BrandingData } from '../../../services/bootstrap/branding.constant'; import { createFakeCheWorkspace } from '../../../store/__mocks__/workspace'; import { WorkspaceAction, WorkspaceStatus } from '../../../services/helpers/types'; -import { convertWorkspace, Workspace } from '../../../services/workspace-adapter'; +import { constructWorkspace, Workspace } from '../../../services/workspace-adapter'; jest.mock('../../../components/Head', () => { const FakeHead = () => { @@ -55,7 +55,7 @@ describe('Workspaces List Page', () => { beforeEach(() => { workspaces = [0, 1, 2, 3, 4] .map(i => createFakeCheWorkspace('workspace-' + i, 'workspace-' + i)) - .map(workspace => convertWorkspace(workspace)); + .map(workspace => constructWorkspace(workspace)); isDeleted = []; }); @@ -352,7 +352,7 @@ describe('Workspaces List Page', () => { status: WorkspaceStatus.RUNNING, activeEnv: 'default', }; - workspaces[0] = convertWorkspace( + workspaces[0] = constructWorkspace( createFakeCheWorkspace( 'workspace-' + 0, 'workspace-' + 0, diff --git a/packages/dashboard-frontend/src/services/workspace-adapter/__tests__/index.spec.ts b/packages/dashboard-frontend/src/services/workspace-adapter/__tests__/index.spec.ts index 8730fb686..7c652bbb9 100644 --- a/packages/dashboard-frontend/src/services/workspace-adapter/__tests__/index.spec.ts +++ b/packages/dashboard-frontend/src/services/workspace-adapter/__tests__/index.spec.ts @@ -11,7 +11,7 @@ */ import { cloneDeep } from 'lodash'; -import { convertWorkspace } from '..'; +import { constructWorkspace } from '..'; import { CheWorkspaceBuilder, CHE_DEVFILE_STUB, @@ -40,14 +40,14 @@ describe('Workspace adapter', () => { it('should not throw when convert Che workspace', () => { const cheWorkspace = new CheWorkspaceBuilder().build(); expect(() => { - convertWorkspace(cheWorkspace); + constructWorkspace(cheWorkspace); }).not.toThrow(); }); it('should not throw when convert Dev workspace', () => { const devWorkspace = new DevWorkspaceBuilder().build(); expect(() => { - convertWorkspace(devWorkspace); + constructWorkspace(devWorkspace); }).not.toThrow(); }); @@ -58,7 +58,7 @@ describe('Workspace adapter', () => { field: 'value', } as any; expect(() => { - convertWorkspace(obj); + constructWorkspace(obj); }).toThrow(); }); }); @@ -66,28 +66,28 @@ describe('Workspace adapter', () => { describe('for Che workspace', () => { it('should return reference to the workspace', () => { const cheWorkspace = new CheWorkspaceBuilder().build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.ref).toMatchObject(cheWorkspace); }); it('should return ID', () => { const id = 'workspace1234asdf'; const cheWorkspace = new CheWorkspaceBuilder().withId(id).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.id).toEqual(id); }); it('should return name', () => { const name = 'wksp-1234'; const cheWorkspace = new CheWorkspaceBuilder().withName(name).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.name).toEqual(name); }); it('should return namespace', () => { const namespace = 'test-namespace'; const cheWorkspace = new CheWorkspaceBuilder().withNamespace(namespace).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.namespace).toEqual(namespace); }); @@ -98,7 +98,7 @@ describe('Workspace adapter', () => { infrastructureNamespace, } as che.WorkspaceAttributes) .build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.infrastructureNamespace).toEqual(infrastructureNamespace); }); @@ -109,7 +109,7 @@ describe('Workspace adapter', () => { created, } as che.WorkspaceAttributes) .build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.created.toString()).toEqual(created); }); @@ -120,14 +120,14 @@ describe('Workspace adapter', () => { updated, } as che.WorkspaceAttributes) .build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.updated.toString()).toEqual(updated); }); it('should return status', () => { const status = 'STARTING'; const cheWorkspace = new CheWorkspaceBuilder().withStatus(status).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.status).toEqual(status); }); @@ -136,7 +136,7 @@ describe('Workspace adapter', () => { const runtime = CHE_RUNTIME_STUB; runtime.machines['theia-ide'].servers.theia.url = ideUrl; const cheWorkspace = new CheWorkspaceBuilder().withRuntime(runtime).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.ideUrl).toEqual(ideUrl); }); @@ -146,7 +146,7 @@ describe('Workspace adapter', () => { asyncPersist: 'false', }; const cheWorkspace = new CheWorkspaceBuilder().withDevfile(cheDevfile).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.storageType).toEqual(StorageTypeTitle.ephemeral.toLowerCase()); }); @@ -156,7 +156,7 @@ describe('Workspace adapter', () => { asyncPersist: 'false', }; const cheWorkspace = new CheWorkspaceBuilder().withDevfile(cheDevfile).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.devfile).toMatchObject(cheDevfile); }); @@ -178,13 +178,13 @@ describe('Workspace adapter', () => { }, ]; const cheWorkspace = new CheWorkspaceBuilder().withProjects(projects).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.projects).toEqual([projects[0].name, projects[1].name]); }); it('should set "ephemeral" storage type', () => { const cheWorkspace = new CheWorkspaceBuilder().withDevfile(cheDevfile).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.storageType).toEqual('persistent'); expect((workspace.devfile as che.WorkspaceDevfile).attributes).toEqual(undefined); @@ -199,7 +199,7 @@ describe('Workspace adapter', () => { it('should set "async" storage type', () => { const cheWorkspace = new CheWorkspaceBuilder().withDevfile(cheDevfile).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.storageType).toEqual('persistent'); expect((workspace.devfile as che.WorkspaceDevfile).attributes).toEqual(undefined); @@ -218,7 +218,7 @@ describe('Workspace adapter', () => { persistVolumes: 'false', }; const cheWorkspace = new CheWorkspaceBuilder().withDevfile(cheDevfile).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.storageType).toEqual('ephemeral'); @@ -235,7 +235,7 @@ describe('Workspace adapter', () => { asyncPersist: 'true', }; const cheWorkspace = new CheWorkspaceBuilder().withDevfile(cheDevfile).build(); - const workspace = convertWorkspace(cheWorkspace); + const workspace = constructWorkspace(cheWorkspace); expect(workspace.storageType).toEqual('async'); @@ -251,35 +251,35 @@ describe('Workspace adapter', () => { describe('for Dev workspace', () => { it('should return reference to the workspace', () => { const devWorkspace = new DevWorkspaceBuilder().build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.ref).toMatchObject(devWorkspace); }); it('should return ID', () => { const id = '1234asdf'; const devWorkspace = new DevWorkspaceBuilder().withId(id).build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.id).toEqual(id); }); it('should return name', () => { const name = 'wksp-1234'; const devWorkspace = new DevWorkspaceBuilder().withName(name).build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.name).toEqual(name); }); it('should return namespace', () => { const namespace = 'test-namespace'; const devWorkspace = new DevWorkspaceBuilder().withNamespace(namespace).build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.namespace).toEqual(namespace); }); it('should return infrastructure namespace', () => { const infrastructureNamespace = 'infrastructure-namespace'; const devWorkspace = new DevWorkspaceBuilder().withNamespace(infrastructureNamespace).build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.infrastructureNamespace).toEqual(infrastructureNamespace); }); @@ -288,7 +288,7 @@ describe('Workspace adapter', () => { const created = new Date(timestamp); const devWorkspace = new DevWorkspaceBuilder().build(); devWorkspace.metadata.creationTimestamp = created; - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.created).toEqual(timestamp); }); @@ -299,27 +299,27 @@ describe('Workspace adapter', () => { devWorkspace.metadata.annotations = { [DEVWORKSPACE_UPDATING_TIMESTAMP_ANNOTATION]: updated, }; - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.updated).toEqual(timestamp); }); it('should return status', () => { const status = 'STARTING'; const devWorkspace = new DevWorkspaceBuilder().withStatus({ phase: status }).build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.status).toEqual(DevWorkspaceStatus[status]); }); it('should return ideUrl', () => { const ideUrl = 'my/ide/url'; const devWorkspace = new DevWorkspaceBuilder().withIdeUrl(ideUrl).build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.ideUrl).toEqual(ideUrl); }); it('should return storage type', () => { const devWorkspace = new DevWorkspaceBuilder().build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.storageType).toEqual(StorageTypeTitle.persistent.toLowerCase()); }); @@ -335,7 +335,7 @@ describe('Workspace adapter', () => { .withName('my-wksp') .withNamespace('my-namespace') .build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.devfile).toMatchObject(devfile); }); @@ -359,7 +359,7 @@ describe('Workspace adapter', () => { }, ]; const devWorkspace = new DevWorkspaceBuilder().withProjects(projects).build(); - const workspace = convertWorkspace(devWorkspace); + const workspace = constructWorkspace(devWorkspace); expect(workspace.projects).toEqual([projects[0].name, projects[1].name]); }); }); diff --git a/packages/dashboard-frontend/src/services/workspace-adapter/index.ts b/packages/dashboard-frontend/src/services/workspace-adapter/index.ts index 7a95e8b8b..95da3cf8b 100644 --- a/packages/dashboard-frontend/src/services/workspace-adapter/index.ts +++ b/packages/dashboard-frontend/src/services/workspace-adapter/index.ts @@ -334,7 +334,7 @@ export class WorkspaceAdapter } } -export function convertWorkspace( +export function constructWorkspace( workspace: T, ): Workspace { return new WorkspaceAdapter(workspace); diff --git a/packages/dashboard-frontend/src/store/Workspaces/selectors.ts b/packages/dashboard-frontend/src/store/Workspaces/selectors.ts index f3bb787d8..987e959c0 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/selectors.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/selectors.ts @@ -12,7 +12,7 @@ import { createSelector } from 'reselect'; import { AppState } from '..'; -import { convertWorkspace, Workspace } from '../../services/workspace-adapter'; +import { constructWorkspace, Workspace } from '../../services/workspace-adapter'; import { selectCheWorkspacesError } from './cheWorkspaces/selectors'; import { selectDevWorkspacesError } from './devWorkspaces/selectors'; @@ -35,7 +35,7 @@ export const selectAllWorkspaces = createSelector( selectDevWorkspacesState, (cheWorkspacesState, devWorkspacesState) => { return [...cheWorkspacesState.workspaces, ...devWorkspacesState.workspaces].map(workspace => - convertWorkspace(workspace), + constructWorkspace(workspace), ); }, ); From 0e36f47d6b0628668ecac5edbd084490fe6ac33a Mon Sep 17 00:00:00 2001 From: Oleksii Kurinnyi Date: Tue, 28 Dec 2021 15:46:32 +0200 Subject: [PATCH 02/20] feat: mark che-workspaces as deprecated --- .../Navigation/RecentItemWorkspaceActions.tsx | 6 +-- .../Navigation/__tests__/RecentItem.spec.tsx | 2 +- .../Navigation/__tests__/RecentList.spec.tsx | 16 +++++-- .../src/Layout/Navigation/index.tsx | 11 +++-- .../src/components/Header/index.tsx | 15 +++--- .../Indicator/__tests__/Indicator.spec.tsx | 9 +++- .../__snapshots__/Indicator.spec.tsx.snap | 33 ++++++++++++- .../components/Workspace/Indicator/index.tsx | 25 ++++++++-- .../__snapshots__/index.spec.tsx.snap | 42 ++++++++++++++++- .../__tests__/index.spec.tsx | 9 +++- .../components/WorkspaceStatusLabel/index.tsx | 25 ++++++++-- .../src/containers/IdeLoader.tsx | 13 +++++- .../IdeLoader/__tests__/IdeLoader.spec.tsx | 14 +++--- .../src/pages/IdeLoader/index.tsx | 9 +++- .../pages/WorkspaceDetails/Header/index.tsx | 7 ++- .../src/services/bootstrap/index.ts | 4 ++ .../src/services/helpers/types.ts | 2 + .../src/services/workspace-adapter/index.ts | 24 ++++++++-- .../src/store/Workspaces/selectors.ts | 46 +++++++++++-------- 19 files changed, 245 insertions(+), 67 deletions(-) diff --git a/packages/dashboard-frontend/src/Layout/Navigation/RecentItemWorkspaceActions.tsx b/packages/dashboard-frontend/src/Layout/Navigation/RecentItemWorkspaceActions.tsx index 8a580e6da..7cc59c4db 100644 --- a/packages/dashboard-frontend/src/Layout/Navigation/RecentItemWorkspaceActions.tsx +++ b/packages/dashboard-frontend/src/Layout/Navigation/RecentItemWorkspaceActions.tsx @@ -98,11 +98,7 @@ class NavigationItemWorkspaceActions extends React.PureComponent { createAction(WorkspaceAction.START_DEBUG_AND_OPEN_LOGS), createAction(WorkspaceAction.START_IN_BACKGROUND), ); - } else if ( - status !== WorkspaceStatus.STOPPING && - status !== DevWorkspaceStatus.TERMINATING && - status !== DevWorkspaceStatus.FAILED - ) { + } else if (status !== WorkspaceStatus.STOPPING && status !== DevWorkspaceStatus.TERMINATING) { dropdownItems.push(createAction(WorkspaceAction.STOP_WORKSPACE)); } if ( diff --git a/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentItem.spec.tsx b/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentItem.spec.tsx index 44c5d2fe7..c5b99af75 100644 --- a/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentItem.spec.tsx +++ b/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentItem.spec.tsx @@ -30,7 +30,7 @@ jest.mock('../../../components/Workspace/Indicator', () => { describe('Navigation Item', () => { const item: NavigationRecentItemObject = { - status: '', + status: WorkspaceStatus.STOPPED, label: 'workspace', to: '/namespace/workspace', isDevWorkspace: false, diff --git a/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentList.spec.tsx b/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentList.spec.tsx index 1ea9cc6ad..184ed3f63 100644 --- a/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentList.spec.tsx +++ b/packages/dashboard-frontend/src/Layout/Navigation/__tests__/RecentList.spec.tsx @@ -21,7 +21,7 @@ import NavigationRecentList from '../RecentList'; import { constructWorkspace, Workspace } from '../../../services/workspace-adapter'; import { FakeStoreBuilder } from '../../../store/__mocks__/storeBuilder'; import { createHashHistory } from 'history'; -import { createFakeCheWorkspace } from '../../../store/__mocks__/workspace'; +import { CheWorkspaceBuilder } from '../../../store/__mocks__/cheWorkspaceBuilder'; jest.mock('react-tooltip', () => { return function DummyTooltip(): React.ReactElement { @@ -29,10 +29,20 @@ jest.mock('react-tooltip', () => { }; }); -const cheWorkspaces = [1, 2, 3].map(i => createFakeCheWorkspace('wksp-' + i, 'wksp-' + i)); -const workspaces = cheWorkspaces.map(workspace => constructWorkspace(workspace)); +let cheWorkspaces: che.Workspace[]; +let workspaces: Workspace[]; describe('Navigation Recent List', () => { + beforeEach(() => { + cheWorkspaces = [1, 2, 3].map(i => + new CheWorkspaceBuilder() + .withId('wksp-' + i) + .withName('wksp-' + i) + .build(), + ); + workspaces = cheWorkspaces.map(workspace => constructWorkspace(workspace)); + }); + function renderComponent(store: Store, workspaces: Workspace[]): RenderResult { const history = createHashHistory(); return render( diff --git a/packages/dashboard-frontend/src/Layout/Navigation/index.tsx b/packages/dashboard-frontend/src/Layout/Navigation/index.tsx index bd0c0e38b..9b96cd975 100644 --- a/packages/dashboard-frontend/src/Layout/Navigation/index.tsx +++ b/packages/dashboard-frontend/src/Layout/Navigation/index.tsx @@ -27,6 +27,11 @@ import { buildWorkspacesLocation, sanitizeLocation, } from '../../services/helpers/location'; +import { + DeprecatedWorkspaceStatus, + DevWorkspaceStatus, + WorkspaceStatus, +} from '../../services/helpers/types'; export interface NavigationItemObject { to: string; @@ -36,7 +41,7 @@ export interface NavigationItemObject { export interface NavigationRecentItemObject { to: string; label: string; - status: string; + status: WorkspaceStatus | DevWorkspaceStatus | DeprecatedWorkspaceStatus; workspaceId: string; isDevWorkspace: boolean; } @@ -111,8 +116,6 @@ export class Navigation extends React.PureComponent { const { theme, recentWorkspaces, history } = this.props; const { activeLocation } = this.state; - const recent = recentWorkspaces || []; - return (