From 90b86b56905050f4f82dd1352a6b51ccd64a5b98 Mon Sep 17 00:00:00 2001 From: Shivanand Sonnad Date: Thu, 24 Oct 2024 04:57:03 +0000 Subject: [PATCH] fix: [AH-558]: fix showing undefined in secret select field (#2857) * fix: [AH-558]: fix showing undefined in secret select field --- .../Forms/UpstreamProxyConfigurationForm.tsx | 11 ++++--- .../components/Forms/utils.ts | 30 +++++++++++++++++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/web/src/ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyConfigurationForm.tsx b/web/src/ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyConfigurationForm.tsx index 71881039f..2f0d515ca 100644 --- a/web/src/ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyConfigurationForm.tsx +++ b/web/src/ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyConfigurationForm.tsx @@ -41,7 +41,7 @@ import { type UpstreamRegistry, type UpstreamRegistryRequest } from '../../types' -import { getFormattedFormDataForAuthType } from './utils' +import { getFormattedFormDataForAuthType, getFormattedInitialValuesForAuthType } from './utils' import css from './Forms.module.scss' @@ -58,7 +58,7 @@ function UpstreamProxyConfigurationForm( const { data, setIsUpdating } = useContext(RepositoryProviderContext) const { showSuccess, showError, clear } = useToaster() const { getString } = useStrings() - const { parent } = useAppStore() + const { parent, scope } = useAppStore() const spaceRef = useGetSpaceRef() const { mutateAsync: modifyUpstreamProxy } = useModifyRegistryMutation() @@ -66,7 +66,10 @@ function UpstreamProxyConfigurationForm( const getInitialValues = (repoData: UpstreamRegistry): UpstreamRegistryRequest => { const repositoryType = factory.getRepositoryType(repoData.packageType) if (repositoryType) { - const transformedInitialValuesForCleanupPolicy = getFormattedIntialValuesForCleanupPolicy(repoData) + const transformedIntialValuesForAuthType = getFormattedInitialValuesForAuthType(repoData, parent) + const transformedInitialValuesForCleanupPolicy = getFormattedIntialValuesForCleanupPolicy( + transformedIntialValuesForAuthType + ) return repositoryType.getUpstreamProxyInitialValues( transformedInitialValuesForCleanupPolicy ) as UpstreamRegistryRequest @@ -96,7 +99,7 @@ function UpstreamProxyConfigurationForm( const handleSubmit = async (values: UpstreamRegistryRequest): Promise => { const repositoryType = factory.getRepositoryType(values.packageType) if (repositoryType) { - const transfomedAuthType = getFormattedFormDataForAuthType(values, parent) + const transfomedAuthType = getFormattedFormDataForAuthType(values, parent, scope) const transformedCleanupPolicy = getFormattedFormDataForCleanupPolicy(transfomedAuthType) const transformedValues = repositoryType.processUpstreamProxyFormData( transformedCleanupPolicy 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 22747d7ed..2a12bfd0d 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 @@ -15,9 +15,11 @@ */ import produce from 'immer' -import { compact, get, set } from 'lodash-es' -import type { Scope } from '@ar/MFEAppTypes' +import { compact, defaultTo, get, set } from 'lodash-es' + import { Parent } from '@ar/common/types' +import type { Scope } from '@ar/MFEAppTypes' + import { DockerRepositoryURLInputSource, UpstreamProxyAuthenticationMode, @@ -62,3 +64,27 @@ export function getFormattedFormDataForAuthType( } }) } + +function getSecretScopeDetailsByIdentifier(identifier: string, secretSpacePath: string) { + const referenceString = getReferenceStringFromSecretSpacePath(identifier, secretSpacePath) + const [, orgIdentifier, projectIdentifier] = secretSpacePath.split('/') + return { + identifier: identifier, + name: identifier, + referenceString, + orgIdentifier, + projectIdentifier + } +} + +export function getFormattedInitialValuesForAuthType(values: UpstreamRegistryRequest, parent?: Parent) { + return produce(values, (draft: UpstreamRegistryRequest) => { + if (draft.config.authType === UpstreamProxyAuthenticationMode.USER_NAME_AND_PASSWORD) { + if (parent === Parent.Enterprise) { + const secretIdentifier = defaultTo(draft.config.auth?.secretIdentifier, '') + const secretSpacePath = defaultTo(draft.config.auth?.secretSpacePath, '') + set(draft, 'config.auth.secretIdentifier', getSecretScopeDetailsByIdentifier(secretIdentifier, secretSpacePath)) + } + } + }) +}