Skip to content

Commit 88142b1

Browse files
authored
Merge pull request #3996 from RedisInsight/fe/feature/RI-6171
RI-6171 User cannot create vector index using form
2 parents 9a6c5bc + 0077fd4 commit 88142b1

File tree

5 files changed

+26
-65
lines changed

5 files changed

+26
-65
lines changed

redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndex.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ const keyTypeOptions = KEY_TYPE_OPTIONS.map((item) => {
5353
}
5454
})
5555

56-
const initialFieldValue = (fieldTypeOptions: EuiSuperSelectOption<string>[], id = 0) => ({ id, identifier: '', fieldType: fieldTypeOptions[0].value })
56+
const initialFieldValue = (fieldTypeOptions: EuiSuperSelectOption<string>[], id = 0) => ({
57+
id,
58+
identifier: '',
59+
fieldType: fieldTypeOptions[0]?.value || ''
60+
})
5761

5862
const CreateRedisearchIndex = ({ onClosePanel, onCreateIndex }: Props) => {
5963
const { viewType } = useSelector(keysSelector)
@@ -63,7 +67,7 @@ const CreateRedisearchIndex = ({ onClosePanel, onCreateIndex }: Props) => {
6367
const [keyTypeSelected, setKeyTypeSelected] = useState<RedisearchIndexKeyType>(keyTypeOptions[0].value)
6468
const [prefixes, setPrefixes] = useState<EuiComboBoxOptionOption[]>([])
6569
const [indexName, setIndexName] = useState<string>('')
66-
const [fieldTypeOptions, setFieldTypeOptions] = useState<EuiSuperSelectOption<string>[]>(getFieldTypeOptions(modules))
70+
const [fieldTypeOptions, setFieldTypeOptions] = useState<EuiSuperSelectOption<string>[]>(getFieldTypeOptions)
6771
const [fields, setFields] = useState<any[]>([initialFieldValue(fieldTypeOptions)])
6872

6973
const [isInfoPopoverOpen, setIsInfoPopoverOpen] = useState<boolean>(false)
@@ -81,7 +85,7 @@ const CreateRedisearchIndex = ({ onClosePanel, onCreateIndex }: Props) => {
8185
}, [fields.length])
8286

8387
useEffect(() => {
84-
setFieldTypeOptions(getFieldTypeOptions(modules))
88+
setFieldTypeOptions(getFieldTypeOptions)
8589
}, [modules])
8690

8791
const addField = () => {

redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndexWrapper.spec.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,12 @@ describe('CreateRedisearchIndexWrapper', () => {
116116
expect(screen.getByTestId('identifier-info-icon')).toBeInTheDocument()
117117
})
118118

119-
it('should not have geoshape option ', () => {
119+
it('should not have geoshape option', () => {
120120
const { queryByText } = render(<CreateRedisearchIndexWrapper onClosePanel={onClose} />)
121121

122122
fireEvent.click(screen.getByTestId('field-type-0'))
123123

124124
expect(queryByText('GEOSHAPE')).not.toBeInTheDocument()
125-
})
126-
127-
it('should have geoshape option ', () => {
128-
const connectedInstanceSelectorMock = jest.fn().mockReturnValueOnce({
129-
id: '1',
130-
modules: [{ name: 'search', semanticVersion: '2.8.4' }]
131-
})
132-
connectedInstanceSelector.mockImplementation(connectedInstanceSelectorMock)
133-
134-
const { queryByText } = render(<CreateRedisearchIndexWrapper onClosePanel={onClose} />)
135-
fireEvent.click(screen.getByTestId('field-type-0'))
136-
137-
expect(queryByText('GEOSHAPE')).toBeInTheDocument()
125+
expect(queryByText('VECTOR')).not.toBeInTheDocument()
138126
})
139127
})

redisinsight/ui/src/pages/browser/components/create-redisearch-index/constants.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ export enum FieldTypes {
55
TAG = 'tag',
66
NUMERIC = 'numeric',
77
GEO = 'geo',
8-
VECTOR = 'vector',
9-
GEOSHAPE = 'geoshape',
108
}
119

1210
export enum RedisearchIndexKeyType {
@@ -44,12 +42,4 @@ export const FIELD_TYPE_OPTIONS = [
4442
text: 'GEO',
4543
value: FieldTypes.GEO,
4644
},
47-
{
48-
text: 'GEOSHAPE',
49-
value: FieldTypes.GEOSHAPE,
50-
},
51-
{
52-
text: 'VECTOR',
53-
value: FieldTypes.VECTOR,
54-
}
5545
]

redisinsight/ui/src/utils/redisearch.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
import { REDISEARCH_MODULES } from 'uiSrc/slices/interfaces'
2-
import { isVersionHigherOrEquals } from 'uiSrc/utils'
3-
import {
4-
REDISEARCH_GEOSHAPE_SEMANTIC_VERSION,
5-
REDISEARCH_GEOSHAPE_VERSION,
6-
} from 'uiSrc/constants'
7-
import { FIELD_TYPE_OPTIONS, FieldTypes } from 'uiSrc/pages/browser/components/create-redisearch-index/constants'
8-
import { AdditionalRedisModule } from 'apiSrc/modules/database/models/additional.redis.module'
1+
import { FIELD_TYPE_OPTIONS } from 'uiSrc/pages/browser/components/create-redisearch-index/constants'
92

10-
const isGeoshapeOptionAvailable = (modules: AdditionalRedisModule[]): boolean =>
11-
modules?.some(({ name, semanticVersion, version }) =>
12-
REDISEARCH_MODULES
13-
.some((search) => (
14-
name === search && (
15-
isVersionHigherOrEquals(semanticVersion, REDISEARCH_GEOSHAPE_SEMANTIC_VERSION)
16-
|| (version && version >= REDISEARCH_GEOSHAPE_VERSION)
17-
))))
18-
19-
export const getFieldTypeOptions = (modules: AdditionalRedisModule[] = []) => FIELD_TYPE_OPTIONS
20-
.filter((option) => option.value !== FieldTypes.GEOSHAPE || isGeoshapeOptionAvailable(modules))
3+
export const getFieldTypeOptions = () => FIELD_TYPE_OPTIONS
214
.map(({ value, text }) => ({
225
value,
236
inputDisplay: text,
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getFieldTypeOptions } from 'uiSrc/utils'
22
import { RedisDefaultModules } from 'uiSrc/slices/interfaces'
3-
import { FIELD_TYPE_OPTIONS, FieldTypes } from
3+
import { FIELD_TYPE_OPTIONS } from
44
'uiSrc/pages/browser/components/create-redisearch-index/constants'
55

66
const nameAndVersionToModule = ([name, semanticVersion, version]: any[]) => (
@@ -12,38 +12,34 @@ const ALL_OPTIONS = FIELD_TYPE_OPTIONS.map(({ value, text }) => ({
1212
inputDisplay: text,
1313
}))
1414

15-
const WITHOUT_GEOSHAPE_OPTIONS = ALL_OPTIONS.filter(({ value }) => value !== FieldTypes.GEOSHAPE)
16-
1715
const getFieldTypeOptionsTests: any[] = [
1816
[[['1', '2.8.4'], [RedisDefaultModules.Search, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS],
19-
[[['1', '2.8.4'], [RedisDefaultModules.Search, '2.8.3']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
17+
[[['1', '2.8.4'], [RedisDefaultModules.Search, '2.8.3']].map(nameAndVersionToModule), ALL_OPTIONS],
2018
[[['1', '2.8.3'], [RedisDefaultModules.SearchLight, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS],
21-
[[['1', '2.8.4'], [RedisDefaultModules.SearchLight, '2.8.3']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
19+
[[['1', '2.8.4'], [RedisDefaultModules.SearchLight, '2.8.3']].map(nameAndVersionToModule), ALL_OPTIONS],
2220
[[['1', '2.8.3'], [RedisDefaultModules.FT, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS],
23-
[[['1', '2.8.4'], [RedisDefaultModules.FT, '2.8.3']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
21+
[[['1', '2.8.4'], [RedisDefaultModules.FT, '2.8.3']].map(nameAndVersionToModule), ALL_OPTIONS],
2422
[[['1', '2.8.3'], [RedisDefaultModules.FTL, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS],
25-
[[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.3']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
26-
[[['1', '2.8.4'], [RedisDefaultModules.Gears, '2.8.4']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
23+
[[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.3']].map(nameAndVersionToModule), ALL_OPTIONS],
24+
[[['1', '2.8.4'], [RedisDefaultModules.Gears, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS],
2725
[[['1', '2.8.4'], [RedisDefaultModules.Search, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS],
28-
[[['1', '2.8.4'], [RedisDefaultModules.Search, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
29-
[[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS],
30-
[[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
26+
[[['1', '2.8.4'], [RedisDefaultModules.Search, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS],
3127
[[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS],
32-
[[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
28+
[[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS],
3329
[[['1', '2.8.4'], [RedisDefaultModules.FT, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS],
34-
[[['1', '2.8.4'], [RedisDefaultModules.FT, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
30+
[[['1', '2.8.4'], [RedisDefaultModules.FT, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS],
3531
[[['1', '2.8.4'], [RedisDefaultModules.FTL, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS],
36-
[[['1', '2.8.4'], [RedisDefaultModules.FTL, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
37-
[[['1', '2.8.4'], [RedisDefaultModules.Gears, undefined, 20804]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
38-
[[['1', '2.8.4'], [RedisDefaultModules.Gears, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
39-
[[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.3', 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS],
32+
[[['1', '2.8.4'], [RedisDefaultModules.FTL, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS],
33+
[[['1', '2.8.4'], [RedisDefaultModules.Gears, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS],
34+
[[['1', '2.8.4'], [RedisDefaultModules.Gears, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS],
35+
[[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.3', 20803]].map(nameAndVersionToModule), ALL_OPTIONS],
4036
[[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.4', 20804]].map(nameAndVersionToModule), ALL_OPTIONS],
4137
]
4238

4339
describe('getFieldTypeOptions', () => {
4440
it.each(getFieldTypeOptionsTests)('for input: %s (type), should be output: %s',
45-
(type, expected) => {
46-
const result = getFieldTypeOptions(type)
41+
(_, expected) => {
42+
const result = getFieldTypeOptions()
4743
expect(result).toEqual(expected)
4844
})
4945
})

0 commit comments

Comments
 (0)