Skip to content

Commit 5de82f2

Browse files
Merge pull request #3435 from RedisInsight/fe/bugfix/RI-5791_fix_password_edit_field
#RI-5791 - fix password field
2 parents c960ea4 + 05a16cc commit 5de82f2

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

redisinsight/ui/src/pages/rdi/home/RdiPage.spec.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,28 @@ describe('RdiPage', () => {
206206
)
207207
})
208208

209+
it('should not pass password when password did not changed', async () => {
210+
render(<RdiPage />)
211+
212+
fireEvent.click(screen.getByTestId('edit-instance-1'))
213+
await screen.findByTestId('connection-form')
214+
215+
await act(() => {
216+
fireEvent.change(screen.getByTestId('connection-form-name-input'), { target: { value: 'name' } })
217+
218+
// submit form
219+
fireEvent.click(screen.getByTestId('connection-form-add-button'))
220+
})
221+
222+
expect(editInstanceAction).toBeCalledWith(
223+
'1',
224+
{
225+
name: 'name',
226+
},
227+
expect.any(Function)
228+
)
229+
})
230+
209231
it('should call create instance when editInstance is not provided', async () => {
210232
render(<RdiPage />)
211233

redisinsight/ui/src/pages/rdi/home/RdiPage.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
sendPageViewTelemetry
1818
} from 'uiSrc/telemetry'
1919
import HomePageTemplate from 'uiSrc/templates/home-page-template'
20-
import { getFormUpdates, setTitle } from 'uiSrc/utils'
20+
import { setTitle } from 'uiSrc/utils'
2121
import EmptyMessage from './empty-message/EmptyMessage'
2222
import ConnectionForm from './connection-form/ConnectionForm'
2323
import RdiHeader from './header/RdiHeader'
@@ -60,8 +60,7 @@ const RdiPage = () => {
6060
}
6161

6262
if (editInstance) {
63-
const payload = getFormUpdates(instance, editInstance)
64-
dispatch(editInstanceAction(editInstance.id, payload, onSuccess))
63+
dispatch(editInstanceAction(editInstance.id, instance, onSuccess))
6564
} else {
6665
dispatch(createInstanceAction({ ...instance }, onSuccess))
6766
}

redisinsight/ui/src/pages/rdi/home/connection-form/ConnectionForm.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import {
1212
} from '@elastic/eui'
1313
import { Field, FieldInputProps, FieldMetaProps, Form, Formik, FormikErrors, FormikHelpers } from 'formik'
1414
import React, { useEffect, useState } from 'react'
15-
1615
import cx from 'classnames'
16+
import { isNull } from 'lodash'
17+
1718
import { SECURITY_FIELD } from 'uiSrc/constants'
1819
import { RdiInstance } from 'uiSrc/slices/interfaces'
20+
import { getFormUpdates, Nullable } from 'uiSrc/utils'
1921
import ValidationTooltip from './components/ValidationTooltip'
2022

2123
import styles from './styles.module.scss'
@@ -24,7 +26,7 @@ export interface ConnectionFormValues {
2426
name: string
2527
url: string
2628
username: string
27-
password: string
29+
password: Nullable<string>
2830
}
2931

3032
export interface Props {
@@ -38,7 +40,7 @@ const getInitialValues = (values: RdiInstance | null): ConnectionFormValues => (
3840
name: values?.name || '',
3941
url: values?.url || '',
4042
username: values?.username || '',
41-
password: !values ? '' : SECURITY_FIELD
43+
password: values ? null : ''
4244
})
4345

4446
const UrlTooltip = () => (
@@ -89,20 +91,26 @@ const ConnectionForm = (props: Props) => {
8991
if (!values.username) {
9092
errors.username = 'Username'
9193
}
92-
if (!values.password) {
94+
// password is security field we did not received it from BE
95+
if (!values.password && !isNull(values.password)) {
9396
errors.password = 'Password'
9497
}
9598

9699
return errors
97100
}
98101

102+
const handleSubmit = (values: ConnectionFormValues) => {
103+
const updates = getFormUpdates(values, editInstance || {})
104+
onSubmit(updates)
105+
}
106+
99107
return (
100108
<Formik
101109
enableReinitialize
102110
initialValues={initialFormValues}
103111
validateOnMount
104112
validate={validate}
105-
onSubmit={onSubmit}
113+
onSubmit={handleSubmit}
106114
>
107115
{({ isValid, errors }) => (
108116
<Form className={styles.form}>
@@ -169,8 +177,9 @@ const ConnectionForm = (props: Props) => {
169177
placeholder="Enter Password"
170178
maxLength={500}
171179
{...field}
180+
value={isNull(field.value) ? SECURITY_FIELD : field.value}
172181
onFocus={() => {
173-
if (field.value === SECURITY_FIELD && !meta.touched) {
182+
if (isNull(field.value) && !meta.touched) {
174183
form.setFieldValue('password', '')
175184
}
176185
}}

0 commit comments

Comments
 (0)