Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions redisinsight/ui/src/pages/home/components/form/DbIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,23 @@ const DbIndex = (props: Props) => {
</Row>

{formik.values.showDb && (
<>
<Spacer />
<Row gap="m" responsive>
<FlexItem grow className={styles.dbInput}>
<FormField label="Database Index">
<NumericInput
autoValidate
min={0}
name="db"
id="db"
data-testid="db"
placeholder="Enter Database Index"
value={Number(formik.values.db)}
onChange={(value) => formik.setFieldValue('db', value)}
/>
</FormField>
</FlexItem>
<FlexItem grow />
</Row>
</>
<Row gap="m" responsive>
<FlexItem grow className={styles.dbInput}>
<FormField label="Database Index">
<NumericInput
autoValidate
min={0}
name="db"
id="db"
data-testid="db"
placeholder="Enter Database Index"
value={Number(formik.values.db)}
onChange={(value) => formik.setFieldValue('db', value)}
/>
</FormField>
</FlexItem>
<FlexItem grow />
</Row>
)}
</>
)
Expand Down
310 changes: 147 additions & 163 deletions redisinsight/ui/src/pages/home/components/form/SSHDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ import {
} from 'uiSrc/components/base/inputs'
import { Checkbox } from 'uiSrc/components/base/forms/checkbox/Checkbox'
import { RiRadioGroup } from 'uiSrc/components/base/forms/radio-group/RadioGroup'
import { Spacer } from 'uiSrc/components/base/layout'
import { Text } from 'uiSrc/components/base/text/Text'
import { useGenerateId } from 'uiSrc/components/base/utils/hooks/generate-id'

export interface Props {
flexGroupClassName?: string
flexItemClassName?: string
formik: FormikProps<DbConnectionInfo>
}

Expand All @@ -43,191 +40,178 @@ const sshPassTypeOptions = [
]

const SSHDetails = (props: Props) => {
const { flexGroupClassName = '', flexItemClassName = '', formik } = props
const { formik } = props
const id = useGenerateId('', ' ssh')

return (
<Col gap="m">
<Row
className={flexGroupClassName}
align={!flexGroupClassName ? 'end' : undefined}
>
<FlexItem style={{ width: '230px' }} className={flexItemClassName}>
<FormField>
<Checkbox
id={id}
name="ssh"
label={<Text>Use SSH Tunnel</Text>}
checked={!!formik.values.ssh}
onChange={formik.handleChange}
data-testid="use-ssh"
/>
</FormField>
</FlexItem>
<Row>
<FormField>
<Checkbox
id={id}
name="ssh"
label={<Text>Use SSH Tunnel</Text>}
checked={!!formik.values.ssh}
onChange={formik.handleChange}
data-testid="use-ssh"
/>
</FormField>
</Row>

{formik.values.ssh && (
<>
<Spacer size="xs" />
<Col gap="m">
<Row gap="m" responsive className={flexGroupClassName}>
<FlexItem grow className={flexItemClassName}>
<FormField label="Host" required>
<TextInput
name="sshHost"
id="sshHost"
data-testid="sshHost"
color="secondary"
maxLength={200}
placeholder="Enter SSH Host"
value={formik.values.sshHost ?? ''}
onChange={(value) => {
formik.setFieldValue(
'sshHost',
validateField(value.trim()),
)
}}
/>
</FormField>
</FlexItem>
<FlexItem grow className={flexItemClassName}>
<FormField label="Port" required>
<NumericInput
autoValidate
min={0}
max={MAX_PORT_NUMBER}
name="sshPort"
id="sshPort"
data-testid="sshPort"
placeholder="Enter SSH Port"
value={Number(formik.values.sshPort)}
onChange={(value) => formik.setFieldValue('sshPort', value)}
onFocus={selectOnFocus}
/>
</FormField>
</FlexItem>
</Row>
<Row responsive className={flexGroupClassName}>
<FlexItem grow className={flexItemClassName}>
<FormField label="Username" required>
<TextInput
name="sshUsername"
id="sshUsername"
data-testid="sshUsername"
color="secondary"
maxLength={200}
placeholder="Enter SSH Username"
value={formik.values.sshUsername ?? ''}
onChange={(value) => {
formik.setFieldValue(
'sshUsername',
validateField(value.trim()),
)
<Col gap="l">
<Row gap="m" responsive>
<FlexItem grow>
<FormField label="Host" required>
<TextInput
name="sshHost"
id="sshHost"
data-testid="sshHost"
color="secondary"
maxLength={200}
placeholder="Enter SSH Host"
value={formik.values.sshHost ?? ''}
onChange={(value) => {
formik.setFieldValue('sshHost', validateField(value.trim()))
}}
/>
</FormField>
</FlexItem>
<FlexItem grow>
<FormField label="Port" required>
<NumericInput
autoValidate
min={0}
max={MAX_PORT_NUMBER}
name="sshPort"
id="sshPort"
data-testid="sshPort"
placeholder="Enter SSH Port"
value={Number(formik.values.sshPort)}
onChange={(value) => formik.setFieldValue('sshPort', value)}
onFocus={selectOnFocus}
/>
</FormField>
</FlexItem>
</Row>
<Row responsive>
<FlexItem grow>
<FormField label="Username" required>
<TextInput
name="sshUsername"
id="sshUsername"
data-testid="sshUsername"
color="secondary"
maxLength={200}
placeholder="Enter SSH Username"
value={formik.values.sshUsername ?? ''}
onChange={(value) => {
formik.setFieldValue(
'sshUsername',
validateField(value.trim()),
)
}}
/>
</FormField>
</FlexItem>
</Row>
<Row responsive>
<FlexItem grow>
<RiRadioGroup
id="sshPassType"
items={sshPassTypeOptions}
layout="horizontal"
value={formik.values.sshPassType}
onChange={(id) => formik.setFieldValue('sshPassType', id)}
data-testid="ssh-pass-type"
/>
</FlexItem>
</Row>
{formik.values.sshPassType === SshPassType.Password && (
<Row responsive>
<FlexItem grow>
<FormField label="Password">
<PasswordInput
name="sshPassword"
id="sshPassword"
data-testid="sshPassword"
maxLength={10_000}
placeholder="Enter SSH Password"
value={
formik.values.sshPassword === true
? SECURITY_FIELD
: (formik.values.sshPassword ?? '')
}
onChangeCapture={formik.handleChange}
onFocus={() => {
if (formik.values.sshPassword === true) {
formik.setFieldValue('sshPassword', '')
}
}}
autoComplete="new-password"
/>
</FormField>
</FlexItem>
</Row>
<Row responsive className={flexGroupClassName}>
<FlexItem grow className={flexItemClassName}>
<Spacer size="m" />
<RiRadioGroup
id="sshPassType"
items={sshPassTypeOptions}
layout="horizontal"
value={formik.values.sshPassType}
onChange={(id) => formik.setFieldValue('sshPassType', id)}
data-testid="ssh-pass-type"
/>
<Spacer size="s" />
</FlexItem>
</Row>
{formik.values.sshPassType === SshPassType.Password && (
<Row responsive className={flexGroupClassName}>
<FlexItem grow className={flexItemClassName}>
<FormField label="Password">
)}

{formik.values.sshPassType === SshPassType.PrivateKey && (
<Col gap="l">
<Row responsive>
<FlexItem grow>
<FormField label="Private Key" required>
<TextArea
name="sshPrivateKey"
id="sshPrivateKey"
data-testid="sshPrivateKey"
maxLength={50_000}
placeholder="Enter SSH Private Key in PEM format"
value={
formik.values.sshPrivateKey === true
? SECURITY_FIELD
: (formik?.values?.sshPrivateKey?.replace(
/./g,
'•',
) ?? '')
}
onChangeCapture={formik.handleChange}
onFocus={() => {
if (formik.values.sshPrivateKey === true) {
formik.setFieldValue('sshPrivateKey', '')
}
}}
/>
</FormField>
</FlexItem>
</Row>
<Row responsive>
<FlexItem grow>
<FormField label="Passphrase">
<PasswordInput
name="sshPassword"
id="sshPassword"
data-testid="sshPassword"
maxLength={10_000}
placeholder="Enter SSH Password"
name="sshPassphrase"
id="sshPassphrase"
data-testid="sshPassphrase"
maxLength={50_000}
placeholder="Enter Passphrase for Private Key"
value={
formik.values.sshPassword === true
formik.values.sshPassphrase === true
? SECURITY_FIELD
: (formik.values.sshPassword ?? '')
: (formik.values.sshPassphrase ?? '')
}
onChangeCapture={formik.handleChange}
onFocus={() => {
if (formik.values.sshPassword === true) {
formik.setFieldValue('sshPassword', '')
if (formik.values.sshPassphrase === true) {
formik.setFieldValue('sshPassphrase', '')
}
}}
autoComplete="new-password"
/>
</FormField>
</FlexItem>
</Row>
)}

{formik.values.sshPassType === SshPassType.PrivateKey && (
<Col gap="l">
<Row responsive className={flexGroupClassName}>
<FlexItem grow className={flexItemClassName}>
<FormField label="Private Key" required>
<TextArea
name="sshPrivateKey"
id="sshPrivateKey"
data-testid="sshPrivateKey"
maxLength={50_000}
placeholder="Enter SSH Private Key in PEM format"
value={
formik.values.sshPrivateKey === true
? SECURITY_FIELD
: (formik?.values?.sshPrivateKey?.replace(
/./g,
'•',
) ?? '')
}
onChangeCapture={formik.handleChange}
onFocus={() => {
if (formik.values.sshPrivateKey === true) {
formik.setFieldValue('sshPrivateKey', '')
}
}}
/>
</FormField>
</FlexItem>
</Row>
<Row responsive className={flexGroupClassName}>
<FlexItem grow className={flexItemClassName}>
<FormField label="Passphrase">
<PasswordInput
name="sshPassphrase"
id="sshPassphrase"
data-testid="sshPassphrase"
maxLength={50_000}
placeholder="Enter Passphrase for Private Key"
value={
formik.values.sshPassphrase === true
? SECURITY_FIELD
: (formik.values.sshPassphrase ?? '')
}
onChangeCapture={formik.handleChange}
onFocus={() => {
if (formik.values.sshPassphrase === true) {
formik.setFieldValue('sshPassphrase', '')
}
}}
autoComplete="new-password"
/>
</FormField>
</FlexItem>
</Row>
</Col>
)}
</Col>
</>
</Col>
)}
</Col>
)}
</Col>
)
Expand Down
Loading
Loading