dify/web/app/components/plugins/provider-card.tsx

98 lines
3.6 KiB
TypeScript
Raw Normal View History

'use client'
2024-10-11 16:21:03 +08:00
import React from 'react'
import type { FC } from 'react'
2024-10-31 20:19:40 +08:00
import { useTranslation } from 'react-i18next'
2024-11-02 12:09:59 +08:00
import { RiArrowRightUpLine } from '@remixicon/react'
2024-10-11 16:21:03 +08:00
import Badge from '../base/badge'
import type { Plugin } from './types'
import Description from './card/base/description'
import Icon from './card/base/card-icon'
import Title from './card/base/title'
import DownloadCount from './card/base/download-count'
import Button from '@/app/components/base/button'
2024-11-06 15:57:50 +08:00
import InstallFromMarketplace from '@/app/components/plugins/install-plugin/install-from-marketplace'
2024-10-11 16:21:03 +08:00
import cn from '@/utils/classnames'
2024-11-06 15:57:50 +08:00
import { useBoolean } from 'ahooks'
2024-12-03 14:34:23 +08:00
import { getPluginLinkInMarketplace } from '@/app/components/plugins/marketplace/utils'
import { useI18N } from '@/context/i18n'
2025-01-03 10:16:44 +08:00
import { useRenderI18nObject } from '@/hooks/use-i18n'
2024-10-11 16:21:03 +08:00
type Props = {
className?: string
payload: Plugin
}
const ProviderCard: FC<Props> = ({
className,
payload,
}) => {
2025-01-03 10:16:44 +08:00
const getValueFromI18nObject = useRenderI18nObject()
2024-10-31 20:19:40 +08:00
const { t } = useTranslation()
2024-11-06 15:57:50 +08:00
const [isShowInstallFromMarketplace, {
setTrue: showInstallFromMarketplace,
setFalse: hideInstallFromMarketplace,
}] = useBoolean(false)
2024-10-11 16:21:03 +08:00
const { org, label } = payload
2024-12-03 14:34:23 +08:00
const { locale } = useI18N()
2024-10-11 16:21:03 +08:00
return (
2024-12-13 14:06:07 +08:00
<div className={cn('group relative p-4 pb-3 border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg hover:bg-components-panel-on-panel-item-bg rounded-xl shadow-xs', className)}>
2024-10-31 19:58:22 +08:00
{/* Header */}
<div className="flex">
<Icon src={payload.icon} />
<div className="ml-3 w-0 grow">
<div className="flex items-center h-5">
2025-01-03 10:16:44 +08:00
<Title title={getValueFromI18nObject(label)} />
2024-11-02 12:09:59 +08:00
{/* <RiVerifiedBadgeLine className="shrink-0 ml-0.5 w-4 h-4 text-text-accent" /> */}
2024-10-31 19:58:22 +08:00
</div>
<div className='mb-1 flex justify-between items-center h-4'>
<div className='flex items-center'>
<div className='text-text-tertiary system-xs-regular'>{org}</div>
<div className='mx-2 text-text-quaternary system-xs-regular'>·</div>
<DownloadCount downloadCount={payload.install_count || 0} />
2024-10-11 16:21:03 +08:00
</div>
</div>
</div>
2024-10-31 19:58:22 +08:00
</div>
2025-01-03 10:16:44 +08:00
<Description className='mt-3' text={getValueFromI18nObject(payload.brief)} descriptionLineRows={2}></Description>
2024-10-31 19:58:22 +08:00
<div className='mt-3 flex space-x-0.5'>
{payload.tags.map(tag => (
<Badge key={tag.name} text={tag.name} />
))}
</div>
<div
2024-12-13 14:06:07 +08:00
className='hidden group-hover:flex items-center gap-2 absolute bottom-0 left-0 right-0 p-4 pt-8 rounded-xl bg-gradient-to-tr from-components-panel-on-panel-item-bg to-background-gradient-mask-transparent'
2024-10-31 19:58:22 +08:00
>
<Button
2024-11-19 16:24:35 +08:00
className='grow'
2024-10-31 19:58:22 +08:00
variant='primary'
2024-11-06 15:57:50 +08:00
onClick={showInstallFromMarketplace}
2024-10-31 19:58:22 +08:00
>
2024-10-31 20:19:40 +08:00
{t('plugin.detailPanel.operation.install')}
2024-10-31 19:58:22 +08:00
</Button>
<Button
2024-11-19 16:24:35 +08:00
className='grow'
2024-10-31 19:58:22 +08:00
variant='secondary'
>
2024-12-03 14:34:23 +08:00
<a href={`${getPluginLinkInMarketplace(payload)}?language=${locale}`} target='_blank' className='flex items-center gap-0.5'>
2024-10-31 20:19:40 +08:00
{t('plugin.detailPanel.operation.detail')}
2024-10-31 19:58:22 +08:00
<RiArrowRightUpLine className='w-4 h-4' />
</a>
</Button>
</div>
2024-11-06 15:57:50 +08:00
{
isShowInstallFromMarketplace && (
<InstallFromMarketplace
manifest={payload as any}
uniqueIdentifier={payload.latest_package_identifier}
onClose={hideInstallFromMarketplace}
onSuccess={() => hideInstallFromMarketplace()}
2024-11-06 15:57:50 +08:00
/>
)
}
2024-10-11 16:21:03 +08:00
</div>
)
}
export default ProviderCard