diff --git a/redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndex.tsx b/redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndex.tsx index 0f5e8c0edd..dd9dbfc343 100644 --- a/redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndex.tsx +++ b/redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndex.tsx @@ -53,7 +53,11 @@ const keyTypeOptions = KEY_TYPE_OPTIONS.map((item) => { } }) -const initialFieldValue = (fieldTypeOptions: EuiSuperSelectOption[], id = 0) => ({ id, identifier: '', fieldType: fieldTypeOptions[0].value }) +const initialFieldValue = (fieldTypeOptions: EuiSuperSelectOption[], id = 0) => ({ + id, + identifier: '', + fieldType: fieldTypeOptions[0]?.value || '' +}) const CreateRedisearchIndex = ({ onClosePanel, onCreateIndex }: Props) => { const { viewType } = useSelector(keysSelector) @@ -63,7 +67,7 @@ const CreateRedisearchIndex = ({ onClosePanel, onCreateIndex }: Props) => { const [keyTypeSelected, setKeyTypeSelected] = useState(keyTypeOptions[0].value) const [prefixes, setPrefixes] = useState([]) const [indexName, setIndexName] = useState('') - const [fieldTypeOptions, setFieldTypeOptions] = useState[]>(getFieldTypeOptions(modules)) + const [fieldTypeOptions, setFieldTypeOptions] = useState[]>(getFieldTypeOptions) const [fields, setFields] = useState([initialFieldValue(fieldTypeOptions)]) const [isInfoPopoverOpen, setIsInfoPopoverOpen] = useState(false) @@ -81,7 +85,7 @@ const CreateRedisearchIndex = ({ onClosePanel, onCreateIndex }: Props) => { }, [fields.length]) useEffect(() => { - setFieldTypeOptions(getFieldTypeOptions(modules)) + setFieldTypeOptions(getFieldTypeOptions) }, [modules]) const addField = () => { diff --git a/redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndexWrapper.spec.tsx b/redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndexWrapper.spec.tsx index 0023850ea0..9e4bbddf9b 100644 --- a/redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndexWrapper.spec.tsx +++ b/redisinsight/ui/src/pages/browser/components/create-redisearch-index/CreateRedisearchIndexWrapper.spec.tsx @@ -116,24 +116,12 @@ describe('CreateRedisearchIndexWrapper', () => { expect(screen.getByTestId('identifier-info-icon')).toBeInTheDocument() }) - it('should not have geoshape option ', () => { + it('should not have geoshape option', () => { const { queryByText } = render() fireEvent.click(screen.getByTestId('field-type-0')) expect(queryByText('GEOSHAPE')).not.toBeInTheDocument() - }) - - it('should have geoshape option ', () => { - const connectedInstanceSelectorMock = jest.fn().mockReturnValueOnce({ - id: '1', - modules: [{ name: 'search', semanticVersion: '2.8.4' }] - }) - connectedInstanceSelector.mockImplementation(connectedInstanceSelectorMock) - - const { queryByText } = render() - fireEvent.click(screen.getByTestId('field-type-0')) - - expect(queryByText('GEOSHAPE')).toBeInTheDocument() + expect(queryByText('VECTOR')).not.toBeInTheDocument() }) }) diff --git a/redisinsight/ui/src/pages/browser/components/create-redisearch-index/constants.ts b/redisinsight/ui/src/pages/browser/components/create-redisearch-index/constants.ts index bce64093c5..afde715b26 100644 --- a/redisinsight/ui/src/pages/browser/components/create-redisearch-index/constants.ts +++ b/redisinsight/ui/src/pages/browser/components/create-redisearch-index/constants.ts @@ -5,8 +5,6 @@ export enum FieldTypes { TAG = 'tag', NUMERIC = 'numeric', GEO = 'geo', - VECTOR = 'vector', - GEOSHAPE = 'geoshape', } export enum RedisearchIndexKeyType { @@ -44,12 +42,4 @@ export const FIELD_TYPE_OPTIONS = [ text: 'GEO', value: FieldTypes.GEO, }, - { - text: 'GEOSHAPE', - value: FieldTypes.GEOSHAPE, - }, - { - text: 'VECTOR', - value: FieldTypes.VECTOR, - } ] diff --git a/redisinsight/ui/src/utils/redisearch.ts b/redisinsight/ui/src/utils/redisearch.ts index 690fe6ddc4..7a8fcd2bfb 100644 --- a/redisinsight/ui/src/utils/redisearch.ts +++ b/redisinsight/ui/src/utils/redisearch.ts @@ -1,23 +1,6 @@ -import { REDISEARCH_MODULES } from 'uiSrc/slices/interfaces' -import { isVersionHigherOrEquals } from 'uiSrc/utils' -import { - REDISEARCH_GEOSHAPE_SEMANTIC_VERSION, - REDISEARCH_GEOSHAPE_VERSION, -} from 'uiSrc/constants' -import { FIELD_TYPE_OPTIONS, FieldTypes } from 'uiSrc/pages/browser/components/create-redisearch-index/constants' -import { AdditionalRedisModule } from 'apiSrc/modules/database/models/additional.redis.module' +import { FIELD_TYPE_OPTIONS } from 'uiSrc/pages/browser/components/create-redisearch-index/constants' -const isGeoshapeOptionAvailable = (modules: AdditionalRedisModule[]): boolean => - modules?.some(({ name, semanticVersion, version }) => - REDISEARCH_MODULES - .some((search) => ( - name === search && ( - isVersionHigherOrEquals(semanticVersion, REDISEARCH_GEOSHAPE_SEMANTIC_VERSION) - || (version && version >= REDISEARCH_GEOSHAPE_VERSION) - )))) - -export const getFieldTypeOptions = (modules: AdditionalRedisModule[] = []) => FIELD_TYPE_OPTIONS - .filter((option) => option.value !== FieldTypes.GEOSHAPE || isGeoshapeOptionAvailable(modules)) +export const getFieldTypeOptions = () => FIELD_TYPE_OPTIONS .map(({ value, text }) => ({ value, inputDisplay: text, diff --git a/redisinsight/ui/src/utils/tests/redisearch.spec.ts b/redisinsight/ui/src/utils/tests/redisearch.spec.ts index 703ba565a2..ba2c91836b 100644 --- a/redisinsight/ui/src/utils/tests/redisearch.spec.ts +++ b/redisinsight/ui/src/utils/tests/redisearch.spec.ts @@ -1,6 +1,6 @@ import { getFieldTypeOptions } from 'uiSrc/utils' import { RedisDefaultModules } from 'uiSrc/slices/interfaces' -import { FIELD_TYPE_OPTIONS, FieldTypes } from +import { FIELD_TYPE_OPTIONS } from 'uiSrc/pages/browser/components/create-redisearch-index/constants' const nameAndVersionToModule = ([name, semanticVersion, version]: any[]) => ( @@ -12,38 +12,34 @@ const ALL_OPTIONS = FIELD_TYPE_OPTIONS.map(({ value, text }) => ({ inputDisplay: text, })) -const WITHOUT_GEOSHAPE_OPTIONS = ALL_OPTIONS.filter(({ value }) => value !== FieldTypes.GEOSHAPE) - const getFieldTypeOptionsTests: any[] = [ [[['1', '2.8.4'], [RedisDefaultModules.Search, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.Search, '2.8.3']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.Search, '2.8.3']].map(nameAndVersionToModule), ALL_OPTIONS], [[['1', '2.8.3'], [RedisDefaultModules.SearchLight, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.SearchLight, '2.8.3']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.SearchLight, '2.8.3']].map(nameAndVersionToModule), ALL_OPTIONS], [[['1', '2.8.3'], [RedisDefaultModules.FT, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.FT, '2.8.3']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.FT, '2.8.3']].map(nameAndVersionToModule), ALL_OPTIONS], [[['1', '2.8.3'], [RedisDefaultModules.FTL, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.3']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.Gears, '2.8.4']].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.3']].map(nameAndVersionToModule), ALL_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.Gears, '2.8.4']].map(nameAndVersionToModule), ALL_OPTIONS], [[['1', '2.8.4'], [RedisDefaultModules.Search, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.Search, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.Search, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS], [[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.SearchLight, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS], [[['1', '2.8.4'], [RedisDefaultModules.FT, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.FT, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.FT, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS], [[['1', '2.8.4'], [RedisDefaultModules.FTL, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.FTL, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.Gears, undefined, 20804]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.Gears, undefined, 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], - [[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.3', 20803]].map(nameAndVersionToModule), WITHOUT_GEOSHAPE_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.FTL, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.Gears, undefined, 20804]].map(nameAndVersionToModule), ALL_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.Gears, undefined, 20803]].map(nameAndVersionToModule), ALL_OPTIONS], + [[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.3', 20803]].map(nameAndVersionToModule), ALL_OPTIONS], [[['1', '2.8.4'], [RedisDefaultModules.FTL, '2.8.4', 20804]].map(nameAndVersionToModule), ALL_OPTIONS], ] describe('getFieldTypeOptions', () => { it.each(getFieldTypeOptionsTests)('for input: %s (type), should be output: %s', - (type, expected) => { - const result = getFieldTypeOptions(type) + (_, expected) => { + const result = getFieldTypeOptions() expect(result).toEqual(expected) }) })