@@ -12,10 +12,12 @@ import {
12
12
} from '@elastic/eui'
13
13
import { Field , FieldInputProps , FieldMetaProps , Form , Formik , FormikErrors , FormikHelpers } from 'formik'
14
14
import React , { useEffect , useState } from 'react'
15
-
16
15
import cx from 'classnames'
16
+ import { isNull } from 'lodash'
17
+
17
18
import { SECURITY_FIELD } from 'uiSrc/constants'
18
19
import { RdiInstance } from 'uiSrc/slices/interfaces'
20
+ import { getFormUpdates , Nullable } from 'uiSrc/utils'
19
21
import ValidationTooltip from './components/ValidationTooltip'
20
22
21
23
import styles from './styles.module.scss'
@@ -24,7 +26,7 @@ export interface ConnectionFormValues {
24
26
name : string
25
27
url : string
26
28
username : string
27
- password : string
29
+ password : Nullable < string >
28
30
}
29
31
30
32
export interface Props {
@@ -38,7 +40,7 @@ const getInitialValues = (values: RdiInstance | null): ConnectionFormValues => (
38
40
name : values ?. name || '' ,
39
41
url : values ?. url || '' ,
40
42
username : values ?. username || '' ,
41
- password : ! values ? '' : SECURITY_FIELD
43
+ password : values ? null : ''
42
44
} )
43
45
44
46
const UrlTooltip = ( ) => (
@@ -89,20 +91,26 @@ const ConnectionForm = (props: Props) => {
89
91
if ( ! values . username ) {
90
92
errors . username = 'Username'
91
93
}
92
- if ( ! values . password ) {
94
+ // password is security field we did not received it from BE
95
+ if ( ! values . password && ! isNull ( values . password ) ) {
93
96
errors . password = 'Password'
94
97
}
95
98
96
99
return errors
97
100
}
98
101
102
+ const handleSubmit = ( values : ConnectionFormValues ) => {
103
+ const updates = getFormUpdates ( values , editInstance || { } )
104
+ onSubmit ( updates )
105
+ }
106
+
99
107
return (
100
108
< Formik
101
109
enableReinitialize
102
110
initialValues = { initialFormValues }
103
111
validateOnMount
104
112
validate = { validate }
105
- onSubmit = { onSubmit }
113
+ onSubmit = { handleSubmit }
106
114
>
107
115
{ ( { isValid, errors } ) => (
108
116
< Form className = { styles . form } >
@@ -169,8 +177,9 @@ const ConnectionForm = (props: Props) => {
169
177
placeholder = "Enter Password"
170
178
maxLength = { 500 }
171
179
{ ...field }
180
+ value = { isNull ( field . value ) ? SECURITY_FIELD : field . value }
172
181
onFocus = { ( ) => {
173
- if ( field . value === SECURITY_FIELD && ! meta . touched ) {
182
+ if ( isNull ( field . value ) && ! meta . touched ) {
174
183
form . setFieldValue ( 'password' , '' )
175
184
}
176
185
} }
0 commit comments