fix: [AH-558]: fix showing undefined in secret select field (#2857)

* fix: [AH-558]: fix showing undefined in secret select field
pull/3576/head
Shivanand Sonnad 2024-10-24 04:57:03 +00:00 committed by Harness
parent b32615d82b
commit 90b86b5690
2 changed files with 35 additions and 6 deletions

View File

@ -41,7 +41,7 @@ import {
type UpstreamRegistry, type UpstreamRegistry,
type UpstreamRegistryRequest type UpstreamRegistryRequest
} from '../../types' } from '../../types'
import { getFormattedFormDataForAuthType } from './utils' import { getFormattedFormDataForAuthType, getFormattedInitialValuesForAuthType } from './utils'
import css from './Forms.module.scss' import css from './Forms.module.scss'
@ -58,7 +58,7 @@ function UpstreamProxyConfigurationForm(
const { data, setIsUpdating } = useContext(RepositoryProviderContext) const { data, setIsUpdating } = useContext(RepositoryProviderContext)
const { showSuccess, showError, clear } = useToaster() const { showSuccess, showError, clear } = useToaster()
const { getString } = useStrings() const { getString } = useStrings()
const { parent } = useAppStore() const { parent, scope } = useAppStore()
const spaceRef = useGetSpaceRef() const spaceRef = useGetSpaceRef()
const { mutateAsync: modifyUpstreamProxy } = useModifyRegistryMutation() const { mutateAsync: modifyUpstreamProxy } = useModifyRegistryMutation()
@ -66,7 +66,10 @@ function UpstreamProxyConfigurationForm(
const getInitialValues = (repoData: UpstreamRegistry): UpstreamRegistryRequest => { const getInitialValues = (repoData: UpstreamRegistry): UpstreamRegistryRequest => {
const repositoryType = factory.getRepositoryType(repoData.packageType) const repositoryType = factory.getRepositoryType(repoData.packageType)
if (repositoryType) { if (repositoryType) {
const transformedInitialValuesForCleanupPolicy = getFormattedIntialValuesForCleanupPolicy(repoData) const transformedIntialValuesForAuthType = getFormattedInitialValuesForAuthType(repoData, parent)
const transformedInitialValuesForCleanupPolicy = getFormattedIntialValuesForCleanupPolicy(
transformedIntialValuesForAuthType
)
return repositoryType.getUpstreamProxyInitialValues( return repositoryType.getUpstreamProxyInitialValues(
transformedInitialValuesForCleanupPolicy transformedInitialValuesForCleanupPolicy
) as UpstreamRegistryRequest ) as UpstreamRegistryRequest
@ -96,7 +99,7 @@ function UpstreamProxyConfigurationForm(
const handleSubmit = async (values: UpstreamRegistryRequest): Promise<void> => { const handleSubmit = async (values: UpstreamRegistryRequest): Promise<void> => {
const repositoryType = factory.getRepositoryType(values.packageType) const repositoryType = factory.getRepositoryType(values.packageType)
if (repositoryType) { if (repositoryType) {
const transfomedAuthType = getFormattedFormDataForAuthType(values, parent) const transfomedAuthType = getFormattedFormDataForAuthType(values, parent, scope)
const transformedCleanupPolicy = getFormattedFormDataForCleanupPolicy(transfomedAuthType) const transformedCleanupPolicy = getFormattedFormDataForCleanupPolicy(transfomedAuthType)
const transformedValues = repositoryType.processUpstreamProxyFormData( const transformedValues = repositoryType.processUpstreamProxyFormData(
transformedCleanupPolicy transformedCleanupPolicy

View File

@ -15,9 +15,11 @@
*/ */
import produce from 'immer' import produce from 'immer'
import { compact, get, set } from 'lodash-es' import { compact, defaultTo, get, set } from 'lodash-es'
import type { Scope } from '@ar/MFEAppTypes'
import { Parent } from '@ar/common/types' import { Parent } from '@ar/common/types'
import type { Scope } from '@ar/MFEAppTypes'
import { import {
DockerRepositoryURLInputSource, DockerRepositoryURLInputSource,
UpstreamProxyAuthenticationMode, 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))
}
}
})
}