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
@@ -1,19 +1,8 @@
import React, { useState } from 'react'

import { RiTooltip } from 'uiSrc/components'
import { TextInput } from 'uiSrc/components/base/inputs'
import { TagSuggestions } from './TagSuggestions'

type TagInputFieldProps = {
value: string
disabled?: boolean
currentTagKeys: Set<string>
suggestedTagKey?: string
rightContent?: React.ReactNode
errorMessage?: string
placeholder?: string
onChange: (value: string) => void
}
import { TagInputFieldProps } from './TagInputField.types'

export const TagInputField = ({
value,
Expand All @@ -30,7 +19,7 @@ export const TagInputField = ({

return (
<div>
<RiTooltip content={errorMessage} position="top">
<span>
<TextInput
value={value}
disabled={disabled}
Expand Down Expand Up @@ -58,7 +47,7 @@ export const TagInputField = ({
}}
/>
)}
</RiTooltip>
</span>
{rightContent}
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type TagInputFieldProps = {
value: string
disabled?: boolean
currentTagKeys: Set<string>
suggestedTagKey?: string
rightContent?: React.ReactNode
errorMessage?: string
placeholder?: string
onChange: (value: string) => void
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,35 @@
}: TagSuggestionsProps) => {
const { data: allTags } = useSelector(tagsSelector)
const tagsSuggestions: SelectOption[] = useMemo(() => {
const options = uniqBy(presetTagSuggestions.concat(allTags), (tag) =>
targetKey ? tag.value : tag.key,
)
.filter(({ key, value }) => {
if (targetKey !== undefined) {
return (
key === targetKey && value !== '' && value.includes(searchTerm)
)
}
const options = uniqBy(presetTagSuggestions.concat(allTags), (tag) =>
targetKey ? tag.value : tag.key,
)
.filter(({ key, value }) => {
if (targetKey !== undefined) {
return key === targetKey && value !== '' && value.includes(searchTerm)
}

return (
key.includes(searchTerm) &&
(!currentTagKeys.has(key) || key === searchTerm)
)
})
.map(({ key, value }) => ({
label: targetKey ? value : key,
value: targetKey ? value : key,
}))
return (
key.includes(searchTerm) &&
(!currentTagKeys.has(key) || key === searchTerm)

Check warning on line 39 in redisinsight/ui/src/pages/home/components/database-manage-tags-modal/TagSuggestions.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
)
})
.map(({ key, value }) => ({
label: targetKey ? value : key,
value: targetKey ? value : key,
}))

const isNewTag = options.length === 0 && searchTerm
const isNewTag = options.length === 0 && searchTerm

Check warning on line 47 in redisinsight/ui/src/pages/home/components/database-manage-tags-modal/TagSuggestions.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

if (isNewTag) {
options.push({
label: `${searchTerm} (new ${targetKey ? 'value' : 'tag'})`,
value: searchTerm,
})
}
if (isNewTag) {
options.push({
label: `${searchTerm} (new ${targetKey ? 'value' : 'tag'})`,

Check warning on line 51 in redisinsight/ui/src/pages/home/components/database-manage-tags-modal/TagSuggestions.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 51 in redisinsight/ui/src/pages/home/components/database-manage-tags-modal/TagSuggestions.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
value: searchTerm,
})

Check warning on line 53 in redisinsight/ui/src/pages/home/components/database-manage-tags-modal/TagSuggestions.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 54 in redisinsight/ui/src/pages/home/components/database-manage-tags-modal/TagSuggestions.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

return options
}, [allTags, targetKey, searchTerm, currentTagKeys])
return options
}, [allTags, targetKey, searchTerm, currentTagKeys])

if (tagsSuggestions.length === 0) {
return null
Expand Down
Loading