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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ const keyTypeOptions = KEY_TYPE_OPTIONS.map((item) => {
}
})

const initialFieldValue = (fieldTypeOptions: EuiSuperSelectOption<string>[], id = 0) => ({ id, identifier: '', fieldType: fieldTypeOptions[0].value })
const initialFieldValue = (fieldTypeOptions: EuiSuperSelectOption<string>[], id = 0) => ({
id,
identifier: '',
fieldType: fieldTypeOptions[0]?.value || ''
})

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

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

useEffect(() => {
setFieldTypeOptions(getFieldTypeOptions(modules))
setFieldTypeOptions(getFieldTypeOptions)
}, [modules])

const addField = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<CreateRedisearchIndexWrapper onClosePanel={onClose} />)

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(<CreateRedisearchIndexWrapper onClosePanel={onClose} />)
fireEvent.click(screen.getByTestId('field-type-0'))

expect(queryByText('GEOSHAPE')).toBeInTheDocument()
expect(queryByText('VECTOR')).not.toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export enum FieldTypes {
TAG = 'tag',
NUMERIC = 'numeric',
GEO = 'geo',
VECTOR = 'vector',
GEOSHAPE = 'geoshape',
}

export enum RedisearchIndexKeyType {
Expand Down Expand Up @@ -44,12 +42,4 @@ export const FIELD_TYPE_OPTIONS = [
text: 'GEO',
value: FieldTypes.GEO,
},
{
text: 'GEOSHAPE',
value: FieldTypes.GEOSHAPE,
},
{
text: 'VECTOR',
value: FieldTypes.VECTOR,
}
]
21 changes: 2 additions & 19 deletions redisinsight/ui/src/utils/redisearch.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
34 changes: 15 additions & 19 deletions redisinsight/ui/src/utils/tests/redisearch.spec.ts
Original file line number Diff line number Diff line change
@@ -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[]) => (
Expand All @@ -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)
})
})
Loading