From 4d86707345484de8ccea43dd020bc8c84b024ae2 Mon Sep 17 00:00:00 2001 From: Deepesh Kumar Date: Tue, 10 Sep 2024 05:10:55 +0000 Subject: [PATCH] feat: [CDE-320]: Updated CDE webpack and Strings file (#2677) * feat: [CDE-320]: Updated CDE webpack and Strings file * feat: [CDE-320]: Updated CDE webpack and Strings file * feat: [CDE-320]: Updated CDE webpack and Strings file --- web/config/cde/moduleFederation.config.js | 52 ---- web/config/webpack.common.js | 21 +- web/config/webpack.dev.js | 15 +- web/scripts/strings/generateTypes.cjs | 8 + web/src/App.tsx | 5 +- .../components/CDEIDESelect/CDEIDESelect.tsx | 16 +- .../GitspaceListing/ListGitspaces.tsx | 7 +- .../components/SelectIDE/SelectIDE.tsx | 8 +- web/src/cde-gitness/config/webpack.dev.js | 6 +- web/src/cde-gitness/constants/index.ts | 2 +- .../GitspaceCreate/CDECreateGitspace.tsx | 4 +- .../GitspaceCreate/CDECreateGitspace.utils.ts | 6 +- .../pages/GitspaceDetails/GitspaceDetails.tsx | 18 +- .../pages/GitspaceListing/GitspaceListing.tsx | 10 +- web/src/cde-gitness/strings/strings.en.yaml | 126 ++++++++++ web/src/framework/strings/languageLoader.ts | 10 +- web/src/framework/strings/stringTypes.ts | 232 +++++++++--------- web/src/i18n/strings.en.yaml | 127 ---------- 18 files changed, 295 insertions(+), 378 deletions(-) delete mode 100644 web/config/cde/moduleFederation.config.js create mode 100644 web/src/cde-gitness/strings/strings.en.yaml diff --git a/web/config/cde/moduleFederation.config.js b/web/config/cde/moduleFederation.config.js deleted file mode 100644 index 653ca8e67..000000000 --- a/web/config/cde/moduleFederation.config.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2023 Harness, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -const packageJSON = require('../../package.json') -const { pick, mapValues } = require('lodash') - -/** - * These packages must be stricly shared with exact versions - */ -const ExactSharedPackages = [ - 'react-dom', - 'react', - 'react-router-dom', - '@blueprintjs/core', - '@blueprintjs/select', - '@blueprintjs/datetime', - 'restful-react' -] - -/** - * @type {import('webpack').ModuleFederationPluginOptions} - */ -module.exports = { - name: 'cdeRemote', - filename: 'remoteEntry.js', - exposes: { - './App': './src/App.tsx', - './Gitspaces': './src/cde-gitness/pages/GitspaceCreate/GitspaceCreate.tsx', - './GitspaceDetail': './src/cde-gitness/pages/GitspaceDetails/GitspaceDetails.tsx', - './GitspaceList': './src/cde-gitness/pages/GitspaceListing/GitspaceListing.tsx' - }, - shared: { - formik: packageJSON.dependencies['formik'], - ...mapValues(pick(packageJSON.dependencies, ExactSharedPackages), version => ({ - singleton: true, - requiredVersion: version - })) - } -} diff --git a/web/config/webpack.common.js b/web/config/webpack.common.js index 5d111a3d7..ca2a28eea 100644 --- a/web/config/webpack.common.js +++ b/web/config/webpack.common.js @@ -29,26 +29,9 @@ const GenerateArStringTypesPlugin = const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin') const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin') const moduleFederationConfig = require('./moduleFederation.config') -const moduleFederationConfigCDE = require('./cde/moduleFederation.config') const CONTEXT = process.cwd() const DEV = process.env.NODE_ENV === 'development' -const getModuleFields = () => { - if (process.env.MODULE === 'cde') { - return { - moduleFederationConfigEntryName: moduleFederationConfigCDE.name, - moduleFederationPlugin: new ModuleFederationPlugin(moduleFederationConfigCDE) - } - } else { - return { - moduleFederationConfigEntryName: moduleFederationConfig.name, - moduleFederationPlugin: new ModuleFederationPlugin(moduleFederationConfig) - } - } -} - -const { moduleFederationConfigEntryName, moduleFederationPlugin } = getModuleFields() - module.exports = { target: 'web', context: CONTEXT, @@ -57,7 +40,7 @@ module.exports = { children: false }, entry: { - [moduleFederationConfigEntryName]: './src/public-path' + [moduleFederationConfig.name]: './src/public-path' }, output: { publicPath: 'auto', @@ -229,7 +212,7 @@ module.exports = { minify: false, templateParameters: {} }), - moduleFederationPlugin, + new ModuleFederationPlugin(moduleFederationConfig), new DefinePlugin({ 'process.env': '{}', // required for @blueprintjs/core __DEV__: DEV diff --git a/web/config/webpack.dev.js b/web/config/webpack.dev.js index e0e5e3892..1e8908718 100644 --- a/web/config/webpack.dev.js +++ b/web/config/webpack.dev.js @@ -21,20 +21,9 @@ require('dotenv').config() const { merge } = require('webpack-merge') const commonConfig = require('./webpack.common') -const getPortByModule = () => { - const module = process.env.MODULE - if (module === 'cde') { - return process.env.CDE_PORT ?? 3021 - } else { - return process.env.PORT ?? 3020 - } -} - -const moduleType = process.env.MODULE const API_URL = process.env.API_URL ?? 'http://localhost:3000' -const CDE_API_URL = process.env.CDE_API_URL ?? 'http://localhost:3000' const HOST = 'localhost' -const PORT = getPortByModule() +const PORT = process.env.PORT ?? 3020 const STANDALONE = process.env.STANDALONE === 'true' const CONTEXT = process.cwd() const prodConfig = require('./webpack.prod') @@ -66,7 +55,7 @@ const devConfig = { port: PORT, proxy: { '/api': { - target: moduleType === 'cde' ? CDE_API_URL : API_URL, + target: API_URL, logLevel: 'debug', secure: false, changeOrigin: true diff --git a/web/scripts/strings/generateTypes.cjs b/web/scripts/strings/generateTypes.cjs index eb5a1416b..8a65d2ef8 100644 --- a/web/scripts/strings/generateTypes.cjs +++ b/web/scripts/strings/generateTypes.cjs @@ -48,11 +48,19 @@ function flattenKeys(data, parentPath = []) { async function generateTypes() { const i18nContent = await fs.promises.readFile(path.resolve(process.cwd(), `src/i18n/strings.en.yaml`), 'utf8') + const i18nCDEContent = await fs.promises.readFile( + path.resolve(process.cwd(), `src/cde-gitness/strings/strings.en.yaml`), + 'utf8' + ) const allData = [ { moduleRef: null, keys: flattenKeys(yaml.parse(i18nContent)) + }, + { + moduleRef: 'cde', + keys: flattenKeys(yaml.parse(i18nCDEContent), ['cde']) } ] diff --git a/web/src/App.tsx b/web/src/App.tsx index 97349d440..a6799e942 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -61,7 +61,10 @@ const App: React.FC = React.memo(function App({ const queryParams = useMemo(() => (!standalone ? { routingId } : {}), [standalone, routingId]) useEffect(() => { - languageLoader(lang).then(setStrings) + const stringsMaps = languageLoader(lang) + if (stringsMaps) { + setStrings(stringsMaps) + } }, [lang, setStrings]) const Wrapper: React.FC<{ fullPage: boolean }> = useCallback( diff --git a/web/src/cde-gitness/components/CDEIDESelect/CDEIDESelect.tsx b/web/src/cde-gitness/components/CDEIDESelect/CDEIDESelect.tsx index fdbe9f5ad..099d3c1b5 100644 --- a/web/src/cde-gitness/components/CDEIDESelect/CDEIDESelect.tsx +++ b/web/src/cde-gitness/components/CDEIDESelect/CDEIDESelect.tsx @@ -18,7 +18,7 @@ import React from 'react' import { Layout, Text } from '@harnessio/uicore' import { Menu, MenuItem } from '@blueprintjs/core' import { Code } from 'iconoir-react' -import { StandaloneIDEType } from 'cde-gitness/constants' +import { IDEType } from 'cde-gitness/constants' import vsCodeWebIcon from 'cde-gitness/assests/vsCodeWeb.svg?url' import vscodeIcon from 'cde-gitness/assests/VSCode.svg?url' import { useStrings } from 'framework/strings' @@ -36,12 +36,12 @@ export const CDEIDESelect = ({ const ideOptions = [ { label: getString('cde.ide.desktop'), - value: StandaloneIDEType.VSCODE, + value: IDEType.VSCODE, img: vscodeIcon }, { label: getString('cde.ide.browser'), - value: StandaloneIDEType.VSCODEWEB, + value: IDEType.VSCODEWEB, img: vsCodeWebIcon } ] @@ -50,14 +50,6 @@ export const CDEIDESelect = ({ return ( - // IDE - // - // Your Gitspace will open in the selected IDE to code - // - // - // } leftElement={ @@ -68,7 +60,7 @@ export const CDEIDESelect = ({ } label={ - + {label} diff --git a/web/src/cde-gitness/components/GitspaceListing/ListGitspaces.tsx b/web/src/cde-gitness/components/GitspaceListing/ListGitspaces.tsx index 5e393c4ec..2716d9f32 100644 --- a/web/src/cde-gitness/components/GitspaceListing/ListGitspaces.tsx +++ b/web/src/cde-gitness/components/GitspaceListing/ListGitspaces.tsx @@ -40,7 +40,7 @@ import { useAppContext } from 'AppContext' import { getErrorMessage } from 'utils/Utils' import { useConfirmAct } from 'hooks/useConfirmAction' import VSCode from 'cde-gitness/assests/VSCode.svg?url' -import { GitspaceActionType, GitspaceStatus } from 'cde-gitness/constants' +import { GitspaceActionType, GitspaceStatus, IDEType } from 'cde-gitness/constants' import type { EnumGitspaceStateType, EnumIDEType, TypesGitspaceConfig } from 'services/cde' import gitspaceIcon from 'cde-gitness/assests/gitspace.svg?url' import { useModalHook } from 'hooks/useModalHook' @@ -89,11 +89,6 @@ export const getStatusText = (getString: UseStringsReturn['getString'], status?: } } -enum IDEType { - VSCODE = 'vs_code', - VSCODEWEB = 'vs_code_web' -} - const getUsageTemplate = ( getString: UseStringsReturn['getString'], icon: React.ReactNode, diff --git a/web/src/cde-gitness/components/SelectIDE/SelectIDE.tsx b/web/src/cde-gitness/components/SelectIDE/SelectIDE.tsx index 1015e0489..9bb73a345 100644 --- a/web/src/cde-gitness/components/SelectIDE/SelectIDE.tsx +++ b/web/src/cde-gitness/components/SelectIDE/SelectIDE.tsx @@ -21,14 +21,14 @@ import { useFormikContext } from 'formik' import { GitspaceSelect } from 'cde-gitness/components/GitspaceSelect/GitspaceSelect' import { useStrings, type UseStringsReturn } from 'framework/strings' import type { OpenapiCreateGitspaceRequest } from 'services/cde' -import { StandaloneIDEType } from 'cde-gitness/constants' +import { IDEType } from 'cde-gitness/constants' import vsCodeWebIcon from 'cde-gitness/assests/vsCodeWeb.svg?url' import VSCode from 'cde-gitness/assests/VSCode.svg?url' export const getIDESelectItems = (getString: UseStringsReturn['getString']) => { return [ - { label: getString('cde.ide.desktop'), value: StandaloneIDEType.VSCODE }, - { label: getString('cde.ide.browser'), value: StandaloneIDEType.VSCODEWEB } + { label: getString('cde.ide.desktop'), value: IDEType.VSCODE }, + { label: getString('cde.ide.browser'), value: IDEType.VSCODEWEB } ] } @@ -44,7 +44,7 @@ export const SelectIDE = () => { text={ { - {formik.values.ide === StandaloneIDEType.VSCODE && } + {formik.values.ide === IDEType.VSCODE && } ) : (