dify/web/app/components/plugins/plugin-detail-panel/index.tsx

139 lines
5.5 KiB
TypeScript
Raw Normal View History

2024-10-12 12:35:56 +08:00
'use client'
2024-10-16 15:37:32 +08:00
import React, { useMemo } from 'react'
2024-10-12 12:35:56 +08:00
import type { FC } from 'react'
2024-10-16 15:37:32 +08:00
import { useContext } from 'use-context-selector'
2024-10-12 14:39:53 +08:00
import { useTranslation } from 'react-i18next'
2024-10-16 17:30:51 +08:00
import {
RiBugLine,
RiCloseLine,
RiHardDrive3Line,
2024-10-17 13:44:56 +08:00
RiVerifiedBadgeLine,
2024-10-16 17:30:51 +08:00
} from '@remixicon/react'
import type { PluginDetail } from '../types'
import { PluginSource } from '../types'
2024-10-17 08:49:29 +08:00
import Description from '../card/base/description'
2024-10-12 12:35:56 +08:00
import Icon from '../card/base/card-icon'
import Title from '../card/base/title'
2024-10-16 17:30:51 +08:00
import OrgInfo from '../card/base/org-info'
2024-10-12 14:39:53 +08:00
import OperationDropdown from './operation-dropdown'
2024-10-12 16:29:46 +08:00
import EndpointList from './endpoint-list'
import ActionList from './action-list'
import ModelList from './model-list'
2024-10-16 17:30:51 +08:00
import Badge from '@/app/components/base/badge'
import Tooltip from '@/app/components/base/tooltip'
2024-10-12 14:39:53 +08:00
import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin'
2024-10-16 17:30:51 +08:00
import { Github } from '@/app/components/base/icons/src/public/common'
2024-10-12 14:39:53 +08:00
import Button from '@/app/components/base/button'
import ActionButton from '@/app/components/base/action-button'
2024-10-12 12:35:56 +08:00
import Drawer from '@/app/components/base/drawer'
2024-10-16 15:37:32 +08:00
// import Loading from '@/app/components/base/loading'
import I18n from '@/context/i18n'
2024-10-12 12:35:56 +08:00
import cn from '@/utils/classnames'
type Props = {
2024-10-16 17:30:51 +08:00
pluginDetail: PluginDetail | undefined
2024-10-16 15:37:32 +08:00
onHide: () => void
2024-10-12 12:35:56 +08:00
}
const PluginDetailPanel: FC<Props> = ({
2024-10-16 15:37:32 +08:00
pluginDetail,
onHide,
2024-10-12 12:35:56 +08:00
}) => {
2024-10-12 14:39:53 +08:00
const { t } = useTranslation()
2024-10-16 15:37:32 +08:00
const { locale } = useContext(I18n)
2024-10-12 12:35:56 +08:00
2024-10-12 14:39:53 +08:00
const hasNewVersion = useMemo(() => {
if (!pluginDetail)
return false
2024-10-16 17:30:51 +08:00
return false // TODO
// return pluginDetail.latest_version !== pluginDetail.version
2024-10-12 14:39:53 +08:00
}, [pluginDetail])
const handleUpdate = () => {}
2024-10-16 15:37:32 +08:00
if (!pluginDetail)
2024-10-12 12:35:56 +08:00
return null
return (
<Drawer
isOpen={!!pluginDetail}
clickOutsideNotOpen={false}
2024-10-16 15:37:32 +08:00
onClose={onHide}
2024-10-12 12:35:56 +08:00
footer={null}
mask={false}
positionCenter={false}
2024-10-12 16:29:46 +08:00
panelClassname={cn('justify-start mt-[64px] mr-2 mb-2 !w-[420px] !max-w-[420px] !p-0 !bg-components-panel-bg rounded-2xl border-[0.5px] border-components-panel-border shadow-xl')}
2024-10-12 12:35:56 +08:00
>
2024-10-16 15:37:32 +08:00
{/* {loading && <Loading type='area' />} */}
{pluginDetail && (
2024-10-12 16:29:46 +08:00
<>
2024-10-12 14:39:53 +08:00
<div className={cn('shrink-0 p-4 pb-3 border-b border-divider-subtle bg-components-panel-bg')}>
2024-10-12 12:35:56 +08:00
<div className="flex">
2024-10-16 17:30:51 +08:00
<Icon src={pluginDetail.declaration.icon} />
2024-10-12 12:35:56 +08:00
<div className="ml-3 w-0 grow">
<div className="flex items-center h-5">
2024-10-16 17:30:51 +08:00
<Title title={pluginDetail.declaration.label[locale]} />
2024-10-17 13:44:56 +08:00
{pluginDetail.declaration.verified && <RiVerifiedBadgeLine className="shrink-0 ml-0.5 w-4 h-4 text-text-accent" />}
2024-10-12 14:39:53 +08:00
<Badge
className='mx-1'
text={pluginDetail.version}
hasRedCornerMark={hasNewVersion}
/>
{hasNewVersion && (
<Button variant='secondary-accent' size='small' className='!h-5' onClick={handleUpdate}>{t('plugin.detailPanel.operation.update')}</Button>
)}
2024-10-12 12:35:56 +08:00
</div>
<div className='mb-1 flex justify-between items-center h-4'>
<div className='flex items-center'>
2024-10-16 17:30:51 +08:00
<OrgInfo
className="mt-0.5"
packageNameClassName='w-auto'
orgName={pluginDetail.declaration.author}
packageName={pluginDetail.declaration.name}
/>
<div className='ml-1 mr-0.5 text-text-quaternary system-xs-regular'>·</div>
{pluginDetail.source === PluginSource.marketplace && (
<Tooltip popupContent={t('plugin.detailPanel.categoryTip.marketplace')} >
<BoxSparkleFill className='w-3.5 h-3.5 text-text-tertiary hover:text-text-accent' />
</Tooltip>
)}
{pluginDetail.source === PluginSource.github && (
<Tooltip popupContent={t('plugin.detailPanel.categoryTip.github')} >
<Github className='w-3.5 h-3.5 text-text-secondary hover:text-text-primary' />
</Tooltip>
)}
{pluginDetail.source === PluginSource.local && (
<Tooltip popupContent={t('plugin.detailPanel.categoryTip.local')} >
<RiHardDrive3Line className='w-3.5 h-3.5 text-text-tertiary' />
</Tooltip>
)}
{pluginDetail.source === PluginSource.debugging && (
<Tooltip popupContent={t('plugin.detailPanel.categoryTip.debugging')} >
<RiBugLine className='w-3.5 h-3.5 text-text-tertiary hover:text-text-warning' />
</Tooltip>
)}
2024-10-12 12:35:56 +08:00
</div>
</div>
</div>
2024-10-12 14:39:53 +08:00
<div className='flex gap-1'>
<OperationDropdown />
2024-10-16 15:37:32 +08:00
<ActionButton onClick={onHide}>
2024-10-12 14:39:53 +08:00
<RiCloseLine className='w-4 h-4' />
</ActionButton>
</div>
2024-10-12 12:35:56 +08:00
</div>
2024-10-17 08:49:29 +08:00
<Description className='mt-3' text={pluginDetail.declaration.description[locale]} descriptionLineRows={2}></Description>
2024-10-12 12:35:56 +08:00
</div>
2024-10-12 16:29:46 +08:00
<div className='grow overflow-y-auto'>
2024-10-13 10:49:55 +08:00
<ActionList />
<EndpointList />
<ModelList />
2024-10-12 16:29:46 +08:00
</div>
</>
2024-10-12 12:35:56 +08:00
)}
</Drawer>
)
}
export default PluginDetailPanel