Skip to content

Commit 36b03fa

Browse files
authored
Merge pull request #1506 from RedisInsight/feature/RI-3541_prepopulate-fields
#RI-3541 - add default values for fields, update host for autodiscovery
2 parents 7bcd750 + 7e65095 commit 36b03fa

File tree

11 files changed

+107
-45
lines changed

11 files changed

+107
-45
lines changed

redisinsight/api/src/modules/autodiscovery/utils/autodiscovery.util.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,39 +124,39 @@ describe('getTCPEndpoints', () => {
124124
name: 'win output',
125125
input: mockWinNetstat.split('\n'),
126126
output: [
127-
{ host: 'localhost', port: 5000 },
128-
{ host: 'localhost', port: 6379 },
129-
{ host: 'localhost', port: 6380 },
130-
{ host: 'localhost', port: 135 },
131-
{ host: 'localhost', port: 445 },
132-
{ host: 'localhost', port: 808 },
133-
{ host: 'localhost', port: 2701 },
127+
{ host: '127.0.0.1', port: 5000 },
128+
{ host: '127.0.0.1', port: 6379 },
129+
{ host: '127.0.0.1', port: 6380 },
130+
{ host: '127.0.0.1', port: 135 },
131+
{ host: '127.0.0.1', port: 445 },
132+
{ host: '127.0.0.1', port: 808 },
133+
{ host: '127.0.0.1', port: 2701 },
134134
],
135135
},
136136
{
137137
name: 'linux output',
138138
input: mockLinuxNetstat.split('\n'),
139139
output: [
140-
{ host: 'localhost', port: 5000 },
141-
{ host: 'localhost', port: 6379 },
142-
{ host: 'localhost', port: 6380 },
143-
{ host: 'localhost', port: 28100 },
144-
{ host: 'localhost', port: 8100 },
145-
{ host: 'localhost', port: 8101 },
146-
{ host: 'localhost', port: 8102 },
147-
{ host: 'localhost', port: 8103 },
148-
{ host: 'localhost', port: 8200 },
140+
{ host: '127.0.0.1', port: 5000 },
141+
{ host: '127.0.0.1', port: 6379 },
142+
{ host: '127.0.0.1', port: 6380 },
143+
{ host: '127.0.0.1', port: 28100 },
144+
{ host: '127.0.0.1', port: 8100 },
145+
{ host: '127.0.0.1', port: 8101 },
146+
{ host: '127.0.0.1', port: 8102 },
147+
{ host: '127.0.0.1', port: 8103 },
148+
{ host: '127.0.0.1', port: 8200 },
149149
],
150150
},
151151
{
152152
name: 'mac output',
153153
input: mockMacNetstat.split('\n'),
154154
output: [
155-
{ host: 'localhost', port: 5000 },
156-
{ host: 'localhost', port: 6379 },
157-
{ host: 'localhost', port: 6380 },
158-
{ host: 'localhost', port: 5002 },
159-
{ host: 'localhost', port: 52167 },
155+
{ host: '127.0.0.1', port: 5000 },
156+
{ host: '127.0.0.1', port: 6379 },
157+
{ host: '127.0.0.1', port: 6380 },
158+
{ host: '127.0.0.1', port: 5002 },
159+
{ host: '127.0.0.1', port: 52167 },
160160
],
161161
},
162162
];

redisinsight/api/src/modules/autodiscovery/utils/autodiscovery.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const getTCPEndpoints = (processes: string[]): IEndpoint[] => {
5757

5858
if (match) {
5959
endpoints.set(match[4], {
60-
host: 'localhost',
60+
host: '127.0.0.1',
6161
port: parseInt(match[4], 10),
6262
});
6363
}

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceForm/InstanceForm.spec.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
3-
import { render, screen, fireEvent, act } from 'uiSrc/utils/test-utils'
4-
import { ConnectionType } from 'uiSrc/slices/interfaces'
5-
import InstanceForm, {
6-
ADD_NEW_CA_CERT,
7-
DbConnectionInfo,
8-
Props,
9-
} from './InstanceForm'
3+
import { act, fireEvent, render, screen } from 'uiSrc/utils/test-utils'
4+
import { ConnectionType, InstanceType } from 'uiSrc/slices/interfaces'
5+
import InstanceForm, { ADD_NEW_CA_CERT, DbConnectionInfo, Props, } from './InstanceForm'
106

117
const BTN_SUBMIT = 'btn-submit'
128
const NEW_CA_CERT = 'new-ca-cert'
@@ -613,5 +609,29 @@ describe('InstanceForm', () => {
613609
)
614610
expect(screen.getByTestId('db-alias')).toHaveTextContent('Clone ')
615611
})
612+
613+
it('should render proper default values for standalone', () => {
614+
render(
615+
<InstanceForm
616+
{...instance(mockedProps)}
617+
formFields={{}}
618+
/>
619+
)
620+
expect(screen.getByTestId('host')).toHaveValue('127.0.0.1')
621+
expect(screen.getByTestId('port')).toHaveValue('6379')
622+
expect(screen.getByTestId('name')).toHaveValue('127.0.0.1:6379')
623+
})
624+
625+
it('should render proper default values for sentinel', () => {
626+
render(
627+
<InstanceForm
628+
{...instance(mockedProps)}
629+
instanceType={InstanceType.Sentinel}
630+
formFields={{}}
631+
/>
632+
)
633+
expect(screen.getByTestId('host')).toHaveValue('127.0.0.1')
634+
expect(screen.getByTestId('port')).toHaveValue('26379')
635+
})
616636
})
617637
})

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceForm/InstanceForm.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848

4949
import { ConnectionType, Instance, InstanceType, } from 'uiSrc/slices/interfaces'
5050
import { getRedisModulesSummary, sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
51-
import { handlePasteHostName, getDiffKeysOfObjectValues, checkRediStackModules } from 'uiSrc/utils'
51+
import { handlePasteHostName, getDiffKeysOfObjectValues, checkRediStackModules, selectOnFocus } from 'uiSrc/utils'
5252
import {
5353
MAX_PORT_NUMBER,
5454
validateCertName,
@@ -137,12 +137,15 @@ const getInitFieldsDisplayNames = ({ host, port, name, instanceType }: any) => {
137137
return {}
138138
}
139139

140+
const getDefaultHost = () => '127.0.0.1'
141+
const getDefaultPort = (instanceType: InstanceType) => (instanceType === InstanceType.Sentinel ? '26379' : '6379')
142+
140143
const AddStandaloneForm = (props: Props) => {
141144
const {
142145
formFields: {
143146
id,
144147
host,
145-
name = '',
148+
name,
146149
port,
147150
tls,
148151
db = null,
@@ -181,9 +184,9 @@ const AddStandaloneForm = (props: Props) => {
181184
const { contextInstanceId, lastPage } = useSelector(appContextSelector)
182185

183186
const prepareInitialValues = () => ({
184-
host,
185-
port: port?.toString(),
186-
name,
187+
host: host ?? getDefaultHost(),
188+
port: port ? port.toString() : getDefaultPort(instanceType),
189+
name: name ?? `${getDefaultHost()}:${getDefaultPort(instanceType)}`,
187190
username,
188191
password,
189192
tls,
@@ -674,7 +677,7 @@ const AddStandaloneForm = (props: Props) => {
674677
<EuiFlexItem className={flexItemClassName}>
675678
<EuiFormRow label="Host*">
676679
<EuiFieldText
677-
autoFocus={!isCloneMode}
680+
autoFocus={!isCloneMode && isEditMode}
678681
name="host"
679682
id="host"
680683
data-testid="host"
@@ -688,8 +691,8 @@ const AddStandaloneForm = (props: Props) => {
688691
validateField(e.target.value.trim())
689692
)
690693
}}
691-
onPaste={(event: React.ClipboardEvent<HTMLInputElement>) =>
692-
handlePasteHostName(onHostNamePaste, event)}
694+
onPaste={(event: React.ClipboardEvent<HTMLInputElement>) => handlePasteHostName(onHostNamePaste, event)}
695+
onFocus={selectOnFocus}
693696
append={<AppendHostName />}
694697
/>
695698
</EuiFormRow>
@@ -711,6 +714,7 @@ const AddStandaloneForm = (props: Props) => {
711714
validatePortNumber(e.target.value.trim())
712715
)
713716
}}
717+
onFocus={selectOnFocus}
714718
type="text"
715719
min={0}
716720
max={MAX_PORT_NUMBER}
@@ -734,6 +738,7 @@ const AddStandaloneForm = (props: Props) => {
734738
id="name"
735739
data-testid="name"
736740
placeholder="Enter Database Alias"
741+
onFocus={selectOnFocus}
737742
value={formik.values.name ?? ''}
738743
maxLength={500}
739744
onChange={formik.handleChange}

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceFormWrapper.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ export enum TitleDatabaseText {
5454
}
5555

5656
const getInitialValues = (editedInstance: Nullable<Instance>) => ({
57-
host: editedInstance?.host ?? '',
58-
port: editedInstance?.port?.toString() ?? '',
59-
name: editedInstance?.name ?? '',
57+
// undefined - to show default value, empty string - for existing db
58+
host: editedInstance?.host ?? (editedInstance ? '' : undefined),
59+
port: editedInstance?.port?.toString() ?? (editedInstance ? '' : undefined),
60+
name: editedInstance?.name ?? (editedInstance ? '' : undefined),
6061
username: editedInstance?.username ?? '',
6162
password: editedInstance?.password ?? '',
6263
tls: !!editedInstance?.tls ?? false,
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import handlePasteHostName from './handlePasteHostName'
2+
import selectOnFocus from './selectOnFocus'
3+
4+
export {
5+
handlePasteHostName,
6+
selectOnFocus
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const selectOnFocus = (e: React.FocusEvent, callback?: (e: React.FocusEvent) => void) => {
2+
(e.target as HTMLInputElement)?.select()
3+
callback?.(e)
4+
}
5+
6+
export default selectOnFocus

redisinsight/ui/src/utils/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Nullable, Maybe } from './types'
2-
import handlePasteHostName from './handlePasteHostName'
32
import getLetterByIndex from './getLetterByIndex'
43
import RouterWithSubRoutes from './routerWithSubRoutes'
54

@@ -26,11 +25,11 @@ export * from './formatters'
2625
export * from './groupTypes'
2726
export * from './modules'
2827
export * from './optimizations'
28+
export * from './events'
2929

3030
export {
3131
Maybe,
3232
Nullable,
33-
handlePasteHostName,
3433
RouterWithSubRoutes,
3534
getLetterByIndex
3635
}

tests/e2e/tests/critical-path/a-first-start-form/autodiscovery.e2e.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test
2020
.after(async() => {
2121
// Delete all auto-discovered databases
2222
for(let i = 0; i < standalonePorts.length; i++) {
23-
await myRedisDatabasePage.deleteDatabaseByName(`localhost:${standalonePorts[i]}`);
23+
await myRedisDatabasePage.deleteDatabaseByName(`127.0.0.1:${standalonePorts[i]}`);
2424
}
2525
})('Verify that when users open application for the first time, they can see all auto-discovered Standalone DBs', async t => {
2626
// Check that standalone DBs have been added into the application
@@ -29,11 +29,12 @@ test
2929
const name = await myRedisDatabasePage.dbNameList.nth(k).textContent;
3030
console.log(`AUTODISCOVERY ${k}: ${name}`);
3131
}
32+
// Verify that user can see all the databases automatically discovered with 127.0.0.1 host instead of localhost
3233
for(let i = 0; i < standalonePorts.length; i++) {
33-
await t.expect(myRedisDatabasePage.dbNameList.withExactText(`localhost:${standalonePorts[i]}`).exists).ok('Standalone DBs');
34+
await t.expect(myRedisDatabasePage.dbNameList.withExactText(`127.0.0.1:${standalonePorts[i]}`).exists).ok('Standalone DBs');
3435
}
3536
// Check that Sentinel and OSS cluster have not been added into the application
3637
for(let j = 0; j < otherPorts.length; j++) {
37-
await t.expect(myRedisDatabasePage.dbNameList.withExactText(`localhost:${otherPorts[j]}`).exists).notOk('Sentinel and OSS DBs');
38+
await t.expect(myRedisDatabasePage.dbNameList.withExactText(`127.0.0.1:${otherPorts[j]}`).exists).notOk('Sentinel and OSS DBs');
3839
}
3940
});

0 commit comments

Comments
 (0)