@@ -21,7 +21,14 @@ import { ISourceControlManagementConfig } from './types';
2121import PrimaryContainedButton from 'components/shared/Buttons/PrimaryContainedButton' ;
2222import PrimaryOutlinedButton from 'components/shared/Buttons/PrimaryOutlinedButton' ;
2323import ButtonLoadingHoc from 'components/shared/Buttons/ButtonLoadingHoc' ;
24- import { authKeys , githubOnlyProviders , patConfigKeys , providers , scmAuthType } from './constants' ;
24+ import {
25+ SCM_AUTH_TYPE_PAT ,
26+ authKeys ,
27+ githubOnlyProviders ,
28+ patConfigKeys ,
29+ providers ,
30+ scmAuthType ,
31+ } from './constants' ;
2532import { defaultSourceControlManagement , sourceControlManagementFormReducer } from './reducer' ;
2633import { addOrValidateSourceControlManagementForm } from '../store/ActionCreator' ;
2734import { getCurrentNamespace } from 'services/NamespaceStore' ;
@@ -95,6 +102,9 @@ const SourceControlManagementForm = ({
95102 defaultSourceControlManagement
96103 ) ;
97104
105+ const supportedAuthTypes =
106+ formState ?. config ?. provider === 'BITBUCKET_SERVER' ? scmAuthType : [ SCM_AUTH_TYPE_PAT ] ;
107+
98108 const getMissingFieldsCount = ( ) => {
99109 let count = 0 ;
100110 if ( ! formState . config ?. link ) {
@@ -293,74 +303,77 @@ const SourceControlManagementForm = ({
293303 < BoldHeader > { T . translate ( `${ PREFIX } .authHeader` ) } </ BoldHeader >
294304 < StyledHr />
295305 < PropertyRow
296- value = { formState . config ?. auth ?. type ? formState . config . auth . type : scmAuthType [ 0 ] . id }
306+ value = {
307+ formState . config ?. auth ?. type ? formState . config . auth . type : supportedAuthTypes [ 0 ] . id
308+ }
297309 property = { {
298310 name : 'auth' ,
299- description : T . translate ( `${ PREFIX } .auth.helperText` ) . toString ( ) ,
311+ description :
312+ supportedAuthTypes . length === 1
313+ ? T . translate ( `${ PREFIX } .auth.helperTextPatOnly` , {
314+ provider : formState ?. config ?. provider ,
315+ } ) . toString ( )
316+ : T . translate ( `${ PREFIX } .auth.helperText` ) . toString ( ) ,
300317 label : T . translate ( `${ PREFIX } .auth.label` ) . toString ( ) ,
301318 'widget-type' : 'radio-group' ,
302319 'widget-attributes' : {
303- default : scmAuthType [ 0 ] . id ,
320+ default : supportedAuthTypes [ 0 ] . id ,
304321 layout : 'inline' ,
305- options : scmAuthType ,
322+ options : supportedAuthTypes ,
306323 } ,
307324 } }
308325 onChange = { ( val ) => {
309326 handleValueChange ( val , 'type' ) ;
310327 } }
311328 />
312- { formState . config ?. auth ?. type === scmAuthType [ 0 ] . id && (
313- < >
314- < PropertyRow
315- value = { formState . config ?. auth ?. patConfig ?. passwordName }
316- property = { {
317- name : 'tokenName' ,
318- description : T . translate ( `${ PREFIX } .auth.pat.tokenNameHelperText` ) . toString ( ) ,
319- label : T . translate ( `${ PREFIX } .auth.pat.tokenName` ) . toString ( ) ,
320- required : true ,
321- } }
322- onChange = { ( val ) => {
323- handleValueChange ( val , 'passwordName' ) ;
324- } }
325- errors = {
326- ! formState . config ?. auth ?. patConfig ?. passwordName && formState . error
327- ? [ { msg : T . translate ( 'commons.requiredFieldMissingMsg' ) . toString ( ) } ]
328- : [ ]
329- }
330- />
331- < PropertyRow
332- value = { formState . config ?. auth ?. token }
333- property = { {
334- name : 'token' ,
335- description : T . translate ( `${ PREFIX } .auth.pat.tokenHelperText` , {
336- provider : formState . config ?. provider || providers . github ,
337- } ) . toString ( ) ,
338- label : T . translate ( `${ PREFIX } .auth.pat.token` ) . toString ( ) ,
339- required : ! isEdit ,
340- 'widget-type' : 'password' ,
341- } }
342- onChange = { ( val ) => {
343- handleValueChange ( val , 'token' ) ;
344- } }
345- errors = {
346- ! formState . config ?. auth ?. token && formState . error
347- ? [ { msg : T . translate ( 'commons.requiredFieldMissingMsg' ) . toString ( ) } ]
348- : [ ]
349- }
350- />
351- < PropertyRow
352- value = { formState . config ?. auth ?. patConfig ?. username }
353- property = { {
354- name : 'username' ,
355- description : T . translate ( `${ PREFIX } .auth.pat.usernameHelperText` ) . toString ( ) ,
356- label : T . translate ( `${ PREFIX } .auth.pat.username` ) . toString ( ) ,
357- } }
358- onChange = { ( val ) => {
359- handleValueChange ( val , 'username' ) ;
360- } }
361- />
362- </ >
363- ) }
329+ < PropertyRow
330+ value = { formState . config ?. auth ?. patConfig ?. passwordName }
331+ property = { {
332+ name : 'tokenName' ,
333+ description : T . translate ( `${ PREFIX } .auth.pat.tokenNameHelperText` ) . toString ( ) ,
334+ label : T . translate ( `${ PREFIX } .auth.pat.tokenName` ) . toString ( ) ,
335+ required : true ,
336+ } }
337+ onChange = { ( val ) => {
338+ handleValueChange ( val , 'passwordName' ) ;
339+ } }
340+ errors = {
341+ ! formState . config ?. auth ?. patConfig ?. passwordName && formState . error
342+ ? [ { msg : T . translate ( 'commons.requiredFieldMissingMsg' ) . toString ( ) } ]
343+ : [ ]
344+ }
345+ />
346+ < PropertyRow
347+ value = { formState . config ?. auth ?. token }
348+ property = { {
349+ name : 'token' ,
350+ description : T . translate ( `${ PREFIX } .auth.pat.tokenHelperText` , {
351+ provider : formState . config ?. provider || providers . github ,
352+ } ) . toString ( ) ,
353+ label : T . translate ( `${ PREFIX } .auth.pat.token` ) . toString ( ) ,
354+ required : ! isEdit ,
355+ 'widget-type' : 'password' ,
356+ } }
357+ onChange = { ( val ) => {
358+ handleValueChange ( val , 'token' ) ;
359+ } }
360+ errors = {
361+ ! formState . config ?. auth ?. token && formState . error
362+ ? [ { msg : T . translate ( 'commons.requiredFieldMissingMsg' ) . toString ( ) } ]
363+ : [ ]
364+ }
365+ />
366+ < PropertyRow
367+ value = { formState . config ?. auth ?. patConfig ?. username }
368+ property = { {
369+ name : 'username' ,
370+ description : T . translate ( `${ PREFIX } .auth.pat.usernameHelperText` ) . toString ( ) ,
371+ label : T . translate ( `${ PREFIX } .auth.pat.username` ) . toString ( ) ,
372+ } }
373+ onChange = { ( val ) => {
374+ handleValueChange ( val , 'username' ) ;
375+ } }
376+ />
364377 </ StyledGroup >
365378 </ StyledForm >
366379 < StyledButtonGroup >
0 commit comments