@@ -4,57 +4,23 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
44import { zodResolver } from '@hookform/resolvers/zod' ;
55import { Input , Modal , Segmented } from 'antd' ;
66import { Controller , useForm } from 'react-hook-form' ;
7- import { z } from 'zod' ;
87
98import { FieldContainer } from '@ui/features/common/form/field-container' ;
109import { ModalComponentProps } from '@ui/features/common/modal/modal-context' ;
1110import { SegmentLabel } from '@ui/features/common/segment-label' ;
12- import { dnsRegex } from '@ui/features/common/utils' ;
1311import {
1412 createCredentials ,
1513 createProjectSecret ,
1614 updateCredentials ,
1715 updateProjectSecret
1816} from '@ui/gen/api/service/v1alpha1/service-KargoService_connectquery' ;
1917import { Secret } from '@ui/gen/k8s.io/api/core/v1/generated_pb' ;
20- import { zodValidators } from '@ui/utils/validators' ;
2118
19+ import { createFormSchema } from './schema-validator' ;
2220import { SecretEditor } from './secret-editor' ;
2321import { CredentialsType } from './types' ;
2422import { constructDefaults , labelForKey , typeLabel } from './utils' ;
2523
26- const createFormSchema = ( genericCreds : boolean , editing ?: boolean ) => {
27- let schema = z . object ( {
28- name : zodValidators . requiredString . regex (
29- dnsRegex ,
30- 'Credentials name must be a valid DNS subdomain.'
31- ) ,
32- description : z . string ( ) . optional ( ) ,
33- type : zodValidators . requiredString ,
34- repoUrl : zodValidators . requiredString ,
35- repoUrlIsRegex : z . boolean ( ) . optional ( ) ,
36- username : zodValidators . requiredString ,
37- password : editing ? z . string ( ) . optional ( ) : zodValidators . requiredString
38- } ) ;
39-
40- if ( genericCreds ) {
41- // @ts -expect-error err
42- schema = z . object ( {
43- name : zodValidators . requiredString . regex (
44- dnsRegex ,
45- 'Credentials name must be a valid DNS subdomain.'
46- ) ,
47- description : z . string ( ) . optional ( ) ,
48- type : zodValidators . requiredString ,
49- data : z . array ( z . array ( z . string ( ) ) )
50- } ) ;
51- }
52-
53- return schema . refine ( ( data ) => [ 'git' , 'helm' , 'image' , 'generic' ] . includes ( data . type ) , {
54- error : "Type must be one of 'git', 'helm', 'image' or 'generic'."
55- } ) ;
56- } ;
57-
5824const placeholders = {
5925 name : 'My Credentials' ,
6026 description : 'An optional description' ,
@@ -63,6 +29,19 @@ const placeholders = {
6329 password : '********'
6430} ;
6531
32+ const repoUrlPlaceholder = ( credType : CredentialsType ) => {
33+ switch ( credType ) {
34+ case 'git' :
35+ return placeholders . repoUrl ;
36+ case 'helm' :
37+ return 'ghcr.io/nginxinc/charts/nginx-ingress' ;
38+ case 'image' :
39+ return 'public.ecr.aws/nginx/nginx' ;
40+ }
41+
42+ return '' ;
43+ } ;
44+
6645const genericCredentialPlaceholders = {
6746 name : 'My Secret' ,
6847 description : placeholders . description
@@ -234,7 +213,9 @@ export const CreateCredentialsModal = ({ project, onSuccess, editing, init, ...p
234213 placeholder = {
235214 key === 'repoUrl' && repoUrlIsRegex
236215 ? repoUrlPatternPlaceholder
237- : placeholders [ key as keyof typeof placeholders ]
216+ : key === 'repoUrl'
217+ ? repoUrlPlaceholder ( credentialType )
218+ : placeholders [ key as keyof typeof placeholders ]
238219 }
239220 disabled = { editing && key === 'name' }
240221 />
0 commit comments