diff --git a/packages/dashboard-frontend/package.json b/packages/dashboard-frontend/package.json index 743ab10b62..536f9ff564 100644 --- a/packages/dashboard-frontend/package.json +++ b/packages/dashboard-frontend/package.json @@ -33,7 +33,6 @@ }, "dependencies": { "@eclipse-che/devfile-converter": "0.0.1-ff55f9a", - "@eclipse-che/workspace-client": "0.0.1-1672830275", "@patternfly/react-core": "^4.276.11", "@patternfly/react-icons": "^4.93.7", "@patternfly/react-table": "^4.113.3", diff --git a/packages/dashboard-frontend/src/components/BannerAlert/WebSocket/__tests__/index.spec.tsx b/packages/dashboard-frontend/src/components/BannerAlert/WebSocket/__tests__/index.spec.tsx index c64b8e7840..b4de42d7eb 100644 --- a/packages/dashboard-frontend/src/components/BannerAlert/WebSocket/__tests__/index.spec.tsx +++ b/packages/dashboard-frontend/src/components/BannerAlert/WebSocket/__tests__/index.spec.tsx @@ -19,7 +19,7 @@ import { BrandingData } from '../../../../services/bootstrap/branding.constant'; import { ConnectionEvent, WebsocketClient, -} from '../../../../services/dashboard-backend-client/websocketClient'; +} from '../../../../services/backend-client/websocketClient'; import { FakeStoreBuilder } from '../../../../store/__mocks__/storeBuilder'; const failingMessage = 'WebSocket connections are failing'; diff --git a/packages/dashboard-frontend/src/components/BannerAlert/WebSocket/index.tsx b/packages/dashboard-frontend/src/components/BannerAlert/WebSocket/index.tsx index dccfb4ae8a..f79c5a8632 100644 --- a/packages/dashboard-frontend/src/components/BannerAlert/WebSocket/index.tsx +++ b/packages/dashboard-frontend/src/components/BannerAlert/WebSocket/index.tsx @@ -20,7 +20,7 @@ import { ConnectionEvent, ConnectionListener, WebsocketClient, -} from '../../../services/dashboard-backend-client/websocketClient'; +} from '../../../services/backend-client/websocketClient'; type Props = MappedProps; diff --git a/packages/dashboard-frontend/src/inversify.config.ts b/packages/dashboard-frontend/src/inversify.config.ts index 601d8faf45..941d68534d 100644 --- a/packages/dashboard-frontend/src/inversify.config.ts +++ b/packages/dashboard-frontend/src/inversify.config.ts @@ -13,20 +13,18 @@ import 'reflect-metadata'; import { Container } from 'inversify'; import getDecorators from 'inversify-inject-decorators'; -import { CheWorkspaceClient } from './services/workspace-client/cheworkspace/cheWorkspaceClient'; import { AppAlerts } from './services/alerts/appAlerts'; import { IssuesReporterService } from './services/bootstrap/issuesReporter'; import { DevWorkspaceClient } from './services/workspace-client/devworkspace/devWorkspaceClient'; import { DevWorkspaceDefaultPluginsHandler } from './services/workspace-client/devworkspace/DevWorkspaceDefaultPluginsHandler'; import { WorkspaceStoppedDetector } from './services/bootstrap/workspaceStoppedDetector'; -import { WebsocketClient } from './services/dashboard-backend-client/websocketClient'; +import { WebsocketClient } from './services/backend-client/websocketClient'; const container = new Container(); const { lazyInject } = getDecorators(container); container.bind(IssuesReporterService).toSelf().inSingletonScope(); container.bind(WebsocketClient).toSelf().inSingletonScope(); -container.bind(CheWorkspaceClient).toSelf().inSingletonScope(); container.bind(DevWorkspaceClient).toSelf().inSingletonScope(); container.bind(AppAlerts).toSelf().inSingletonScope(); container.bind(DevWorkspaceDefaultPluginsHandler).toSelf().inSingletonScope(); diff --git a/packages/dashboard-frontend/src/services/backend-client/__tests__/kubernetesNamespaceApi.spec.tsx b/packages/dashboard-frontend/src/services/backend-client/__tests__/kubernetesNamespaceApi.spec.tsx new file mode 100644 index 0000000000..7b1ed92b0f --- /dev/null +++ b/packages/dashboard-frontend/src/services/backend-client/__tests__/kubernetesNamespaceApi.spec.tsx @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018-2023 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +import mockAxios from 'axios'; +import { getKubernetesNamespace, provisionKubernetesNamespace } from '../kubernetesNamespaceApi'; + +describe('Kubernetes namespace API', () => { + const mockGet = mockAxios.get as jest.Mock; + const mockPost = mockAxios.post as jest.Mock; + + const namespace: che.KubernetesNamespace = { name: 'test-name', attributes: { phase: 'Active' } }; + + afterEach(() => { + jest.resetAllMocks(); + }); + + describe('fetch namespace', () => { + it('should call "/api/kubernetes/namespace"', async () => { + mockGet.mockResolvedValueOnce({ + data: expect.anything(), + }); + await getKubernetesNamespace(); + + expect(mockGet).toBeCalledWith('/api/kubernetes/namespace'); + expect(mockPost).not.toBeCalled(); + }); + + it('should return a list of namespaces', async () => { + mockGet.mockResolvedValueOnce({ + data: [namespace], + }); + + const res = await getKubernetesNamespace(); + + expect(res).toEqual([namespace]); + }); + }); + + describe('provision namespace', () => { + it('should call "/api/kubernetes/namespace/provision"', async () => { + mockPost.mockResolvedValueOnce({ + data: expect.anything(), + }); + await provisionKubernetesNamespace(); + + expect(mockGet).not.toBeCalled(); + expect(mockPost).toBeCalledWith('/api/kubernetes/namespace/provision'); + }); + + it('should return a list of namespaces', async () => { + mockPost.mockResolvedValueOnce({ + data: [namespace], + }); + + const res = await provisionKubernetesNamespace(); + + expect(res).toEqual([namespace]); + }); + }); +}); diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/clusterConfigApi.ts b/packages/dashboard-frontend/src/services/backend-client/clusterConfigApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/clusterConfigApi.ts rename to packages/dashboard-frontend/src/services/backend-client/clusterConfigApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/clusterInfoApi.ts b/packages/dashboard-frontend/src/services/backend-client/clusterInfoApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/clusterInfoApi.ts rename to packages/dashboard-frontend/src/services/backend-client/clusterInfoApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/const.ts b/packages/dashboard-frontend/src/services/backend-client/const.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/const.ts rename to packages/dashboard-frontend/src/services/backend-client/const.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/devWorkspaceApi.ts b/packages/dashboard-frontend/src/services/backend-client/devWorkspaceApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/devWorkspaceApi.ts rename to packages/dashboard-frontend/src/services/backend-client/devWorkspaceApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/devWorkspaceTemplateApi.ts b/packages/dashboard-frontend/src/services/backend-client/devWorkspaceTemplateApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/devWorkspaceTemplateApi.ts rename to packages/dashboard-frontend/src/services/backend-client/devWorkspaceTemplateApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/devworkspaceResourcesApi.ts b/packages/dashboard-frontend/src/services/backend-client/devworkspaceResourcesApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/devworkspaceResourcesApi.ts rename to packages/dashboard-frontend/src/services/backend-client/devworkspaceResourcesApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/eventsApi.ts b/packages/dashboard-frontend/src/services/backend-client/eventsApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/eventsApi.ts rename to packages/dashboard-frontend/src/services/backend-client/eventsApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/factoryResolverApi.ts b/packages/dashboard-frontend/src/services/backend-client/factoryApi.ts similarity index 71% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/factoryResolverApi.ts rename to packages/dashboard-frontend/src/services/backend-client/factoryApi.ts index bace207744..16cd22d3d8 100644 --- a/packages/dashboard-frontend/src/services/dashboard-backend-client/factoryResolverApi.ts +++ b/packages/dashboard-frontend/src/services/backend-client/factoryApi.ts @@ -14,16 +14,22 @@ import axios from 'axios'; import { cheServerPrefix } from './const'; import { FactoryResolver } from '../helpers/types'; -const factoryResolverEndpoint = '/factory/resolver'; +const factoryEndpoint = '/factory'; export async function getFactoryResolver( url: string, overrideParams: { [params: string]: string } = {}, ): Promise { const response = await axios.post( - `${cheServerPrefix}${factoryResolverEndpoint}`, + `${cheServerPrefix}${factoryEndpoint}/resolver`, Object.assign({}, overrideParams, { url }), ); return response.data; } + +export async function refreshFactoryOauthToken(url: string): Promise { + await axios.post(`${cheServerPrefix}${factoryEndpoint}/token/refresh?url=${url}`); + + return Promise.resolve(); +} diff --git a/packages/dashboard-frontend/src/services/backend-client/kubernetesNamespaceApi.ts b/packages/dashboard-frontend/src/services/backend-client/kubernetesNamespaceApi.ts new file mode 100644 index 0000000000..f6d0667efc --- /dev/null +++ b/packages/dashboard-frontend/src/services/backend-client/kubernetesNamespaceApi.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018-2023 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +import axios from 'axios'; +import { cheServerPrefix } from './const'; +import { api } from '@eclipse-che/common'; + +export async function getKubernetesNamespace(): Promise { + const response = await axios.get(`${cheServerPrefix}/kubernetes/namespace`); + + return response.data; +} + +export async function provisionKubernetesNamespace(): Promise { + const response = await axios.post(`${cheServerPrefix}/kubernetes/namespace/provision`); + + return response.data; +} diff --git a/packages/dashboard-frontend/src/services/backend-client/oAuthApi.ts b/packages/dashboard-frontend/src/services/backend-client/oAuthApi.ts new file mode 100644 index 0000000000..7100630a7b --- /dev/null +++ b/packages/dashboard-frontend/src/services/backend-client/oAuthApi.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018-2023 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +import axios from 'axios'; +import { cheServerPrefix } from './const'; +import { api } from '@eclipse-che/common'; + +export async function getOAuthProviders(): Promise< + { + name: api.GitOauthProvider; + endpointUrl: string; + }[] +> { + const response = await axios.get(`${cheServerPrefix}/resolver`); + + return response.data; +} + +export async function getOAuthToken(provider: api.GitOauthProvider): Promise { + const response = await axios.get(`${cheServerPrefix}/oauth/token?oauth_provider=${provider}`); + + return response.data; +} + +export async function deleteOAuthToken(provider: api.GitOauthProvider): Promise { + await axios.delete(`${cheServerPrefix}/oauth/token?oauth_provider=${provider}`); + + return Promise.resolve(); +} diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/personalAccessTokenApi.ts b/packages/dashboard-frontend/src/services/backend-client/personalAccessTokenApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/personalAccessTokenApi.ts rename to packages/dashboard-frontend/src/services/backend-client/personalAccessTokenApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/podsApi.ts b/packages/dashboard-frontend/src/services/backend-client/podsApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/podsApi.ts rename to packages/dashboard-frontend/src/services/backend-client/podsApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/serverConfigApi.ts b/packages/dashboard-frontend/src/services/backend-client/serverConfigApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/serverConfigApi.ts rename to packages/dashboard-frontend/src/services/backend-client/serverConfigApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/userProfileApi.ts b/packages/dashboard-frontend/src/services/backend-client/userProfileApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/userProfileApi.ts rename to packages/dashboard-frontend/src/services/backend-client/userProfileApi.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/__tests__/index.spec.ts b/packages/dashboard-frontend/src/services/backend-client/websocketClient/__tests__/index.spec.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/__tests__/index.spec.ts rename to packages/dashboard-frontend/src/services/backend-client/websocketClient/__tests__/index.spec.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/__tests__/messageHandler.spec.ts b/packages/dashboard-frontend/src/services/backend-client/websocketClient/__tests__/messageHandler.spec.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/__tests__/messageHandler.spec.ts rename to packages/dashboard-frontend/src/services/backend-client/websocketClient/__tests__/messageHandler.spec.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/__tests__/subscriptionsManager.spec.ts b/packages/dashboard-frontend/src/services/backend-client/websocketClient/__tests__/subscriptionsManager.spec.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/__tests__/subscriptionsManager.spec.ts rename to packages/dashboard-frontend/src/services/backend-client/websocketClient/__tests__/subscriptionsManager.spec.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/index.ts b/packages/dashboard-frontend/src/services/backend-client/websocketClient/index.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/index.ts rename to packages/dashboard-frontend/src/services/backend-client/websocketClient/index.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/messageHandler.ts b/packages/dashboard-frontend/src/services/backend-client/websocketClient/messageHandler.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/messageHandler.ts rename to packages/dashboard-frontend/src/services/backend-client/websocketClient/messageHandler.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/subscriptionsManager.ts b/packages/dashboard-frontend/src/services/backend-client/websocketClient/subscriptionsManager.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/websocketClient/subscriptionsManager.ts rename to packages/dashboard-frontend/src/services/backend-client/websocketClient/subscriptionsManager.ts diff --git a/packages/dashboard-frontend/src/services/dashboard-backend-client/yamlResolverApi.ts b/packages/dashboard-frontend/src/services/backend-client/yamlResolverApi.ts similarity index 100% rename from packages/dashboard-frontend/src/services/dashboard-backend-client/yamlResolverApi.ts rename to packages/dashboard-frontend/src/services/backend-client/yamlResolverApi.ts diff --git a/packages/dashboard-frontend/src/services/bootstrap/index.ts b/packages/dashboard-frontend/src/services/bootstrap/index.ts index 7662967cf3..39b0c15791 100644 --- a/packages/dashboard-frontend/src/services/bootstrap/index.ts +++ b/packages/dashboard-frontend/src/services/bootstrap/index.ts @@ -41,10 +41,10 @@ import { Workspace } from '../workspace-adapter'; import { WorkspaceRunningError, WorkspaceStoppedDetector } from './workspaceStoppedDetector'; import { selectOpenVSXUrl } from '../../store/ServerConfig/selectors'; import { selectEmptyWorkspaceUrl } from '../../store/DevfileRegistries/selectors'; -import { WebsocketClient } from '../dashboard-backend-client/websocketClient'; +import { WebsocketClient } from '../backend-client/websocketClient'; import { selectEventsResourceVersion } from '../../store/Events/selectors'; import { selectPodsResourceVersion } from '../../store/Pods/selectors'; -import { ChannelListener } from '../dashboard-backend-client/websocketClient/messageHandler'; +import { ChannelListener } from '../backend-client/websocketClient/messageHandler'; import { selectApplications } from '../../store/ClusterInfo/selectors'; import { isAvailableEndpoint } from '../helpers/api-ping'; import { DEFAULT_REGISTRY } from '../../store/DevfileRegistries'; diff --git a/packages/dashboard-frontend/src/services/oauth/__tests__/index.spec.ts b/packages/dashboard-frontend/src/services/oauth/__tests__/index.spec.ts index 21aff60299..5a15c2e85f 100644 --- a/packages/dashboard-frontend/src/services/oauth/__tests__/index.spec.ts +++ b/packages/dashboard-frontend/src/services/oauth/__tests__/index.spec.ts @@ -13,16 +13,10 @@ import { AxiosError } from 'axios'; import common from '@eclipse-che/common'; import OAuthService from '..'; -import { container } from '../../../inversify.config'; import { DevWorkspaceBuilder } from '../../../store/__mocks__/devWorkspaceBuilder'; -import { CheWorkspaceClient } from '../../workspace-client/cheworkspace/cheWorkspaceClient'; +import * as factoryApi from '../../backend-client/factoryApi'; -const cheWorkspaceClient = container.get(CheWorkspaceClient); - -const refreshFactoryOauthTokenSpy = jest.spyOn( - cheWorkspaceClient.restApiClient, - 'refreshFactoryOauthToken', -); +const refreshFactoryOauthTokenSpy = jest.spyOn(factoryApi, 'refreshFactoryOauthToken'); const mockOpenOAuthPage = jest.fn().mockImplementation(); OAuthService.openOAuthPage = mockOpenOAuthPage; diff --git a/packages/dashboard-frontend/src/services/oauth/index.ts b/packages/dashboard-frontend/src/services/oauth/index.ts index 9f6953d690..2518dee6fc 100644 --- a/packages/dashboard-frontend/src/services/oauth/index.ts +++ b/packages/dashboard-frontend/src/services/oauth/index.ts @@ -12,11 +12,8 @@ import common, { helpers } from '@eclipse-che/common'; import { OAuthResponse } from '../../store/FactoryResolver'; -import { container } from '../../inversify.config'; -import { CheWorkspaceClient } from '../workspace-client/cheworkspace/cheWorkspaceClient'; import devfileApi from '../devfileApi'; - -const WorkspaceClient = container.get(CheWorkspaceClient); +import { refreshFactoryOauthToken } from '../backend-client/factoryApi'; export default class OAuthService { static openOAuthPage(authenticationUrl: string, redirectUrl: string): void { @@ -44,7 +41,7 @@ export default class OAuthService { } try { - await WorkspaceClient.restApiClient.refreshFactoryOauthToken(project.git.remotes.origin); + await refreshFactoryOauthToken(project.git.remotes.origin); } catch (e) { if (!common.helpers.errors.includesAxiosResponse(e)) { return; diff --git a/packages/dashboard-frontend/src/services/workspace-client/__tests__/helpers.spec.ts b/packages/dashboard-frontend/src/services/workspace-client/__tests__/helpers.spec.ts index 124c824011..b29205eb0b 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/__tests__/helpers.spec.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/__tests__/helpers.spec.ts @@ -11,7 +11,7 @@ */ import { getCustomEditor, isForbidden, isInternalServerError, isUnauthorized } from '../helpers'; -import { CHE_EDITOR_YAML_PATH } from '../'; +import { CHE_EDITOR_YAML_PATH } from '../helpers'; import { dump } from 'js-yaml'; import common from '@eclipse-che/common'; import devfileApi from '../../devfileApi'; diff --git a/packages/dashboard-frontend/src/services/workspace-client/cheworkspace/cheWorkspaceClient.ts b/packages/dashboard-frontend/src/services/workspace-client/cheworkspace/cheWorkspaceClient.ts deleted file mode 100644 index 9c783beeb6..0000000000 --- a/packages/dashboard-frontend/src/services/workspace-client/cheworkspace/cheWorkspaceClient.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2018-2023 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ - -import { injectable } from 'inversify'; -import { default as WorkspaceClientLib, IRemoteAPI } from '@eclipse-che/workspace-client'; - -/** - * This class manages the api connection. - */ -@injectable() -export class CheWorkspaceClient { - private baseUrl: string; - private _restApiClient: IRemoteAPI; - - /** - * Default constructor that is using resource. - */ - constructor() { - this.baseUrl = '/api'; - } - - get restApiClient(): IRemoteAPI { - // Lazy initialization of restApiClient - if (!this._restApiClient) { - this.updateRestApiClient(); - } - return this._restApiClient; - } - - updateRestApiClient(): void { - const baseUrl = this.baseUrl; - this._restApiClient = WorkspaceClientLib.getRestApi({ baseUrl }); - } -} diff --git a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/DevWorkspaceDefaultPluginsHandler.ts b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/DevWorkspaceDefaultPluginsHandler.ts index aceaf43dd5..932498c11c 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/DevWorkspaceDefaultPluginsHandler.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/DevWorkspaceDefaultPluginsHandler.ts @@ -10,7 +10,7 @@ * Red Hat, Inc. - initial API and implementation */ -import * as DwApi from '../../dashboard-backend-client/devWorkspaceApi'; +import * as DwApi from '../../backend-client/devWorkspaceApi'; import devfileApi from '../../devfileApi'; import { api } from '@eclipse-che/common'; import { createHash } from 'crypto'; diff --git a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.changeWorkspaceStatus.spec.ts b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.changeWorkspaceStatus.spec.ts index 2e1738a3f8..b49b7d8ce6 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.changeWorkspaceStatus.spec.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.changeWorkspaceStatus.spec.ts @@ -13,7 +13,7 @@ import { container } from '../../../../inversify.config'; import { DevWorkspaceBuilder } from '../../../../store/__mocks__/devWorkspaceBuilder'; import { DevWorkspaceClient } from '../devWorkspaceClient'; -import * as DwApi from '../../../dashboard-backend-client/devWorkspaceApi'; +import * as DwApi from '../../../backend-client/devWorkspaceApi'; describe('DevWorkspace client, changeWorkspaceStatus', () => { let client: DevWorkspaceClient; diff --git a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.create.spec.ts b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.create.spec.ts index 557432a824..165f29e527 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.create.spec.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.create.spec.ts @@ -12,8 +12,8 @@ import { container } from '../../../../inversify.config'; import { DevWorkspaceClient } from '../devWorkspaceClient'; -import * as DwtApi from '../../../dashboard-backend-client/devWorkspaceTemplateApi'; -import * as DwApi from '../../../dashboard-backend-client/devWorkspaceApi'; +import * as DwtApi from '../../../backend-client/devWorkspaceTemplateApi'; +import * as DwApi from '../../../backend-client/devWorkspaceApi'; import devfileApi from '../../../devfileApi'; describe('DevWorkspace client, create', () => { diff --git a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.editorUpdate.spec.ts b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.editorUpdate.spec.ts index 555362c378..89879393b9 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.editorUpdate.spec.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.editorUpdate.spec.ts @@ -13,10 +13,10 @@ import { container } from '../../../../inversify.config'; import { DevWorkspaceClient } from '../devWorkspaceClient'; import mockAxios from 'axios'; -import { dashboardBackendPrefix } from '../../../dashboard-backend-client/const'; +import { dashboardBackendPrefix } from '../../../backend-client/const'; import getDevWorkspaceTemplate from './__mocks__/devWorkspaceSpecTemplates'; import devfileApi from '../../../devfileApi'; -import * as DwtApi from '../../../dashboard-backend-client/devWorkspaceTemplateApi'; +import * as DwtApi from '../../../backend-client/devWorkspaceTemplateApi'; describe('DevWorkspace client editor update', () => { const namespace = 'admin-che'; diff --git a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.onStart.spec.ts b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.onStart.spec.ts index 223b1836cd..54fffda36d 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.onStart.spec.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.onStart.spec.ts @@ -13,7 +13,7 @@ import { container } from '../../../../inversify.config'; import { DevWorkspaceBuilder } from '../../../../store/__mocks__/devWorkspaceBuilder'; import { DevWorkspaceClient } from '../devWorkspaceClient'; -import * as DwApi from '../../../dashboard-backend-client/devWorkspaceApi'; +import * as DwApi from '../../../backend-client/devWorkspaceApi'; import mockAxios from 'axios'; /* eslint-disable @typescript-eslint/no-non-null-assertion */ diff --git a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.update.spec.ts b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.update.spec.ts index 72eb58f9fe..59a3b1ea18 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.update.spec.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/__tests__/devWorkspaceClient.update.spec.ts @@ -13,7 +13,7 @@ import { container } from '../../../../inversify.config'; import { DevWorkspaceBuilder } from '../../../../store/__mocks__/devWorkspaceBuilder'; import { DevWorkspaceClient } from '../devWorkspaceClient'; -import * as DwApi from '../../../dashboard-backend-client/devWorkspaceApi'; +import * as DwApi from '../../../backend-client/devWorkspaceApi'; describe('DevWorkspace client, update', () => { let client: DevWorkspaceClient; diff --git a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/devWorkspaceClient.ts b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/devWorkspaceClient.ts index 629ce1cc2e..b4c523dfef 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/devworkspace/devWorkspaceClient.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/devworkspace/devWorkspaceClient.ts @@ -21,8 +21,8 @@ import { WorkspacesDefaultPlugins } from 'dashboard-frontend/src/store/Plugins/d import { decorate, inject, injectable } from 'inversify'; import { load } from 'js-yaml'; import { cloneDeep, isEqual } from 'lodash'; -import * as DwApi from '../../dashboard-backend-client/devWorkspaceApi'; -import * as DwtApi from '../../dashboard-backend-client/devWorkspaceTemplateApi'; +import * as DwApi from '../../backend-client/devWorkspaceApi'; +import * as DwtApi from '../../backend-client/devWorkspaceTemplateApi'; import devfileApi from '../../devfileApi'; import { DEVWORKSPACE_CHE_EDITOR, @@ -38,7 +38,6 @@ import { isWebTerminal } from '../../helpers/devworkspace'; import { DevWorkspaceStatus } from '../../helpers/types'; import { fetchData } from '../../registry/fetchData'; import { WorkspaceAdapter } from '../../workspace-adapter'; -import { WorkspaceClient } from '../index'; import { devWorkspaceApiGroup, devWorkspaceSingularSubresource, @@ -73,13 +72,11 @@ export interface ICheEditorYaml { }; } -decorate(injectable(), WorkspaceClient); - /** * This class manages the connection between the frontend and the devworkspace typescript library */ @injectable() -export class DevWorkspaceClient extends WorkspaceClient { +export class DevWorkspaceClient { private readonly maxStatusAttempts: number; private readonly pluginRegistryUrlEnvName: string; private readonly pluginRegistryInternalUrlEnvName: string; @@ -93,7 +90,6 @@ export class DevWorkspaceClient extends WorkspaceClient { @inject(DevWorkspaceDefaultPluginsHandler) defaultPluginsHandler: DevWorkspaceDefaultPluginsHandler, ) { - super(); this.maxStatusAttempts = 10; this.pluginRegistryUrlEnvName = 'CHE_PLUGIN_REGISTRY_URL'; this.pluginRegistryInternalUrlEnvName = 'CHE_PLUGIN_REGISTRY_INTERNAL_URL'; diff --git a/packages/dashboard-frontend/src/services/workspace-client/helpers.ts b/packages/dashboard-frontend/src/services/workspace-client/helpers.ts index 847816c313..3130a45a09 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/helpers.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/helpers.ts @@ -14,7 +14,6 @@ import common from '@eclipse-che/common'; import devfileApi, { isDevfileV2 } from '../devfileApi'; import { load, dump } from 'js-yaml'; import { ICheEditorYaml } from './devworkspace/devWorkspaceClient'; -import { CHE_EDITOR_YAML_PATH } from './'; import { AppState } from '../../store'; import { ThunkDispatch } from 'redux-thunk'; import { KnownAction } from '../../store/DevfileRegistries'; @@ -73,6 +72,8 @@ function hasStatus(response: unknown, _status: number): boolean { return false; } +export const CHE_EDITOR_YAML_PATH = '.che/che-editor.yaml'; + /** * Look for the custom editor in .che/che-editor.yaml */ diff --git a/packages/dashboard-frontend/src/services/workspace-client/index.ts b/packages/dashboard-frontend/src/services/workspace-client/index.ts deleted file mode 100644 index b708ea0097..0000000000 --- a/packages/dashboard-frontend/src/services/workspace-client/index.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018-2023 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ - -import { default as WorkspaceClientLib } from '@eclipse-che/workspace-client'; -import axios, { AxiosInstance } from 'axios'; - -export const CHE_EDITOR_YAML_PATH = '.che/che-editor.yaml'; - -/** - * This class manages the common functions between the che workspace client and the devworkspace client - */ -export abstract class WorkspaceClient { - protected readonly axios: AxiosInstance; - - protected constructor() { - // change this temporary solution after adding the proper method to workspace-client https://github.com/eclipse/che/issues/18311 - this.axios = (WorkspaceClientLib as any).createAxiosInstance({ loggingEnabled: false }); - - // workspaceClientLib axios interceptor - this.axios.interceptors.response.use( - response => response, - async error => { - // any status codes that falls outside the range of 2xx - return Promise.reject(error); - }, - ); - - // dashboard-backend axios interceptor - axios.interceptors.response.use( - response => response, - async error => { - // any status codes that falls outside the range of 2xx - return Promise.reject(error); - }, - ); - } -} diff --git a/packages/dashboard-frontend/src/store/BannerAlert/index.ts b/packages/dashboard-frontend/src/store/BannerAlert/index.ts index 2bcac8a609..65c9961a26 100644 --- a/packages/dashboard-frontend/src/store/BannerAlert/index.ts +++ b/packages/dashboard-frontend/src/store/BannerAlert/index.ts @@ -71,13 +71,13 @@ export const reducer: Reducer = ( switch (action.type) { case 'ADD_BANNER': - return createObject(state, { + return createObject(state, { messages: state.messages.includes(action.message) ? state.messages : state.messages.concat([action.message]), }); case 'REMOVE_BANNER': - return createObject(state, { + return createObject(state, { messages: state.messages.includes(action.message) ? state.messages.filter(message => message !== action.message) : state.messages, diff --git a/packages/dashboard-frontend/src/store/Branding/index.ts b/packages/dashboard-frontend/src/store/Branding/index.ts index 5d0ae02010..4991d2b878 100644 --- a/packages/dashboard-frontend/src/store/Branding/index.ts +++ b/packages/dashboard-frontend/src/store/Branding/index.ts @@ -117,17 +117,17 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case 'REQUEST_BRANDING': - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case 'RECEIVED_BRANDING': - return createObject(state, { + return createObject(state, { isLoading: false, data: action.data, }); case 'RECEIVED_BRANDING_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/ClusterConfig/index.ts b/packages/dashboard-frontend/src/store/ClusterConfig/index.ts index e6e10ec318..616dc2dcbc 100644 --- a/packages/dashboard-frontend/src/store/ClusterConfig/index.ts +++ b/packages/dashboard-frontend/src/store/ClusterConfig/index.ts @@ -15,7 +15,7 @@ import common, { ClusterConfig } from '@eclipse-che/common'; import { AppThunk } from '..'; import { createObject } from '../helpers'; import * as BannerAlertStore from '../BannerAlert'; -import { fetchClusterConfig } from '../../services/dashboard-backend-client/clusterConfigApi'; +import { fetchClusterConfig } from '../../services/backend-client/clusterConfigApi'; import { AddBannerAction } from '../BannerAlert'; import { AUTHORIZED, SanityCheckAction } from '../sanityCheckMiddleware'; @@ -105,17 +105,17 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_CLUSTER_CONFIG: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_CLUSTER_CONFIG: - return createObject(state, { + return createObject(state, { isLoading: false, clusterConfig: action.clusterConfig, }); case Type.RECEIVE_CLUSTER_CONFIG_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/ClusterInfo/index.ts b/packages/dashboard-frontend/src/store/ClusterInfo/index.ts index b1593808df..62d78ff2d5 100644 --- a/packages/dashboard-frontend/src/store/ClusterInfo/index.ts +++ b/packages/dashboard-frontend/src/store/ClusterInfo/index.ts @@ -14,7 +14,7 @@ import { Action, Reducer } from 'redux'; import common, { ClusterInfo } from '@eclipse-che/common'; import { AppThunk } from '..'; import { createObject } from '../helpers'; -import { fetchClusterInfo } from '../../services/dashboard-backend-client/clusterInfoApi'; +import { fetchClusterInfo } from '../../services/backend-client/clusterInfoApi'; import { AUTHORIZED, SanityCheckAction } from '../sanityCheckMiddleware'; export interface State { @@ -97,17 +97,17 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_CLUSTER_INFO: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_CLUSTER_INFO: - return createObject(state, { + return createObject(state, { isLoading: false, clusterInfo: action.clusterInfo, }); case Type.RECEIVE_CLUSTER_INFO_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/DevfileRegistries/fetchAndUpdateDevfileSchema.ts b/packages/dashboard-frontend/src/store/DevfileRegistries/fetchAndUpdateDevfileSchema.ts index 9f0c4ae6b1..2c8c0e78b9 100644 --- a/packages/dashboard-frontend/src/store/DevfileRegistries/fetchAndUpdateDevfileSchema.ts +++ b/packages/dashboard-frontend/src/store/DevfileRegistries/fetchAndUpdateDevfileSchema.ts @@ -11,7 +11,7 @@ */ import { JSONSchema7 } from 'json-schema'; -import { getDevfileSchema } from '../../services/dashboard-backend-client/devWorkspaceApi'; +import { getDevfileSchema } from '../../services/backend-client/devWorkspaceApi'; export default async function fetchAndUpdateDevfileSchema( schemaVersion: string, diff --git a/packages/dashboard-frontend/src/store/DevfileRegistries/index.ts b/packages/dashboard-frontend/src/store/DevfileRegistries/index.ts index f8980f7b40..1363e8628c 100644 --- a/packages/dashboard-frontend/src/store/DevfileRegistries/index.ts +++ b/packages/dashboard-frontend/src/store/DevfileRegistries/index.ts @@ -319,24 +319,24 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_REGISTRY_METADATA: - return createObject(state, { + return createObject(state, { isLoading: true, }); case Type.REQUEST_SCHEMA: - return createObject(state, { + return createObject(state, { isLoading: true, schema: {}, }); case Type.REQUEST_DEVFILE: - return createObject(state, { + return createObject(state, { isLoading: true, }); case Type.REQUEST_RESOURCES: - return createObject(state, { + return createObject(state, { isLoading: true, }); case Type.RECEIVE_REGISTRY_METADATA: - return createObject(state, { + return createObject(state, { isLoading: false, registries: createObject(state.registries, { [action.url]: { @@ -345,7 +345,7 @@ export const reducer: Reducer = ( }), }); case Type.RECEIVE_REGISTRY_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, registries: { [action.url]: { @@ -354,7 +354,7 @@ export const reducer: Reducer = ( }, }); case Type.RECEIVE_DEVFILE: - return createObject(state, { + return createObject(state, { isLoading: false, devfiles: createObject(state.devfiles, { [action.url]: { @@ -363,7 +363,7 @@ export const reducer: Reducer = ( }), }); case Type.RECEIVE_RESOURCES: - return createObject(state, { + return createObject(state, { isLoading: false, devWorkspaceResources: createObject(state.devWorkspaceResources, { [action.url]: { @@ -372,7 +372,7 @@ export const reducer: Reducer = ( }), }); case Type.RECEIVE_RESOURCES_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, devWorkspaceResources: { [action.url]: { @@ -381,26 +381,26 @@ export const reducer: Reducer = ( }, }); case Type.RECEIVE_SCHEMA: - return createObject(state, { + return createObject(state, { isLoading: false, schema: { schema: action.schema, }, }); case Type.RECEIVE_SCHEMA_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, schema: { error: action.error, }, }); case Type.SET_FILTER: { - return createObject(state, { + return createObject(state, { filter: action.value, }); } case Type.CLEAR_FILTER: { - return createObject(state, { + return createObject(state, { filter: '', }); } diff --git a/packages/dashboard-frontend/src/store/DockerConfig/index.ts b/packages/dashboard-frontend/src/store/DockerConfig/index.ts index 453e045561..083339451e 100644 --- a/packages/dashboard-frontend/src/store/DockerConfig/index.ts +++ b/packages/dashboard-frontend/src/store/DockerConfig/index.ts @@ -14,7 +14,7 @@ import { Action, Reducer } from 'redux'; import { api, helpers } from '@eclipse-che/common'; import { AppThunk } from '..'; import { createObject } from '../helpers'; -import * as DwApi from '../../services/dashboard-backend-client/devWorkspaceApi'; +import * as DwApi from '../../services/backend-client/devWorkspaceApi'; import { RegistryEntry } from './types'; import { State } from './dockerConfigState'; import { AUTHORIZED, SanityCheckAction } from '../sanityCheckMiddleware'; @@ -166,18 +166,18 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case 'REQUEST_DEVWORKSPACE_CREDENTIALS': - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case 'SET_DEVWORKSPACE_CREDENTIALS': - return createObject(state, { + return createObject(state, { isLoading: false, registries: action.registries, resourceVersion: action.resourceVersion, }); case 'RECEIVE_DEVWORKSPACE_CREDENTIALS_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/Events/__tests__/actions.spec.ts b/packages/dashboard-frontend/src/store/Events/__tests__/actions.spec.ts index 6679b20abd..01b8e36845 100644 --- a/packages/dashboard-frontend/src/store/Events/__tests__/actions.spec.ts +++ b/packages/dashboard-frontend/src/store/Events/__tests__/actions.spec.ts @@ -18,7 +18,7 @@ import { ThunkDispatch } from 'redux-thunk'; import * as testStore from '..'; import { AppState } from '../..'; import { container } from '../../../inversify.config'; -import { WebsocketClient } from '../../../services/dashboard-backend-client/websocketClient'; +import { WebsocketClient } from '../../../services/backend-client/websocketClient'; import { AUTHORIZED } from '../../sanityCheckMiddleware'; import { FakeStoreBuilder } from '../../__mocks__/storeBuilder'; import { event1, event2 } from './stubs'; diff --git a/packages/dashboard-frontend/src/store/Events/index.ts b/packages/dashboard-frontend/src/store/Events/index.ts index cb0a5b8c5b..a1d6c12978 100644 --- a/packages/dashboard-frontend/src/store/Events/index.ts +++ b/packages/dashboard-frontend/src/store/Events/index.ts @@ -15,8 +15,8 @@ import { CoreV1Event } from '@kubernetes/client-node'; import { Action, Reducer } from 'redux'; import { AppThunk } from '..'; import { container } from '../../inversify.config'; -import { fetchEvents } from '../../services/dashboard-backend-client/eventsApi'; -import { WebsocketClient } from '../../services/dashboard-backend-client/websocketClient'; +import { fetchEvents } from '../../services/backend-client/eventsApi'; +import { WebsocketClient } from '../../services/backend-client/websocketClient'; import { getNewerResourceVersion } from '../../services/helpers/resourceVersion'; import { createObject } from '../helpers'; import { selectDefaultNamespace } from '../InfrastructureNamespaces/selectors'; @@ -188,18 +188,18 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_EVENTS: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_EVENTS: - return createObject(state, { + return createObject(state, { isLoading: false, events: state.events.concat(action.events), resourceVersion: getNewerResourceVersion(action.resourceVersion, state.resourceVersion), }); case Type.MODIFY_EVENT: - return createObject(state, { + return createObject(state, { events: state.events.map(event => { if (event.metadata.uid === action.event.metadata.uid) { return action.event; @@ -212,7 +212,7 @@ export const reducer: Reducer = ( ), }); case Type.DELETE_EVENT: - return createObject(state, { + return createObject(state, { events: state.events.filter(event => event.metadata.uid !== action.event.metadata.uid), resourceVersion: getNewerResourceVersion( action.event.metadata.resourceVersion, @@ -220,7 +220,7 @@ export const reducer: Reducer = ( ), }); case Type.RECEIVE_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/FactoryResolver/__tests__/index.spec.ts b/packages/dashboard-frontend/src/store/FactoryResolver/__tests__/index.spec.ts index 3e60c7fc4f..c2a3126a05 100644 --- a/packages/dashboard-frontend/src/store/FactoryResolver/__tests__/index.spec.ts +++ b/packages/dashboard-frontend/src/store/FactoryResolver/__tests__/index.spec.ts @@ -16,7 +16,7 @@ import common from '@eclipse-che/common'; import { AppState } from '../..'; import { FakeStoreBuilder } from '../../__mocks__/storeBuilder'; import devfileApi from '../../../services/devfileApi'; -import * as factoryResolver from '../../../services/dashboard-backend-client/factoryResolverApi'; +import * as factoryResolver from '../../../services/backend-client/factoryApi'; import * as factoryResolverStore from '..'; import { AxiosError } from 'axios'; import normalizeDevfileV1 from '../normalizeDevfileV1'; @@ -26,7 +26,7 @@ import { convertDevfileV1toDevfileV2, } from '../../../services/devfile/converters'; import { AUTHORIZED } from '../../sanityCheckMiddleware'; -import * as yamlResolver from '../../../services/dashboard-backend-client/yamlResolverApi'; +import * as yamlResolver from '../../../services/backend-client/yamlResolverApi'; jest.mock('../normalizeDevfileV1.ts'); (normalizeDevfileV1 as jest.Mock).mockImplementation(devfile => { diff --git a/packages/dashboard-frontend/src/store/FactoryResolver/index.ts b/packages/dashboard-frontend/src/store/FactoryResolver/index.ts index f390dab1ef..f99303dc0a 100644 --- a/packages/dashboard-frontend/src/store/FactoryResolver/index.ts +++ b/packages/dashboard-frontend/src/store/FactoryResolver/index.ts @@ -22,13 +22,13 @@ import { convertDevfileV1toDevfileV2 } from '../../services/devfile/converters'; import normalizeDevfileV2 from './normalizeDevfileV2'; import normalizeDevfileV1 from './normalizeDevfileV1'; import { selectDefaultNamespace } from '../InfrastructureNamespaces/selectors'; -import { getYamlResolver } from '../../services/dashboard-backend-client/yamlResolverApi'; +import { getYamlResolver } from '../../services/backend-client/yamlResolverApi'; import { DEFAULT_REGISTRY } from '../DevfileRegistries'; import { isOAuthResponse } from '../../services/oauth'; import { AUTHORIZED, SanityCheckAction } from '../sanityCheckMiddleware'; -import { CHE_EDITOR_YAML_PATH } from '../../services/workspace-client'; +import { CHE_EDITOR_YAML_PATH } from '../../services/workspace-client/helpers'; import { FactoryParams } from '../../services/helpers/factoryFlow/buildFactoryParams'; -import { getFactoryResolver } from '../../services/dashboard-backend-client/factoryResolverApi'; +import { getFactoryResolver } from '../../services/backend-client/factoryApi'; export type OAuthResponse = { attributes: { @@ -245,18 +245,18 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case 'REQUEST_FACTORY_RESOLVER': - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case 'RECEIVE_FACTORY_RESOLVER': - return createObject(state, { + return createObject(state, { isLoading: false, resolver: action.resolver, converted: action.converted, }); case 'RECEIVE_FACTORY_RESOLVER_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/GitOauthConfig/index.ts b/packages/dashboard-frontend/src/store/GitOauthConfig/index.ts index 500add1964..6622d449d3 100644 --- a/packages/dashboard-frontend/src/store/GitOauthConfig/index.ts +++ b/packages/dashboard-frontend/src/store/GitOauthConfig/index.ts @@ -15,9 +15,12 @@ import common, { api } from '@eclipse-che/common'; import { AppThunk } from '..'; import { createObject } from '../helpers'; import { AUTHORIZED } from '../sanityCheckMiddleware'; -import { container } from '../../inversify.config'; -import { CheWorkspaceClient } from '../../services/workspace-client/cheworkspace/cheWorkspaceClient'; import { IGitOauth } from './types'; +import { + deleteOAuthToken, + getOAuthProviders, + getOAuthToken, +} from '../../services/backend-client/oAuthApi'; export interface State { isLoading: boolean; @@ -25,8 +28,6 @@ export interface State { error: string | undefined; } -const cheWorkspaceClient = container.get(CheWorkspaceClient); - export enum Type { REQUEST_GIT_OAUTH_CONFIG = 'REQUEST_GIT_OAUTH_CONFIG', DELETE_OAUTH = 'DELETE_OAUTH', @@ -74,11 +75,11 @@ export const actionCreators: ActionCreators = { }); const gitOauth: IGitOauth[] = []; try { - const oAuthProviders = await cheWorkspaceClient.restApiClient.getOAuthProviders(); + const oAuthProviders = await getOAuthProviders(); const promises: Promise[] = []; for (const { name, endpointUrl } of oAuthProviders) { promises.push( - cheWorkspaceClient.restApiClient.getOAuthToken(name).then(() => { + getOAuthToken(name).then(() => { gitOauth.push({ name: name as api.GitOauthProvider, endpointUrl, @@ -110,7 +111,7 @@ export const actionCreators: ActionCreators = { check: AUTHORIZED, }); try { - await cheWorkspaceClient.restApiClient.deleteOAuthToken(oauthProvider); + await deleteOAuthToken(oauthProvider); dispatch({ type: Type.DELETE_OAUTH, provider: oauthProvider, @@ -143,22 +144,22 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_GIT_OAUTH_CONFIG: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_GIT_OAUTH_CONFIG: - return createObject(state, { + return createObject(state, { isLoading: false, gitOauth: action.gitOauth, }); case Type.DELETE_OAUTH: - return createObject(state, { + return createObject(state, { isLoading: false, gitOauth: state.gitOauth.filter(v => v.name !== action.provider), }); case Type.RECEIVE_GIT_OAUTH_CONFIG_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/InfrastructureNamespaces/index.ts b/packages/dashboard-frontend/src/store/InfrastructureNamespaces/index.ts index 9aadd84314..66b3fcb7b3 100644 --- a/packages/dashboard-frontend/src/store/InfrastructureNamespaces/index.ts +++ b/packages/dashboard-frontend/src/store/InfrastructureNamespaces/index.ts @@ -12,13 +12,10 @@ import { Action, Reducer } from 'redux'; import common from '@eclipse-che/common'; -import { container } from '../../inversify.config'; -import { CheWorkspaceClient } from '../../services/workspace-client/cheworkspace/cheWorkspaceClient'; import { AppThunk } from '..'; import { createObject } from '../helpers'; import { AUTHORIZED, SanityCheckAction } from '../sanityCheckMiddleware'; - -const WorkspaceClient = container.get(CheWorkspaceClient); +import { getKubernetesNamespace } from '../../services/backend-client/kubernetesNamespaceApi'; export interface State { isLoading: boolean; @@ -53,10 +50,7 @@ export const actionCreators: ActionCreators = { await dispatch({ type: 'REQUEST_NAMESPACES', check: AUTHORIZED }); try { - const namespaces = - await WorkspaceClient.restApiClient.getKubernetesNamespace< - Array - >(); + const namespaces = await getKubernetesNamespace(); dispatch({ type: 'RECEIVE_NAMESPACES', namespaces, @@ -91,17 +85,17 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case 'REQUEST_NAMESPACES': - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case 'RECEIVE_NAMESPACES': - return createObject(state, { + return createObject(state, { isLoading: false, namespaces: action.namespaces, }); case 'RECEIVE_NAMESPACES_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/PersonalAccessToken/__tests__/actions.spec.ts b/packages/dashboard-frontend/src/store/PersonalAccessToken/__tests__/actions.spec.ts index 80a300b394..ddbdada66e 100644 --- a/packages/dashboard-frontend/src/store/PersonalAccessToken/__tests__/actions.spec.ts +++ b/packages/dashboard-frontend/src/store/PersonalAccessToken/__tests__/actions.spec.ts @@ -17,21 +17,23 @@ import { AppState } from '../..'; import { AUTHORIZED } from '../../sanityCheckMiddleware'; import { FakeStoreBuilder } from '../../__mocks__/storeBuilder'; import { token1, token2 } from './stub'; -import * as PersonalAccessTokenApi from '../../../services/dashboard-backend-client/personalAccessTokenApi'; -import { container } from '../../../inversify.config'; -import { CheWorkspaceClient } from '../../../services/workspace-client/cheworkspace/cheWorkspaceClient'; +import * as PersonalAccessTokenApi from '../../../services/backend-client/personalAccessTokenApi'; +import * as KubernetesNamespaceApi from '../../../services/backend-client/kubernetesNamespaceApi'; -const cheWorkspaceClient = container.get(CheWorkspaceClient); -jest - .spyOn(cheWorkspaceClient.restApiClient, 'provisionKubernetesNamespace') - .mockImplementation(() => Promise.resolve({} as che.KubernetesNamespace)); +jest.mock( + '../../../services/backend-client/kubernetesNamespaceApi', + () => + ({ + provisionKubernetesNamespace: () => Promise.resolve({} as che.KubernetesNamespace), + }) as typeof KubernetesNamespaceApi, +); const mockFetchTokens = jest.fn(); const mockAddToken = jest.fn(); const mockUpdateToken = jest.fn(); const mockRemoveToken = jest.fn(); jest.mock( - '../../../services/dashboard-backend-client/personalAccessTokenApi', + '../../../services/backend-client/personalAccessTokenApi', () => ({ fetchTokens: (...args) => mockFetchTokens(...args), diff --git a/packages/dashboard-frontend/src/store/PersonalAccessToken/index.ts b/packages/dashboard-frontend/src/store/PersonalAccessToken/index.ts index 52773b06d5..dfba043a9c 100644 --- a/packages/dashboard-frontend/src/store/PersonalAccessToken/index.ts +++ b/packages/dashboard-frontend/src/store/PersonalAccessToken/index.ts @@ -13,23 +13,20 @@ import { api, helpers } from '@eclipse-che/common'; import { Action, Reducer } from 'redux'; import { AppThunk } from '..'; -import { container } from '../../inversify.config'; import { addToken, fetchTokens, removeToken, updateToken, -} from '../../services/dashboard-backend-client/personalAccessTokenApi'; -import { CheWorkspaceClient } from '../../services/workspace-client/cheworkspace/cheWorkspaceClient'; +} from '../../services/backend-client/personalAccessTokenApi'; import { createObject } from '../helpers'; import { selectDefaultNamespace } from '../InfrastructureNamespaces/selectors'; import { AUTHORIZED, SanityCheckAction } from '../sanityCheckMiddleware'; import { State } from './state'; +import { provisionKubernetesNamespace } from '../../services/backend-client/kubernetesNamespaceApi'; export * from './state'; -const WorkspaceClient = container.get(CheWorkspaceClient); - export enum Type { RECEIVE_ERROR = 'RECEIVE_ERROR', RECEIVE_TOKENS = 'RECEIVE_TOKENS', @@ -90,7 +87,7 @@ export const actionCreators: ActionCreators = { const state = getState(); const namespace = selectDefaultNamespace(state).name; - await dispatch({ + dispatch({ type: Type.REQUEST_TOKENS, check: AUTHORIZED, }); @@ -117,7 +114,7 @@ export const actionCreators: ActionCreators = { const state = getState(); const namespace = selectDefaultNamespace(state).name; - await dispatch({ + dispatch({ type: Type.REQUEST_TOKENS, check: AUTHORIZED, }); @@ -135,8 +132,7 @@ export const actionCreators: ActionCreators = { } /* request namespace provision as it triggers tokens validation */ - - await WorkspaceClient.restApiClient.provisionKubernetesNamespace(); + await provisionKubernetesNamespace(); /* check if the new token is available */ @@ -164,7 +160,7 @@ export const actionCreators: ActionCreators = { const state = getState(); const namespace = selectDefaultNamespace(state).name; - await dispatch({ + dispatch({ type: Type.REQUEST_TOKENS, check: AUTHORIZED, }); @@ -191,7 +187,7 @@ export const actionCreators: ActionCreators = { const state = getState(); const namespace = selectDefaultNamespace(state).name; - await dispatch({ + dispatch({ type: Type.REQUEST_TOKENS, check: AUTHORIZED, }); @@ -229,34 +225,34 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_TOKENS: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_TOKENS: - return createObject(state, { + return createObject(state, { isLoading: false, tokens: action.tokens, }); case Type.ADD_TOKEN: - return createObject(state, { + return createObject(state, { isLoading: false, tokens: [...state.tokens, action.token], }); case Type.UPDATE_TOKEN: - return createObject(state, { + return createObject(state, { isLoading: false, tokens: state.tokens.map(token => token.tokenName === action.token.tokenName ? action.token : token, ), }); case Type.REMOVE_TOKEN: - return createObject(state, { + return createObject(state, { isLoading: false, tokens: state.tokens.filter(token => token.tokenName !== action.token.tokenName), }); case Type.RECEIVE_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/Plugins/chePlugins/index.ts b/packages/dashboard-frontend/src/store/Plugins/chePlugins/index.ts index 05148122fa..545702b32d 100644 --- a/packages/dashboard-frontend/src/store/Plugins/chePlugins/index.ts +++ b/packages/dashboard-frontend/src/store/Plugins/chePlugins/index.ts @@ -93,17 +93,17 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case 'REQUEST_PLUGINS': - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case 'RECEIVE_PLUGINS': - return createObject(state, { + return createObject(state, { isLoading: false, plugins: action.plugins, }); case 'RECEIVE_PLUGINS_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/Plugins/devWorkspacePlugins/index.ts b/packages/dashboard-frontend/src/store/Plugins/devWorkspacePlugins/index.ts index 6b65d1915b..59db6b12d6 100644 --- a/packages/dashboard-frontend/src/store/Plugins/devWorkspacePlugins/index.ts +++ b/packages/dashboard-frontend/src/store/Plugins/devWorkspacePlugins/index.ts @@ -127,7 +127,7 @@ export const actionCreators: ActionCreators = { requestDwDevfile: (url: string): AppThunk> => async (dispatch): Promise => { - await dispatch({ + dispatch({ type: 'REQUEST_DW_PLUGIN', check: AUTHORIZED, url, @@ -177,7 +177,7 @@ export const actionCreators: ActionCreators = { } try { - await dispatch({ + dispatch({ type: 'REQUEST_DW_EDITOR', check: AUTHORIZED, url: editorUrl, @@ -208,7 +208,7 @@ export const actionCreators: ActionCreators = { async (dispatch, getState): Promise => { const config = getState().dwServerConfig.config; const defaultEditor = config.defaults.editor; - await dispatch({ + dispatch({ type: 'REQUEST_DW_DEFAULT_EDITOR', check: AUTHORIZED, }); @@ -223,7 +223,7 @@ export const actionCreators: ActionCreators = { throw errorMessage; } - const defaultEditorUrl = defaultEditor.startsWith('https://') + const defaultEditorUrl = (defaultEditor as string).startsWith('https://') ? defaultEditor : `${config.pluginRegistryURL}/plugins/${defaultEditor}/devfile.yaml`; @@ -240,7 +240,7 @@ export const actionCreators: ActionCreators = { requestDwDefaultPlugins: (): AppThunk> => async (dispatch, getState): Promise => { - await dispatch({ + dispatch({ type: 'REQUEST_DW_DEFAULT_PLUGINS', check: AUTHORIZED, }); @@ -280,7 +280,7 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case 'REQUEST_DW_PLUGIN': - return createObject(state, { + return createObject(state, { isLoading: true, plugins: { [action.url]: { @@ -291,7 +291,7 @@ export const reducer: Reducer = ( }, }); case 'REQUEST_DW_EDITOR': - return createObject(state, { + return createObject(state, { isLoading: true, editors: createObject(state.editors, { [action.editorName]: { @@ -301,13 +301,13 @@ export const reducer: Reducer = ( }), }); case 'REQUEST_DW_DEFAULT_EDITOR': - return createObject(state, { + return createObject(state, { isLoading: true, defaultEditorName: undefined, defaultEditorError: undefined, }); case 'RECEIVE_DW_PLUGIN': - return createObject(state, { + return createObject(state, { isLoading: false, plugins: { [action.url]: { @@ -317,7 +317,7 @@ export const reducer: Reducer = ( }, }); case 'RECEIVE_DW_EDITOR': - return createObject(state, { + return createObject(state, { isLoading: false, editors: createObject(state.editors, { [action.editorName]: { @@ -327,7 +327,7 @@ export const reducer: Reducer = ( }), }); case 'RECEIVE_DW_EDITOR_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, editors: { [action.editorName]: { @@ -338,7 +338,7 @@ export const reducer: Reducer = ( }); case 'RECEIVE_DW_PLUGIN_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, plugins: { [action.url]: { @@ -350,21 +350,21 @@ export const reducer: Reducer = ( }, }); case 'RECEIVE_DW_DEFAULT_EDITOR_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, defaultEditorError: action.error, }); case 'RECEIVE_DW_DEFAULT_EDITOR': - return createObject(state, { + return createObject(state, { isLoading: false, defaultEditorName: action.defaultEditorName, }); case 'REQUEST_DW_DEFAULT_PLUGINS': - return createObject(state, { + return createObject(state, { isLoading: true, }); case 'RECEIVE_DW_DEFAULT_PLUGINS': - return createObject(state, { + return createObject(state, { isLoading: false, defaultPlugins: action.defaultPlugins, }); diff --git a/packages/dashboard-frontend/src/store/Pods/Logs/__tests__/actions.spec.ts b/packages/dashboard-frontend/src/store/Pods/Logs/__tests__/actions.spec.ts index 17ca36e379..6ea27c9698 100644 --- a/packages/dashboard-frontend/src/store/Pods/Logs/__tests__/actions.spec.ts +++ b/packages/dashboard-frontend/src/store/Pods/Logs/__tests__/actions.spec.ts @@ -19,7 +19,7 @@ import { ThunkDispatch } from 'redux-thunk'; import * as testStore from '..'; import { AppState } from '../../..'; import { container } from '../../../../inversify.config'; -import { WebsocketClient } from '../../../../services/dashboard-backend-client/websocketClient'; +import { WebsocketClient } from '../../../../services/backend-client/websocketClient'; import { FakeStoreBuilder } from '../../../__mocks__/storeBuilder'; describe('Pod logs store, actions', () => { diff --git a/packages/dashboard-frontend/src/store/Pods/Logs/index.ts b/packages/dashboard-frontend/src/store/Pods/Logs/index.ts index 490e5a3650..d43e5f26fe 100644 --- a/packages/dashboard-frontend/src/store/Pods/Logs/index.ts +++ b/packages/dashboard-frontend/src/store/Pods/Logs/index.ts @@ -15,8 +15,8 @@ import { V1Pod } from '@kubernetes/client-node'; import { Action, Reducer } from 'redux'; import { AppThunk } from '../..'; import { container } from '../../../inversify.config'; -import { WebsocketClient } from '../../../services/dashboard-backend-client/websocketClient'; -import { ChannelListener } from '../../../services/dashboard-backend-client/websocketClient/messageHandler'; +import { WebsocketClient } from '../../../services/backend-client/websocketClient'; +import { ChannelListener } from '../../../services/backend-client/websocketClient/messageHandler'; import { createObject } from '../../helpers'; import { selectDefaultNamespace } from '../../InfrastructureNamespaces/selectors'; import { selectAllPods } from '../selectors'; @@ -193,11 +193,11 @@ export const reducer: Reducer = ( const _containers = _pod?.containers; const _containerLogs = _containers?.[action.containerName]; const _logs = action.failure === _containerLogs?.failure ? _containerLogs.logs : ''; - return createObject(state, { + return createObject(state, { logs: createObject(state.logs, { - [action.podName]: createObject(_pod, { + [action.podName]: createObject(_pod, { error: undefined, - containers: createObject(_containers, { + containers: createObject(_containers, { [action.containerName]: { logs: _logs + action.logs, failure: action.failure, @@ -208,7 +208,7 @@ export const reducer: Reducer = ( }); } case Type.DELETE_LOGS: - return createObject(state, { + return createObject(state, { logs: createObject(state.logs, { [action.podName]: undefined, }), diff --git a/packages/dashboard-frontend/src/store/Pods/__tests__/actions.spec.ts b/packages/dashboard-frontend/src/store/Pods/__tests__/actions.spec.ts index b5299a2d0f..7b989aa070 100644 --- a/packages/dashboard-frontend/src/store/Pods/__tests__/actions.spec.ts +++ b/packages/dashboard-frontend/src/store/Pods/__tests__/actions.spec.ts @@ -18,7 +18,7 @@ import { ThunkDispatch } from 'redux-thunk'; import * as testStore from '..'; import { AppState } from '../..'; import { container } from '../../../inversify.config'; -import { WebsocketClient } from '../../../services/dashboard-backend-client/websocketClient'; +import { WebsocketClient } from '../../../services/backend-client/websocketClient'; import { AUTHORIZED } from '../../sanityCheckMiddleware'; import { FakeStoreBuilder } from '../../__mocks__/storeBuilder'; import { pod1, pod2 } from './stub'; diff --git a/packages/dashboard-frontend/src/store/Pods/index.ts b/packages/dashboard-frontend/src/store/Pods/index.ts index d4d0d09e46..624ae83009 100644 --- a/packages/dashboard-frontend/src/store/Pods/index.ts +++ b/packages/dashboard-frontend/src/store/Pods/index.ts @@ -15,8 +15,8 @@ import { V1Pod } from '@kubernetes/client-node'; import { Action, Reducer } from 'redux'; import { AppThunk } from '..'; import { container } from '../../inversify.config'; -import { fetchPods } from '../../services/dashboard-backend-client/podsApi'; -import { WebsocketClient } from '../../services/dashboard-backend-client/websocketClient'; +import { fetchPods } from '../../services/backend-client/podsApi'; +import { WebsocketClient } from '../../services/backend-client/websocketClient'; import { getNewerResourceVersion } from '../../services/helpers/resourceVersion'; import { createObject } from '../helpers'; import { selectDefaultNamespace } from '../InfrastructureNamespaces/selectors'; @@ -198,23 +198,23 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_PODS: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_PODS: - return createObject(state, { + return createObject(state, { isLoading: false, pods: action.pods, resourceVersion: getNewerResourceVersion(action.resourceVersion, state.resourceVersion), }); case Type.RECEIVE_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); case Type.RECEIVE_POD: - return createObject(state, { + return createObject(state, { pods: state.pods.concat([action.pod]), resourceVersion: getNewerResourceVersion( action.pod.metadata?.resourceVersion, @@ -222,7 +222,7 @@ export const reducer: Reducer = ( ), }); case Type.MODIFY_POD: - return createObject(state, { + return createObject(state, { pods: state.pods.map(pod => (isSamePod(pod, action.pod) ? action.pod : pod)), resourceVersion: getNewerResourceVersion( action.pod.metadata?.resourceVersion, @@ -230,7 +230,7 @@ export const reducer: Reducer = ( ), }); case Type.DELETE_POD: - return createObject(state, { + return createObject(state, { pods: state.pods.filter(pod => isSamePod(pod, action.pod) === false), resourceVersion: getNewerResourceVersion( action.pod.metadata?.resourceVersion, diff --git a/packages/dashboard-frontend/src/store/SanityCheck/index.ts b/packages/dashboard-frontend/src/store/SanityCheck/index.ts index b43807b09a..4638600cb2 100644 --- a/packages/dashboard-frontend/src/store/SanityCheck/index.ts +++ b/packages/dashboard-frontend/src/store/SanityCheck/index.ts @@ -13,14 +13,11 @@ import { Action, Reducer } from 'redux'; import { AppThunk } from '..'; import { helpers } from '@eclipse-che/common'; -import { container } from '../../inversify.config'; import { getDefer } from '../../services/helpers/deferred'; import { delay } from '../../services/helpers/delay'; -import { CheWorkspaceClient } from '../../services/workspace-client/cheworkspace/cheWorkspaceClient'; import { isForbidden, isUnauthorized } from '../../services/workspace-client/helpers'; import { createObject } from '../helpers'; - -const WorkspaceClient = container.get(CheWorkspaceClient); +import { provisionKubernetesNamespace } from '../../services/backend-client/kubernetesNamespaceApi'; const secToStale = 5; const timeToStale = secToStale * 1000; @@ -93,7 +90,7 @@ export const actionCreators: ActionCreators = { for (let attempt = 1; attempt <= maxAttemptsNumber; attempt++) { try { - await WorkspaceClient.restApiClient.provisionKubernetesNamespace(); + await provisionKubernetesNamespace(); deferred.resolve(true); dispatch({ @@ -148,15 +145,15 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_BACKEND_CHECK: - return createObject(state, { + return createObject(state, { error: undefined, authorized: action.authorized, lastFetched: action.lastFetched, }); case Type.RECEIVED_BACKEND_CHECK: - return createObject(state, {}); + return createObject(state, {}); case Type.RECEIVED_BACKEND_CHECK_ERROR: - return createObject(state, { + return createObject(state, { authorized: state.authorized, lastFetched: state.lastFetched, error: action.error, diff --git a/packages/dashboard-frontend/src/store/ServerConfig/index.ts b/packages/dashboard-frontend/src/store/ServerConfig/index.ts index a81b545bda..1041215e16 100644 --- a/packages/dashboard-frontend/src/store/ServerConfig/index.ts +++ b/packages/dashboard-frontend/src/store/ServerConfig/index.ts @@ -14,7 +14,7 @@ import { Action, Reducer } from 'redux'; import common, { api } from '@eclipse-che/common'; import { AppThunk } from '../'; import { createObject } from '../helpers'; -import * as ServerConfigApi from '../../services/dashboard-backend-client/serverConfigApi'; +import * as ServerConfigApi from '../../services/backend-client/serverConfigApi'; import { AUTHORIZED, SanityCheckAction } from '../sanityCheckMiddleware'; export interface State { @@ -112,17 +112,17 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case 'REQUEST_DW_SERVER_CONFIG': - return createObject(state, { + return createObject(state, { isLoading: true, }); case 'RECEIVE_DW_SERVER_CONFIG': - return createObject(state, { + return createObject(state, { isLoading: false, config: action.config, error: undefined, }); case 'RECEIVE_DW_SERVER_CONFIG_ERROR': - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/User/Id/index.ts b/packages/dashboard-frontend/src/store/User/Id/index.ts index 47391d31af..4827bcfe66 100644 --- a/packages/dashboard-frontend/src/store/User/Id/index.ts +++ b/packages/dashboard-frontend/src/store/User/Id/index.ts @@ -88,17 +88,17 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_CHE_USER_ID: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_CHE_USER_ID: - return createObject(state, { + return createObject(state, { isLoading: false, cheUserId: action.cheUserId, }); case Type.RECEIVE_CHE_USER_ID_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/User/Profile/index.ts b/packages/dashboard-frontend/src/store/User/Profile/index.ts index af906e3764..ccf0e7b474 100644 --- a/packages/dashboard-frontend/src/store/User/Profile/index.ts +++ b/packages/dashboard-frontend/src/store/User/Profile/index.ts @@ -14,7 +14,7 @@ import common, { api } from '@eclipse-che/common'; import { Action, Reducer } from 'redux'; -import { fetchUserProfile } from '../../../services/dashboard-backend-client/userProfileApi'; +import { fetchUserProfile } from '../../../services/backend-client/userProfileApi'; import { createObject } from '../../helpers'; import { AppThunk } from '../../index'; import { AUTHORIZED, SanityCheckAction } from '../../sanityCheckMiddleware'; @@ -99,17 +99,17 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_USER_PROFILE: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_USER_PROFILE: - return createObject(state, { + return createObject(state, { isLoading: false, userProfile: action.userProfile, }); case Type.RECEIVE_USER_PROFILE_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); diff --git a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/__tests__/actions.spec.ts b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/__tests__/actions.spec.ts index 86acb05e85..6add4b66d3 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/__tests__/actions.spec.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/__tests__/actions.spec.ts @@ -22,8 +22,8 @@ import * as testStore from '..'; import { AppState } from '../../..'; import { container } from '../../../../inversify.config'; import { FactoryParams } from '../../../../services/helpers/factoryFlow/buildFactoryParams'; -import { fetchServerConfig } from '../../../../services/dashboard-backend-client/serverConfigApi'; -import { WebsocketClient } from '../../../../services/dashboard-backend-client/websocketClient'; +import { fetchServerConfig } from '../../../../services/backend-client/serverConfigApi'; +import { WebsocketClient } from '../../../../services/backend-client/websocketClient'; import devfileApi from '../../../../services/devfileApi'; import { DevWorkspaceClient } from '../../../../services/workspace-client/devworkspace/devWorkspaceClient'; import { AUTHORIZED } from '../../../sanityCheckMiddleware'; @@ -33,13 +33,13 @@ import { FakeStoreBuilder } from '../../../__mocks__/storeBuilder'; import { checkRunningWorkspacesLimit } from '../checkRunningWorkspacesLimit'; import { DEVWORKSPACE_STORAGE_TYPE_ATTR } from '../../../../services/devfileApi/devWorkspace/spec/template'; -jest.mock('../../../../services/dashboard-backend-client/serverConfigApi'); +jest.mock('../../../../services/backend-client/serverConfigApi'); jest.mock('../../../../services/helpers/delay', () => ({ delay: jest.fn().mockResolvedValue(undefined), })); jest.mock('../checkRunningWorkspacesLimit.ts'); -jest.mock('../../../../services/dashboard-backend-client/devworkspaceResourcesApi', () => ({ +jest.mock('../../../../services/backend-client/devworkspaceResourcesApi', () => ({ fetchResources: () => ` apiVersion: workspace.devfile.io/v1alpha2 kind: DevWorkspaceTemplate @@ -95,7 +95,7 @@ spec: })); const mockPatchTemplate = jest.fn(); -jest.mock('../../../../services/dashboard-backend-client/devWorkspaceTemplateApi', () => ({ +jest.mock('../../../../services/backend-client/devWorkspaceTemplateApi', () => ({ getTemplates: () => [ { apiVersion: 'workspace.devfile.io/v1alpha2', @@ -111,7 +111,7 @@ jest.mock('../../../../services/dashboard-backend-client/devWorkspaceTemplateApi mockPatchTemplate(templateNamespace, templateName, targetTemplatePatch), })); const mockPatchWorkspace = jest.fn(); -jest.mock('../../../../services/dashboard-backend-client/devWorkspaceApi', () => ({ +jest.mock('../../../../services/backend-client/devWorkspaceApi', () => ({ patchWorkspace: (namespace, workspaceName, patch) => mockPatchWorkspace(namespace, workspaceName, patch), })); diff --git a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/index.ts b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/index.ts index cbe99da2f8..2c5c7b64f4 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/index.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/index.ts @@ -16,12 +16,9 @@ import { Action, Reducer } from 'redux'; import { AppThunk } from '../..'; import { container } from '../../../inversify.config'; import { FactoryParams } from '../../../services/helpers/factoryFlow/buildFactoryParams'; -import { - injectKubeConfig, - podmanLogin, -} from '../../../services/dashboard-backend-client/devWorkspaceApi'; -import { fetchResources } from '../../../services/dashboard-backend-client/devworkspaceResourcesApi'; -import { WebsocketClient } from '../../../services/dashboard-backend-client/websocketClient'; +import { injectKubeConfig, podmanLogin } from '../../../services/backend-client/devWorkspaceApi'; +import { fetchResources } from '../../../services/backend-client/devworkspaceResourcesApi'; +import { WebsocketClient } from '../../../services/backend-client/websocketClient'; import devfileApi, { isDevWorkspace } from '../../../services/devfileApi'; import { devWorkspaceKind } from '../../../services/devfileApi/devWorkspace'; import { @@ -56,9 +53,9 @@ import { } from '../../ServerConfig/selectors'; import { checkRunningWorkspacesLimit } from './checkRunningWorkspacesLimit'; import { selectDevWorkspacesResourceVersion } from './selectors'; -import * as DwtApi from '../../../services/dashboard-backend-client/devWorkspaceTemplateApi'; +import * as DwtApi from '../../../services/backend-client/devWorkspaceTemplateApi'; import { selectDefaultDevfile } from '../../DevfileRegistries/selectors'; -import * as DwApi from '../../../services/dashboard-backend-client/devWorkspaceApi'; +import * as DwApi from '../../../services/backend-client/devWorkspaceApi'; import { selectDefaultEditor } from '../../Plugins/devWorkspacePlugins/selectors'; import { DEVWORKSPACE_STORAGE_TYPE_ATTR } from '../../../services/devfileApi/devWorkspace/spec/template'; @@ -1019,23 +1016,23 @@ export const reducer: Reducer = ( const action = incomingAction as KnownAction; switch (action.type) { case Type.REQUEST_DEVWORKSPACE: - return createObject(state, { + return createObject(state, { isLoading: true, error: undefined, }); case Type.RECEIVE_DEVWORKSPACE: - return createObject(state, { + return createObject(state, { isLoading: false, workspaces: action.workspaces, resourceVersion: getNewerResourceVersion(action.resourceVersion, state.resourceVersion), }); case Type.RECEIVE_DEVWORKSPACE_ERROR: - return createObject(state, { + return createObject(state, { isLoading: false, error: action.error, }); case Type.UPDATE_DEVWORKSPACE: - return createObject(state, { + return createObject(state, { isLoading: false, workspaces: state.workspaces.map(workspace => WorkspaceAdapter.getUID(workspace) === WorkspaceAdapter.getUID(action.workspace) @@ -1048,7 +1045,7 @@ export const reducer: Reducer = ( ), }); case Type.ADD_DEVWORKSPACE: - return createObject(state, { + return createObject(state, { isLoading: false, workspaces: state.workspaces .filter( @@ -1062,7 +1059,7 @@ export const reducer: Reducer = ( ), }); case Type.TERMINATE_DEVWORKSPACE: - return createObject(state, { + return createObject(state, { isLoading: false, workspaces: state.workspaces.map(workspace => { if (WorkspaceAdapter.getUID(workspace) === action.workspaceUID) { @@ -1078,7 +1075,7 @@ export const reducer: Reducer = ( }), }); case Type.DELETE_DEVWORKSPACE: - return createObject(state, { + return createObject(state, { isLoading: false, workspaces: state.workspaces.filter( workspace => @@ -1090,7 +1087,7 @@ export const reducer: Reducer = ( ), }); case Type.UPDATE_STARTED_WORKSPACES: - return createObject(state, { + return createObject(state, { startedWorkspaces: action.workspaces.reduce((acc, workspace) => { if (workspace.spec.started === false) { delete acc[WorkspaceAdapter.getUID(workspace)]; @@ -1113,7 +1110,7 @@ export const reducer: Reducer = ( }, state.startedWorkspaces), }); case Type.UPDATE_WARNING: - return createObject(state, { + return createObject(state, { warnings: { [WorkspaceAdapter.getUID(action.workspace)]: action.warning, }, diff --git a/packages/dashboard-frontend/src/store/Workspaces/index.ts b/packages/dashboard-frontend/src/store/Workspaces/index.ts index e5b8736a5b..ece5fc2b19 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/index.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/index.ts @@ -300,7 +300,7 @@ export const reducer: Reducer = (state: State | undefined, action: KnownA switch (action.type) { case 'REQUEST_WORKSPACES': - return createObject(state, { + return createObject(state, { isLoading: true, }); case 'RECEIVE_ERROR': @@ -308,25 +308,25 @@ export const reducer: Reducer = (state: State | undefined, action: KnownA case 'ADD_WORKSPACE': case 'DELETE_WORKSPACE': case 'RECEIVE_WORKSPACES': - return createObject(state, { + return createObject(state, { isLoading: false, }); case 'SET_WORKSPACE_NAME': - return createObject(state, { + return createObject(state, { namespace: action.namespace, workspaceName: action.workspaceName, }); case 'CLEAR_WORKSPACE_NAME': - return createObject(state, { + return createObject(state, { namespace: '', workspaceName: '', }); case 'SET_WORKSPACE_UID': - return createObject(state, { + return createObject(state, { workspaceUID: action.workspaceUID, }); case 'CLEAR_WORKSPACE_UID': - return createObject(state, { + return createObject(state, { workspaceUID: '', }); default: diff --git a/yarn.lock b/yarn.lock index 07ccc89dcb..fc8a4bd07f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -369,7 +369,7 @@ resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70" integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw== -"@eclipse-che/api@^7.0.0-beta-4.0", "@eclipse-che/api@^7.18.1", "@eclipse-che/api@^7.39.2": +"@eclipse-che/api@^7.18.1", "@eclipse-che/api@^7.39.2": version "7.72.0" resolved "https://registry.yarnpkg.com/@eclipse-che/api/-/api-7.72.0.tgz#f16a19f2628c307783203aa5c205b6098b7e57df" integrity sha512-baah1TSYAmCOuiFCHssb7mBoO5BrTAAz8tLV8Y1nqXvDIYMXXyHOnbBpl8/rVeplHGEZIDpFyFN1OGLoy6mcJA== @@ -399,16 +399,6 @@ jsonc-parser "^3.0.0" reflect-metadata "^0.1.13" -"@eclipse-che/workspace-client@0.0.1-1672830275": - version "0.0.1-1672830275" - resolved "https://registry.yarnpkg.com/@eclipse-che/workspace-client/-/workspace-client-0.0.1-1672830275.tgz#7724fbe74fa8ee86a23f888e23d7031cb608787e" - integrity sha512-QgbLxTns7m/efbWZbFRqd9UxH4ELN5Np3JzYWzqN5i/R3cra/xuV9KwDedctarZ6iwnW9ptZFsfDcU5zedZKKQ== - dependencies: - "@eclipse-che/api" "^7.0.0-beta-4.0" - axios "^0.21.4" - qs "^6.9.4" - tunnel "0.0.6" - "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.0" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" @@ -9497,7 +9487,7 @@ q@^1.5.1: resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7" integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw== -qs@^6.11.2, qs@^6.9.4: +qs@^6.11.2: version "6.11.2" resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.2.tgz#64bea51f12c1f5da1bc01496f48ffcff7c69d7d9" integrity sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA== @@ -11313,11 +11303,6 @@ tunnel-agent@^0.6.0: dependencies: safe-buffer "^5.0.1" -tunnel@0.0.6: - version "0.0.6" - resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" - integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg== - tweetnacl@^0.14.3, tweetnacl@~0.14.0: version "0.14.5" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"