diff --git a/web/package.json b/web/package.json index 50f9b267a..7a688d178 100644 --- a/web/package.json +++ b/web/package.json @@ -51,7 +51,7 @@ "@codemirror/view": "^6.9.6", "@harnessio/design-system": "^2.1.1", "@harnessio/icons": "^2.1.9", - "@harnessio/react-har-service-client": "^0.6.0", + "@harnessio/react-har-service-client": "^0.7.0", "@harnessio/react-ssca-manager-client": "^0.65.0", "@harnessio/uicore": "^4.1.2", "@tanstack/react-query": "4.20.4", diff --git a/web/src/ar/MFEAppTypes.ts b/web/src/ar/MFEAppTypes.ts index 423b8ec22..69978622a 100644 --- a/web/src/ar/MFEAppTypes.ts +++ b/web/src/ar/MFEAppTypes.ts @@ -134,5 +134,6 @@ export interface MFEAppProps { export enum FeatureFlags { HAR_GENERIC_ARTIFACT_ENABLED = 'HAR_GENERIC_ARTIFACT_ENABLED', - HAR_TRIGGERS = 'HAR_TRIGGERS' + HAR_TRIGGERS = 'HAR_TRIGGERS', + HAR_MAVEN_ARTIFACT_ENABLED = 'HAR_MAVEN_ARTIFACT_ENABLED' } diff --git a/web/src/ar/hooks/index.ts b/web/src/ar/hooks/index.ts index a53c35d9f..5b309a884 100644 --- a/web/src/ar/hooks/index.ts +++ b/web/src/ar/hooks/index.ts @@ -25,3 +25,4 @@ export { useGetSpaceRef } from './useGetSpaceRef' export { useParentContextObj } from './useParentContextObj' export { useLicenseStore } from './useLicenseStore' export { useFeatureFlags, useFeatureFlag } from './useFeatureFlag' +export { useGetUpstreamRepositoryPackageTypes } from './useGetUpstreamRepositoryPackageTypes' diff --git a/web/src/ar/hooks/useGetRepositoryTypes.ts b/web/src/ar/hooks/useGetRepositoryTypes.ts index 80120a7ba..f04067848 100644 --- a/web/src/ar/hooks/useGetRepositoryTypes.ts +++ b/web/src/ar/hooks/useGetRepositoryTypes.ts @@ -67,6 +67,7 @@ const RepositoryTypes: RepositoryTypeListItem[] = [ label: 'repositoryTypes.maven', value: RepositoryPackageType.MAVEN, icon: 'maven-repository-type', + featureFlag: FeatureFlags.HAR_MAVEN_ARTIFACT_ENABLED, tooltip: 'Coming Soon!', disabled: true }, diff --git a/web/src/ar/hooks/useGetUpstreamRepositoryPackageTypes.ts b/web/src/ar/hooks/useGetUpstreamRepositoryPackageTypes.ts new file mode 100644 index 000000000..ec179fe7a --- /dev/null +++ b/web/src/ar/hooks/useGetUpstreamRepositoryPackageTypes.ts @@ -0,0 +1,68 @@ +/* + * Copyright 2024 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. + */ + +import type { IconName } from '@harnessio/icons' + +import { FeatureFlags } from '@ar/MFEAppTypes' +import type { StringsMap } from '@ar/frameworks/strings' +import { UpstreamProxyPackageType } from '@ar/pages/upstream-proxy-details/types' + +import { useFeatureFlags } from './useFeatureFlag' + +export interface UpstreamRepositoryPackageTypeListItem { + label: keyof StringsMap + value: UpstreamProxyPackageType + icon: IconName + disabled?: boolean + tooltip?: string + featureFlag?: FeatureFlags +} + +export const useGetUpstreamRepositoryPackageTypes = (): UpstreamRepositoryPackageTypeListItem[] => { + const featureFlags = useFeatureFlags() + + return UpstreamProxyPackageTypeList.map(repo => { + if (repo.disabled && repo.featureFlag && featureFlags[repo.featureFlag]) { + return { + ...repo, + disabled: false, + tooltip: undefined + } + } + return repo + }) +} + +export const UpstreamProxyPackageTypeList: UpstreamRepositoryPackageTypeListItem[] = [ + { + label: 'repositoryTypes.docker', + value: UpstreamProxyPackageType.DOCKER, + icon: 'docker-step' + }, + { + label: 'repositoryTypes.helm', + value: UpstreamProxyPackageType.HELM, + icon: 'service-helm' + }, + { + label: 'repositoryTypes.maven', + value: UpstreamProxyPackageType.MAVEN, + featureFlag: FeatureFlags.HAR_MAVEN_ARTIFACT_ENABLED, + icon: 'maven-repository-type', + tooltip: 'Coming Soon!', + disabled: true + } +] diff --git a/web/src/ar/pages/repository-details/MavenRepository/MavenRepository.tsx b/web/src/ar/pages/repository-details/MavenRepository/MavenRepository.tsx new file mode 100644 index 000000000..52a7585a4 --- /dev/null +++ b/web/src/ar/pages/repository-details/MavenRepository/MavenRepository.tsx @@ -0,0 +1,130 @@ +/* + * Copyright 2024 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. + */ + +import React from 'react' +import type { IconName } from '@harnessio/icons' + +import { RepositoryConfigType, RepositoryPackageType } from '@ar/common/types' +import UpstreamProxyActions from '@ar/pages/upstream-proxy-details/components/UpstreamProxyActions/UpstreamProxyActions' +import UpstreamProxyConfigurationForm from '@ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyConfigurationForm' +import UpstreamProxyCreateFormContent from '@ar/pages/upstream-proxy-details/components/FormContent/UpstreamProxyCreateFormContent' +import UpstreamProxyDetailsHeader from '@ar/pages/upstream-proxy-details/components/UpstreamProxyDetailsHeader/UpstreamProxyDetailsHeader' +import { + type CreateRepositoryFormProps, + type RepositoryActionsProps, + type RepositoryConfigurationFormProps, + type RepositoryDetailsHeaderProps, + RepositoryStep, + type RepositoySetupClientProps +} from '@ar/frameworks/RepositoryStep/Repository' +import { + UpstreamProxyAuthenticationMode, + type UpstreamRegistryRequest, + UpstreamRepositoryURLInputSource +} from '@ar/pages/upstream-proxy-details/types' + +import type { Repository, VirtualRegistryRequest } from '../types' +import RepositoryActions from '../components/Actions/RepositoryActions' +import RedirectPageView from '../components/RedirectPageView/RedirectPageView' +import SetupClientContent from '../components/SetupClientContent/SetupClientContent' +import RepositoryConfigurationForm from '../components/Forms/RepositoryConfigurationForm' +import RepositoryCreateFormContent from '../components/FormContent/RepositoryCreateFormContent' +import RepositoryDetailsHeader from '../components/RepositoryDetailsHeader/RepositoryDetailsHeader' + +export class MavenRepositoryType extends RepositoryStep { + protected packageType = RepositoryPackageType.MAVEN + protected repositoryName = 'Maven Repository' + protected repositoryIcon: IconName = 'maven-repository-type' + protected supportedScanners = [] + protected supportsUpstreamProxy = true + protected supportedUpstreamURLSources = [ + UpstreamRepositoryURLInputSource.MavenCentral, + UpstreamRepositoryURLInputSource.Custom + ] + + protected defaultValues: VirtualRegistryRequest = { + packageType: RepositoryPackageType.MAVEN, + identifier: '', + config: { + type: RepositoryConfigType.VIRTUAL + }, + scanners: [] + } + + protected defaultUpstreamProxyValues: UpstreamRegistryRequest = { + packageType: RepositoryPackageType.MAVEN, + identifier: '', + config: { + type: RepositoryConfigType.UPSTREAM, + authType: UpstreamProxyAuthenticationMode.ANONYMOUS, + source: UpstreamRepositoryURLInputSource.Custom, + url: '' + }, + cleanupPolicy: [], + scanners: [] + } + + renderCreateForm(props: CreateRepositoryFormProps): JSX.Element { + const { type } = props + if (type === RepositoryConfigType.VIRTUAL) { + return + } else { + return + } + } + + renderCofigurationForm(props: RepositoryConfigurationFormProps): JSX.Element { + const { type } = props + if (type === RepositoryConfigType.VIRTUAL) { + return + } else { + return + } + } + + renderActions(props: RepositoryActionsProps): JSX.Element { + if (props.type === RepositoryConfigType.VIRTUAL) { + return + } + return + } + + renderSetupClient(props: RepositoySetupClientProps): JSX.Element { + const { repoKey, onClose, artifactKey, versionKey } = props + return ( + + ) + } + + renderRepositoryDetailsHeader(props: RepositoryDetailsHeaderProps): JSX.Element { + const { type } = props + if (type === RepositoryConfigType.VIRTUAL) { + return + } else { + return + } + } + + renderRedirectPage(): JSX.Element { + return + } +} diff --git a/web/src/ar/pages/repository-details/RepositoryFactory.tsx b/web/src/ar/pages/repository-details/RepositoryFactory.tsx index 82c85866c..c3947bf4b 100644 --- a/web/src/ar/pages/repository-details/RepositoryFactory.tsx +++ b/web/src/ar/pages/repository-details/RepositoryFactory.tsx @@ -16,9 +16,11 @@ import repositoryFactory from '@ar/frameworks/RepositoryStep/RepositoryFactory' import { DockerRepositoryType } from './DockerRepository/DockerRepositoryType' +import { MavenRepositoryType } from './MavenRepository/MavenRepository' import { HelmRepositoryType } from './HelmRepository/HelmRepositoryType' import { GenericRepositoryType } from './GenericRepository/GenericRepositoryType' repositoryFactory.registerStep(new DockerRepositoryType()) repositoryFactory.registerStep(new HelmRepositoryType()) repositoryFactory.registerStep(new GenericRepositoryType()) +repositoryFactory.registerStep(new MavenRepositoryType()) diff --git a/web/src/ar/pages/upstream-proxy-details/components/AuthenticationFormInput/constants.tsx b/web/src/ar/pages/upstream-proxy-details/components/AuthenticationFormInput/constants.tsx index 76dcf19b0..365bc5c2d 100644 --- a/web/src/ar/pages/upstream-proxy-details/components/AuthenticationFormInput/constants.tsx +++ b/web/src/ar/pages/upstream-proxy-details/components/AuthenticationFormInput/constants.tsx @@ -54,5 +54,9 @@ export const URLSourceToSupportedAuthTypesMapping: Record< [UpstreamRepositoryURLInputSource.Custom]: [ UpstreamProxyAuthenticationMode.USER_NAME_AND_PASSWORD, UpstreamProxyAuthenticationMode.ANONYMOUS + ], + [UpstreamRepositoryURLInputSource.MavenCentral]: [ + UpstreamProxyAuthenticationMode.USER_NAME_AND_PASSWORD, + UpstreamProxyAuthenticationMode.ANONYMOUS ] } diff --git a/web/src/ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyCreateForm.tsx b/web/src/ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyCreateForm.tsx index 95d682ea4..0fbaa4af6 100644 --- a/web/src/ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyCreateForm.tsx +++ b/web/src/ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyCreateForm.tsx @@ -29,7 +29,7 @@ import { } from '@harnessio/uicore' import { useCreateRegistryMutation } from '@harnessio/react-har-service-client' -import { useAppStore, useGetSpaceRef } from '@ar/hooks' +import { useAppStore, useGetSpaceRef, useGetUpstreamRepositoryPackageTypes } from '@ar/hooks' import { useStrings } from '@ar/frameworks/strings' import { decodeRef } from '@ar/hooks/useGetSpaceRef' import { setFormikRef } from '@ar/common/utils' @@ -41,7 +41,6 @@ import { UpstreamRegistry, UpstreamRegistryRequest } from '@ar/pages/upstream-proxy-details/types' -import { UpstreamProxyPackageTypeList } from '@ar/pages/upstream-proxy-details/constants' import CreateRepositoryWidget from '@ar/frameworks/RepositoryStep/CreateRepositoryWidget' import repositoryFactory from '@ar/frameworks/RepositoryStep/RepositoryFactory' @@ -67,6 +66,7 @@ function FormContent(props: FormContentProps): JSX.Element { const { getString } = useStrings() const { values } = formikProps const { packageType } = values + const packageTypeList = useGetUpstreamRepositoryPackageTypes() return ( @@ -77,7 +77,7 @@ function FormContent(props: FormContentProps): JSX.Element { ({ + items={packageTypeList.map(each => ({ ...each, label: getString(each.label) }))} diff --git a/web/src/ar/pages/upstream-proxy-details/components/Forms/utils.ts b/web/src/ar/pages/upstream-proxy-details/components/Forms/utils.ts index bf5a86cc3..2a6dad9d0 100644 --- a/web/src/ar/pages/upstream-proxy-details/components/Forms/utils.ts +++ b/web/src/ar/pages/upstream-proxy-details/components/Forms/utils.ts @@ -117,7 +117,11 @@ export function getFormattedFormDataForAuthType( } else if (draft.config.authType === UpstreamProxyAuthenticationMode.ANONYMOUS) { set(draft, 'config.auth', null) } - if (draft.config.source === UpstreamRepositoryURLInputSource.Dockerhub) { + if ( + [UpstreamRepositoryURLInputSource.Dockerhub, UpstreamRepositoryURLInputSource.MavenCentral].includes( + draft.config.source as UpstreamRepositoryURLInputSource + ) + ) { set(draft, 'config.url', '') } }) diff --git a/web/src/ar/pages/upstream-proxy-details/components/RepositoryUrlInput/constants.ts b/web/src/ar/pages/upstream-proxy-details/components/RepositoryUrlInput/constants.ts index 37ebbf5c1..be5a28d5c 100644 --- a/web/src/ar/pages/upstream-proxy-details/components/RepositoryUrlInput/constants.ts +++ b/web/src/ar/pages/upstream-proxy-details/components/RepositoryUrlInput/constants.ts @@ -33,5 +33,9 @@ export const UpstreamURLSourceConfig: Record