11import React from "react" ;
2+ import { yupResolver } from "@hookform/resolvers/yup" ;
3+ import { AxiosError } from "axios" ;
4+ import { FormProvider , useForm } from "react-hook-form" ;
25import { useTranslation } from "react-i18next" ;
36import * as yup from "yup" ;
4- import { AxiosError } from "axios" ;
57import {
68 ActionGroup ,
79 Button ,
810 ButtonVariant ,
911 Form ,
1012} from "@patternfly/react-core" ;
11- import { FormProvider , useForm } from "react-hook-form" ;
12- import { yupResolver } from "@hookform/resolvers/yup" ;
1313
14- import { OptionWithValue , SimpleSelect } from "@app/components/SimpleSelect" ;
1514import { Identity , IdentityKind , IdentityKinds , New } from "@app/api/models" ;
16- import { duplicateNameCheck , getAxiosErrorMessage } from "@app/utils/utils" ;
17- import { toOptionLike } from "@app/utils/model-utils" ;
18- import {
19- useCreateIdentityMutation ,
20- useFetchIdentities ,
21- useUpdateIdentityMutation ,
22- } from "@app/queries/identities" ;
2315import {
2416 HookFormPFGroupController ,
2517 HookFormPFTextInput ,
2618} from "@app/components/HookFormPFFields" ;
2719import { NotificationsContext } from "@app/components/NotificationsContext" ;
20+ import { OptionWithValue , SimpleSelect } from "@app/components/SimpleSelect" ;
21+ import {
22+ useCreateIdentityMutation ,
23+ useFetchIdentities ,
24+ useUpdateIdentityMutation ,
25+ } from "@app/queries/identities" ;
26+ import { toOptionLike } from "@app/utils/model-utils" ;
27+ import { duplicateNameCheck , getAxiosErrorMessage } from "@app/utils/utils" ;
2828
2929import { KIND_OPTIONS } from "../../utils" ;
30- import { KindSourceForm } from "./kind-source-form" ;
31- import { KindAssetForm } from "./kind-asset -form" ;
30+
31+ import { KindBearerTokenForm } from "./kind-bearer-token -form" ;
3232import { KindMavenSettingsFileForm } from "./kind-maven-settings-file-form" ;
3333import { KindSimpleUsernamePasswordForm } from "./kind-simple-username-password-form" ;
34- import { KindBearerTokenForm } from "./kind-bearer-token -form" ;
34+ import { KindSourceForm } from "./kind-source -form" ;
3535
3636import "./identity-form.css" ;
3737
@@ -70,7 +70,7 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
7070 const getUserCredentialsInitialValue = (
7171 identity ?: Identity
7272 ) : UserCredentials | undefined => {
73- if ( "source" === identity ?. kind || "asset" === identity ?. kind ) {
73+ if ( "source" === identity ?. kind ) {
7474 if ( identity ?. user && identity ?. password ) {
7575 return "userpass" ;
7676 } else {
@@ -159,20 +159,6 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
159159 } ) ;
160160 }
161161
162- if ( kind === "asset" && formValues . userCredentials === "source" ) {
163- Object . assign ( payload , {
164- key : formValues . key ,
165- password : formValues . password . trim ( ) ,
166- } ) ;
167- }
168-
169- if ( kind === "asset" && formValues . userCredentials === "userpass" ) {
170- Object . assign ( payload , {
171- user : formValues . user . trim ( ) ,
172- password : formValues . password . trim ( ) ,
173- } ) ;
174- }
175-
176162 if ( kind === "basic-auth" ) {
177163 Object . assign ( payload , {
178164 user : formValues . user . trim ( ) ,
@@ -237,7 +223,7 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
237223 default : yup . bool ( ) . defined ( ) ,
238224
239225 userCredentials : yup . mixed < UserCredentials > ( ) . when ( "kind" , {
240- is : ( kind : IdentityKind ) => kind === "source" || kind === "asset" ,
226+ is : ( kind : IdentityKind ) => kind === "source" ,
241227 then : ( schema ) => schema . required ( ) . oneOf ( [ "userpass" , "source" ] ) ,
242228 } ) ,
243229
@@ -259,16 +245,6 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
259245 . string ( )
260246 . defined ( )
261247 . trim ( )
262- . when ( [ "kind" , "userCredentials" ] , {
263- is : ( kind : IdentityKind , userCredentials : UserCredentials ) =>
264- ( kind === "source" || kind === "asset" ) &&
265- userCredentials === "userpass" ,
266- then : ( schema ) =>
267- schema
268- . required ( t ( "validation.required" ) )
269- . min ( 3 , t ( "validation.minLength" , { length : 3 } ) )
270- . max ( 120 , t ( "validation.maxLength" , { length : 120 } ) ) ,
271- } )
272248 . when ( "kind" , {
273249 is : ( kind : IdentityKind ) => kind === "proxy" ,
274250 then : ( schema ) =>
@@ -285,6 +261,15 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
285261 . min ( 3 , t ( "validation.minLength" , { length : 3 } ) )
286262 . max ( 120 , t ( "validation.maxLength" , { length : 120 } ) )
287263 . email ( "Username must be a valid email" ) ,
264+ } )
265+ . when ( [ "kind" , "userCredentials" ] , {
266+ is : ( kind : IdentityKind , userCredentials : UserCredentials ) =>
267+ kind === "source" && userCredentials === "userpass" ,
268+ then : ( schema ) =>
269+ schema
270+ . required ( t ( "validation.required" ) )
271+ . min ( 3 , t ( "validation.minLength" , { length : 3 } ) )
272+ . max ( 120 , t ( "validation.maxLength" , { length : 120 } ) ) ,
288273 } ) ,
289274 password : yup
290275 . string ( )
@@ -308,8 +293,7 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
308293 } )
309294 . when ( [ "kind" , "userCredentials" ] , {
310295 is : ( kind : IdentityKind , userCredentials : UserCredentials ) =>
311- ( kind === "source" || kind === "asset" ) &&
312- userCredentials === "userpass" ,
296+ kind === "source" && userCredentials === "userpass" ,
313297 then : ( schema ) =>
314298 schema
315299 . required ( t ( "validation.required" ) )
@@ -322,8 +306,7 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
322306 . defined ( )
323307 . when ( [ "kind" , "userCredentials" ] , {
324308 is : ( kind : IdentityKind , userCredentials : UserCredentials ) =>
325- ( kind === "source" || kind === "asset" ) &&
326- userCredentials === "source" ,
309+ kind === "source" && userCredentials === "source" ,
327310 // If we want to verify key contents before saving, add the yup test in the then function
328311 then : ( schema ) => schema . required ( t ( "validation.required" ) ) ,
329312 } )
@@ -417,8 +400,6 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
417400 />
418401 ) }
419402
420- { values ?. kind === "asset" && < KindAssetForm identity = { identity } /> }
421-
422403 { values ?. kind === "maven" && (
423404 < KindMavenSettingsFileForm
424405 identity = { identity }
0 commit comments