mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 03:36:36 +08:00
refactor: Simplify tag label retrieval in hooks and update related components
This commit is contained in:
parent
d790d2bc89
commit
a061215e42
@ -26,9 +26,16 @@ export const useTags = (translateFromOut?: TFunction) => {
|
|||||||
return acc
|
return acc
|
||||||
}, {} as Record<string, Tag>)
|
}, {} as Record<string, Tag>)
|
||||||
|
|
||||||
|
const getTagLabel = (name: string) => {
|
||||||
|
if (!tagsMap[name])
|
||||||
|
return name
|
||||||
|
return tagsMap[name].label
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tags,
|
tags,
|
||||||
tagsMap,
|
tagsMap,
|
||||||
|
getTagLabel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ const CardWrapper = ({
|
|||||||
setFalse: hideInstallFromMarketplace,
|
setFalse: hideInstallFromMarketplace,
|
||||||
}] = useBoolean(false)
|
}] = useBoolean(false)
|
||||||
const { locale: localeFromLocale } = useI18N()
|
const { locale: localeFromLocale } = useI18N()
|
||||||
const { tagsMap } = useTags(t)
|
const { getTagLabel } = useTags(t)
|
||||||
|
|
||||||
if (showInstallButton) {
|
if (showInstallButton) {
|
||||||
return (
|
return (
|
||||||
@ -43,7 +43,7 @@ const CardWrapper = ({
|
|||||||
footer={
|
footer={
|
||||||
<CardMoreInfo
|
<CardMoreInfo
|
||||||
downloadCount={plugin.install_count}
|
downloadCount={plugin.install_count}
|
||||||
tags={plugin.tags.map(tag => tagsMap[tag.name].label)}
|
tags={plugin.tags.map(tag => getTagLabel(tag.name))}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@ -92,7 +92,7 @@ const CardWrapper = ({
|
|||||||
footer={
|
footer={
|
||||||
<CardMoreInfo
|
<CardMoreInfo
|
||||||
downloadCount={plugin.install_count}
|
downloadCount={plugin.install_count}
|
||||||
tags={plugin.tags.map(tag => tagsMap[tag.name].label)}
|
tags={plugin.tags.map(tag => getTagLabel(tag.name))}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -27,7 +27,7 @@ const TagsFilter = ({
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [searchText, setSearchText] = useState('')
|
const [searchText, setSearchText] = useState('')
|
||||||
const { tags: options, tagsMap } = useTags()
|
const { tags: options, getTagLabel } = useTags()
|
||||||
const filteredOptions = options.filter(option => option.name.toLowerCase().includes(searchText.toLowerCase()))
|
const filteredOptions = options.filter(option => option.name.toLowerCase().includes(searchText.toLowerCase()))
|
||||||
const handleCheck = (id: string) => {
|
const handleCheck = (id: string) => {
|
||||||
if (value.includes(id))
|
if (value.includes(id))
|
||||||
@ -59,7 +59,7 @@ const TagsFilter = ({
|
|||||||
!selectedTagsLength && t('pluginTags.allTags')
|
!selectedTagsLength && t('pluginTags.allTags')
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
!!selectedTagsLength && value.map(val => tagsMap[val].label).slice(0, 2).join(',')
|
!!selectedTagsLength && value.map(val => getTagLabel(val)).slice(0, 2).join(',')
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
selectedTagsLength > 2 && (
|
selectedTagsLength > 2 && (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user