From 0a5ed06f0299b66cbf3763395f11d82bbdaa98d8 Mon Sep 17 00:00:00 2001 From: Deepesh Kumar Date: Sat, 13 Jul 2024 04:28:07 +0000 Subject: [PATCH] feat: [CDE-129]: added flag gitspace_enabled (#2214) * feat: [CDE-129]: fixed lint * feat: [CDE-129]: fixed lint * feat: [CDE-129]: updated flag gitspace_enabled * feat: [CDE-129]: updated webpack * feat: [CDE-129]: updated webpack * feat: [CDE-129]: added flag gitspace_enabled --- app/api/handler/system/list_config.go | 2 ++ types/config.go | 3 +++ web/config/webpack.common.js | 4 +--- web/config/webpack.dev.js | 3 +-- web/package.json | 6 +++--- web/src/global.d.ts | 3 --- web/src/layouts/menu/DefaultMenu.tsx | 5 ++++- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/api/handler/system/list_config.go b/app/api/handler/system/list_config.go index 12e917e25..c8b1ddbf8 100644 --- a/app/api/handler/system/list_config.go +++ b/app/api/handler/system/list_config.go @@ -26,6 +26,7 @@ type ConfigOutput struct { UserSignupAllowed bool `json:"user_signup_allowed"` PublicResourceCreationEnabled bool `json:"public_resource_creation_enabled"` SSHEnabled bool `json:"ssh_enabled"` + GitspaceEnabled bool `json:"gitspace_enabled"` } // HandleGetConfig returns an http.HandlerFunc that processes an http.Request @@ -44,6 +45,7 @@ func HandleGetConfig(config *types.Config, sysCtrl *system.Controller) http.Hand SSHEnabled: config.SSH.Enable, UserSignupAllowed: userSignupAllowed, PublicResourceCreationEnabled: config.PublicResourceCreationEnabled, + GitspaceEnabled: config.Gitspace.Enable, }) } } diff --git a/types/config.go b/types/config.go index 28b76254f..da87d4f80 100644 --- a/types/config.go +++ b/types/config.go @@ -399,6 +399,9 @@ type Config struct { DefaultBaseImage string `envconfig:"GITNESS_GITSPACE_DEFAULT_BASE_IMAGE" default:"mcr.microsoft.com/devcontainers/base:dev-ubuntu-24.04"` //nolint:lll // DefaultBindMountTargetPath is the target for bind mount in the Gitspace container. DefaultBindMountTargetPath string `envconfig:"GITNESS_GITSPACE_DEFAULT_BIND_MOUNT_TARGET_PATH" default:"/gitspace"` //nolint:lll + + Enable bool `envconfig:"GITNESS_GITSPACE_ENABLE" default:"false"` + // DefaultBindMountTargetPath is the source for bind mount in the Gitspace container. // Sub-directories will be created from this eg /gitspace/space1/space2/config1 // If left blank, it will be set to $HOME/.gitness diff --git a/web/config/webpack.common.js b/web/config/webpack.common.js index 6f14de945..d3fba8a8b 100644 --- a/web/config/webpack.common.js +++ b/web/config/webpack.common.js @@ -30,7 +30,6 @@ const moduleFederationConfig = require('./moduleFederation.config') const moduleFederationConfigCDE = require('./cde/moduleFederation.config') const CONTEXT = process.cwd() const DEV = process.env.NODE_ENV === 'development' -const ENABLE_GITSPACE = process.env.ENABLE_GITSPACE === 'true' const getModuleFields = () => { if (process.env.MODULE === 'cde') { @@ -224,8 +223,7 @@ module.exports = { moduleFederationPlugin, new DefinePlugin({ 'process.env': '{}', // required for @blueprintjs/core - __DEV__: DEV, - __ENABLE_GITSPACE__: ENABLE_GITSPACE + __DEV__: DEV }), new GenerateStringTypesPlugin(), new RetryChunkLoadPlugin({ diff --git a/web/config/webpack.dev.js b/web/config/webpack.dev.js index 27fb17e76..cd1a2c11b 100644 --- a/web/config/webpack.dev.js +++ b/web/config/webpack.dev.js @@ -34,13 +34,12 @@ const API_URL = process.env.API_URL ?? 'http://localhost:3000' const HOST = 'localhost' const PORT = getPortByModule() const STANDALONE = process.env.STANDALONE === 'true' -const ENABLE_GITSPACE = process.env.ENABLE_GITSPACE === 'true' const CONTEXT = process.cwd() const prodConfig = require('./webpack.prod') console.info(`Starting development build... http://${HOST}:${PORT}`) console.info('Environment variables:') -console.table({ STANDALONE, ENABLE_GITSPACE, HOST, PORT, API_URL }) +console.table({ STANDALONE, HOST, PORT, API_URL }) const devConfig = { mode: 'development', diff --git a/web/package.json b/web/package.json index 38a8584ad..38f2aa70d 100644 --- a/web/package.json +++ b/web/package.json @@ -19,12 +19,12 @@ "webpack:cde": "NODE_ENV=development MODULE=cde webpack serve --config config/webpack.dev.js", "typed-scss": "typed-scss-modules src --watch", "dev": "run-p webpack typed-scss", - "dev:cde": "MODULE=cde ENABLE_GITSPACE=true run-p webpack:cde typed-scss", + "dev:cde": "MODULE=cde run-p webpack:cde typed-scss", "test": "jest src --silent", "test:watch": "jest --watch", "build": "rm -rf dist && webpack --config config/webpack.prod.js", - "build:cde": "rm -rf dist && MODULE=cde ENABLE_GITSPACE=true webpack --config config/webpack.prod.js", - "lint": "eslint --fix --rulesdir ./scripts/eslint-rules --ext .ts --ext .tsx src", + "build:cde": "rm -rf dist && MODULE=cde webpack --config config/webpack.prod.js", + "lint": "eslint --rulesdir ./scripts/eslint-rules --ext .ts --ext .tsx src", "prettier": "prettier --check \"./src/**/*.{ts,tsx,css,scss}\"", "coverage": "npm test --coverage", "typecheck": "tsc", diff --git a/web/src/global.d.ts b/web/src/global.d.ts index b6300457f..5381c3607 100644 --- a/web/src/global.d.ts +++ b/web/src/global.d.ts @@ -17,9 +17,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ declare const __DEV__: boolean -/* eslint-disable @typescript-eslint/no-explicit-any */ -declare const __ENABLE_GITSPACE__: boolean - declare module '*.png' { const value: string export default value diff --git a/web/src/layouts/menu/DefaultMenu.tsx b/web/src/layouts/menu/DefaultMenu.tsx index 874f99b1f..81204ed92 100644 --- a/web/src/layouts/menu/DefaultMenu.tsx +++ b/web/src/layouts/menu/DefaultMenu.tsx @@ -19,6 +19,7 @@ import { Container, Layout } from '@harnessio/uicore' import { Render } from 'react-jsx-match' import { useHistory, useRouteMatch } from 'react-router-dom' import { FingerprintLockCircle, BookmarkBook, UserSquare, Settings } from 'iconoir-react' +import { useGet } from 'restful-react' import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata' import { useStrings } from 'framework/strings' import type { SpaceSpaceOutput } from 'services/code' @@ -38,6 +39,8 @@ export const DefaultMenu: React.FC = () => { const routeMatch = useRouteMatch() const isCommitSelected = useMemo(() => routeMatch.path === '/:space*/:repoName/commit/:commitRef*', [routeMatch]) + const { data: systemConfig } = useGet({ path: 'api/v1/system/config' }) + const isFilesSelected = useMemo( () => !isCommitSelected && @@ -172,7 +175,7 @@ export const DefaultMenu: React.FC = () => { - {__ENABLE_GITSPACE__ && ( + {systemConfig?.gitspace_enabled && (