mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 00:33:37 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: jyong <718720800@qq.com> Co-authored-by: Yansong Zhang <916125788@qq.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: hj24 <mambahj24@gmail.com> Co-authored-by: hj24 <huangjian@dify.ai> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Ayush Baluni <73417844+aayushbaluni@users.noreply.github.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: jimcody1995 <jjimcody@gmail.com> Co-authored-by: James <63717587+jamesrayammons@users.noreply.github.com> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: Stephen Zhou <hi@hyoban.cc> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: jerryzai <jerryzh8710@protonmail.com> Co-authored-by: NVIDIAN <speedy.hpc@hotmail.com> Co-authored-by: ai-hpc <ai-hpc@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Junghwan <70629228+shaun0927@users.noreply.github.com> Co-authored-by: HeYinKazune <70251095+HeYin-OS@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Jingyi <jingyi.qi@dify.ai> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: sxxtony <166789813+sxxtony@users.noreply.github.com>
121 lines
4.1 KiB
TypeScript
121 lines
4.1 KiB
TypeScript
'use client'
|
|
import type { Plugin } from '../types'
|
|
import { useTranslation } from '#i18n'
|
|
import { cn } from '@langgenius/dify-ui/cn'
|
|
import { RiAlertFill } from '@remixicon/react'
|
|
import * as React from 'react'
|
|
import { useSelector } from '@/context/app-context'
|
|
import { useGetLanguage } from '@/context/i18n'
|
|
import useTheme from '@/hooks/use-theme'
|
|
import {
|
|
renderI18nObject,
|
|
} from '@/i18n-config'
|
|
import { Theme } from '@/types/app'
|
|
import Partner from '../base/badges/partner'
|
|
import Verified from '../base/badges/verified'
|
|
import Icon from '../card/base/card-icon'
|
|
import { useCategories } from '../hooks'
|
|
import { getPluginCardIconUrl } from '../utils'
|
|
import CornerMark from './base/corner-mark'
|
|
import Description from './base/description'
|
|
import OrgInfo from './base/org-info'
|
|
import Placeholder from './base/placeholder'
|
|
import Title from './base/title'
|
|
|
|
type Props = {
|
|
className?: string
|
|
payload: Plugin
|
|
titleLeft?: React.ReactNode
|
|
installed?: boolean
|
|
installFailed?: boolean
|
|
hideCornerMark?: boolean
|
|
descriptionLineRows?: number
|
|
footer?: React.ReactNode
|
|
isLoading?: boolean
|
|
loadingFileName?: string
|
|
limitedInstall?: boolean
|
|
}
|
|
|
|
const Card = ({
|
|
className,
|
|
payload,
|
|
titleLeft,
|
|
installed,
|
|
installFailed,
|
|
hideCornerMark,
|
|
descriptionLineRows = 2,
|
|
footer,
|
|
isLoading = false,
|
|
loadingFileName,
|
|
limitedInstall = false,
|
|
}: Props) => {
|
|
const locale = useGetLanguage()
|
|
const { t } = useTranslation()
|
|
const { categoriesMap } = useCategories(true)
|
|
const currentWorkspaceId = useSelector(s => s.currentWorkspace.id)
|
|
const { category, type, name, org, label, brief, icon, icon_dark, verified, badges = [], from } = payload
|
|
const { theme } = useTheme()
|
|
const iconSrc = getPluginCardIconUrl(
|
|
{ from, name, org, type },
|
|
theme === Theme.dark && icon_dark ? icon_dark : icon,
|
|
currentWorkspaceId,
|
|
)
|
|
const getLocalizedText = (obj: Record<string, string> | undefined) =>
|
|
obj ? renderI18nObject(obj, locale) : ''
|
|
const isPartner = badges.includes('partner')
|
|
|
|
const wrapClassName = cn('hover-bg-components-panel-on-panel-item-bg relative overflow-hidden rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg shadow-xs', className)
|
|
if (isLoading) {
|
|
return (
|
|
<Placeholder
|
|
wrapClassName={wrapClassName}
|
|
loadingFileName={loadingFileName!}
|
|
/>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className={wrapClassName}>
|
|
<div className={cn('p-4 pb-3', limitedInstall && 'pb-1')}>
|
|
{!hideCornerMark && <CornerMark text={categoriesMap[type === 'bundle' ? type : category]?.label!} />}
|
|
{/* Header */}
|
|
<div className="flex">
|
|
<Icon src={iconSrc} installed={installed} installFailed={installFailed} />
|
|
<div className="ml-3 w-0 grow">
|
|
<div className="flex h-5 items-center">
|
|
<Title title={getLocalizedText(label)} />
|
|
{isPartner && <Partner className="ml-0.5 h-4 w-4" text={t('marketplace.partnerTip', { ns: 'plugin' })} />}
|
|
{verified && <Verified className="ml-0.5 h-4 w-4" text={t('marketplace.verifiedTip', { ns: 'plugin' })} />}
|
|
{titleLeft}
|
|
{' '}
|
|
{/* This can be version badge */}
|
|
</div>
|
|
<OrgInfo
|
|
className="mt-0.5"
|
|
orgName={org}
|
|
packageName={name}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<Description
|
|
className="mt-3"
|
|
text={getLocalizedText(brief)}
|
|
descriptionLineRows={descriptionLineRows}
|
|
/>
|
|
{!!footer && <div>{footer}</div>}
|
|
</div>
|
|
{limitedInstall
|
|
&& (
|
|
<div className="relative flex h-8 items-center gap-x-2 px-3 after:absolute after:top-0 after:right-0 after:bottom-0 after:left-0 after:bg-toast-warning-bg after:opacity-40">
|
|
<RiAlertFill className="h-3 w-3 shrink-0 text-text-warning-secondary" />
|
|
<p className="z-10 grow system-xs-regular text-text-secondary">
|
|
{t('installModal.installWarning', { ns: 'plugin' })}
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default React.memo(Card)
|