mirror of https://github.com/langgenius/dify.git
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
|
||||
}, {} as Record<string, Tag>)
|
||||
|
||||
const getTagLabel = (name: string) => {
|
||||
if (!tagsMap[name])
|
||||
return name
|
||||
return tagsMap[name].label
|
||||
}
|
||||
|
||||
return {
|
||||
tags,
|
||||
tagsMap,
|
||||
getTagLabel,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ const CardWrapper = ({
|
|||
setFalse: hideInstallFromMarketplace,
|
||||
}] = useBoolean(false)
|
||||
const { locale: localeFromLocale } = useI18N()
|
||||
const { tagsMap } = useTags(t)
|
||||
const { getTagLabel } = useTags(t)
|
||||
|
||||
if (showInstallButton) {
|
||||
return (
|
||||
|
|
@ -43,7 +43,7 @@ const CardWrapper = ({
|
|||
footer={
|
||||
<CardMoreInfo
|
||||
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={
|
||||
<CardMoreInfo
|
||||
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 [open, setOpen] = useState(false)
|
||||
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 handleCheck = (id: string) => {
|
||||
if (value.includes(id))
|
||||
|
|
@ -59,7 +59,7 @@ const TagsFilter = ({
|
|||
!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 && (
|
||||
|
|
|
|||
Loading…
Reference in New Issue