mirror of https://github.com/harness/drone.git
fix: [AH-558]: fix showing undefined in secret select field (#2857)
* fix: [AH-558]: fix showing undefined in secret select fieldpull/3576/head
parent
b32615d82b
commit
90b86b5690
|
@ -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<void> => {
|
||||
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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue