plugin panel detail

This commit is contained in:
JzoNg 2024-10-12 16:29:46 +08:00
parent 99f5fea001
commit 2fbfc988c4
11 changed files with 116 additions and 39 deletions

View File

@ -8,7 +8,7 @@ export async function handleDelete() {
revalidatePath('/') revalidatePath('/')
} }
export async function fetchPluginDetail(id: string) { export async function fetchPluginDetail(org: string, name: string) {
// Fetch plugin detail TODO // Fetch plugin detail TODO
return { id } return { org, name }
} }

View File

@ -185,7 +185,7 @@ const ModelProviderPage = () => {
{!collapse && ( {!collapse && (
<div className='grid grid-cols-2 gap-2'> <div className='grid grid-cols-2 gap-2'>
{pluginList.map((plugin, index) => ( {pluginList.map((plugin, index) => (
<ProviderCard key={index} locale={locale} payload={plugin as any} /> <ProviderCard key={index} installed={false} locale={locale} payload={plugin as any} />
))} ))}
</div> </div>
)} )}

View File

@ -1,7 +1,6 @@
import { PluginType } from '../types' import { PluginType } from '../types'
export const toolNotion = { export const toolNotion = {
id: 'tool-notion',
type: PluginType.tool, type: PluginType.tool,
org: 'Notion', org: 'Notion',
name: 'notion page search', name: 'notion page search',
@ -19,7 +18,6 @@ export const toolNotion = {
} }
export const extensionDallE = { export const extensionDallE = {
id: 'extension-dalle',
type: PluginType.extension, type: PluginType.extension,
org: 'OpenAI', org: 'OpenAI',
name: 'DALL-E', name: 'DALL-E',
@ -38,7 +36,6 @@ export const extensionDallE = {
} }
export const modelGPT4 = { export const modelGPT4 = {
id: 'model-gpt4',
type: PluginType.model, type: PluginType.model,
org: 'OpenAI', org: 'OpenAI',
name: 'GPT-4', name: 'GPT-4',

View File

@ -0,0 +1,11 @@
import React from 'react'
const ActionList = () => {
return (
<div>
<h1>Action List</h1>
</div>
)
}
export default ActionList

View File

@ -0,0 +1,11 @@
import React from 'react'
const EndpointList = () => {
return (
<div>
<h1>Endpoints</h1>
</div>
)
}
export default EndpointList

View File

@ -5,11 +5,15 @@ import { useTranslation } from 'react-i18next'
import { usePathname, useRouter, useSearchParams } from 'next/navigation' import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { RiCloseLine, RiVerifiedBadgeLine } from '@remixicon/react' import { RiCloseLine, RiVerifiedBadgeLine } from '@remixicon/react'
import type { Plugin } from '../types' import type { Plugin } from '../types'
import { PluginType } from '../types'
import Badge from '../../base/badge' import Badge from '../../base/badge'
import Description from '../card/base/description' import Description from '../card/base/description'
import Icon from '../card/base/card-icon' import Icon from '../card/base/card-icon'
import Title from '../card/base/title' import Title from '../card/base/title'
import OperationDropdown from './operation-dropdown' import OperationDropdown from './operation-dropdown'
import EndpointList from './endpoint-list'
import ActionList from './action-list'
import ModelList from './model-list'
import type { Locale } from '@/i18n' import type { Locale } from '@/i18n'
import { fetchPluginDetail } from '@/app/(commonLayout)/plugins/test/card/actions' import { fetchPluginDetail } from '@/app/(commonLayout)/plugins/test/card/actions'
import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin' import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin'
@ -20,8 +24,8 @@ import Loading from '@/app/components/base/loading'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { import {
// extensionDallE, // extensionDallE,
// modelGPT4, modelGPT4,
toolNotion, // toolNotion,
} from '@/app/components/plugins/card/card-mock' } from '@/app/components/plugins/card/card-mock'
type Props = { type Props = {
@ -33,7 +37,8 @@ const PluginDetailPanel: FC<Props> = ({
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const searchParams = useSearchParams() const searchParams = useSearchParams()
const pluginID = searchParams.get('pluginID') const org = searchParams.get('org')
const name = searchParams.get('name')
const router = useRouter() const router = useRouter()
const pathname = usePathname() const pathname = usePathname()
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
@ -45,12 +50,14 @@ const PluginDetailPanel: FC<Props> = ({
return pluginDetail.latest_version !== pluginDetail.version return pluginDetail.latest_version !== pluginDetail.version
}, [pluginDetail]) }, [pluginDetail])
const getPluginDetail = async (pluginID: string) => { const getPluginDetail = async (org: string, name: string) => {
console.log('organization: ', org)
console.log('plugin name: ', name)
setLoading(true) setLoading(true)
const detail = await fetchPluginDetail(pluginID) const detail = await fetchPluginDetail(org, name)
setPluginDetail({ setPluginDetail({
...detail, ...detail,
...toolNotion, ...modelGPT4,
} as any) } as any)
setLoading(false) setLoading(false)
} }
@ -63,11 +70,11 @@ const PluginDetailPanel: FC<Props> = ({
const handleUpdate = () => {} const handleUpdate = () => {}
useEffect(() => { useEffect(() => {
if (pluginID) if (org && name)
getPluginDetail(pluginID) getPluginDetail(org, name)
}, [pluginID]) }, [org, name])
if (!pluginID) if (!org || !name)
return null return null
return ( return (
@ -78,11 +85,11 @@ const PluginDetailPanel: FC<Props> = ({
footer={null} footer={null}
mask={false} mask={false}
positionCenter={false} positionCenter={false}
panelClassname={cn('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')} 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')}
> >
{loading && <Loading type='area' />} {loading && <Loading type='area' />}
{!loading && pluginDetail && ( {!loading && pluginDetail && (
<div className={cn('w-full flex flex-col')}> <>
<div className={cn('shrink-0 p-4 pb-3 border-b border-divider-subtle bg-components-panel-bg')}> <div className={cn('shrink-0 p-4 pb-3 border-b border-divider-subtle bg-components-panel-bg')}>
<div className="flex"> <div className="flex">
<Icon src={pluginDetail.icon} /> <Icon src={pluginDetail.icon} />
@ -102,7 +109,7 @@ const PluginDetailPanel: FC<Props> = ({
<div className='mb-1 flex justify-between items-center h-4'> <div className='mb-1 flex justify-between items-center h-4'>
<div className='flex items-center'> <div className='flex items-center'>
<div className='text-text-tertiary system-xs-regular'>{pluginDetail.org}</div> <div className='text-text-tertiary system-xs-regular'>{pluginDetail.org}</div>
<div className='mx-2 text-text-quaternary system-xs-regular'>·</div> <div className='ml-1 text-text-quaternary system-xs-regular'>·</div>
<BoxSparkleFill className='w-3.5 h-3.5 text-text-tertiary' /> <BoxSparkleFill className='w-3.5 h-3.5 text-text-tertiary' />
</div> </div>
</div> </div>
@ -116,7 +123,18 @@ const PluginDetailPanel: FC<Props> = ({
</div> </div>
<Description className='mt-3' text={pluginDetail.brief[locale]} descriptionLineRows={2}></Description> <Description className='mt-3' text={pluginDetail.brief[locale]} descriptionLineRows={2}></Description>
</div> </div>
</div> <div className='grow overflow-y-auto'>
{pluginDetail.type === PluginType.model && (
<ModelList />
)}
{pluginDetail.type !== PluginType.model && (
<>
<EndpointList />
<ActionList />
</>
)}
</div>
</>
)} )}
</Drawer> </Drawer>
) )

View File

@ -0,0 +1,31 @@
import React from 'react'
import { useTranslation } from 'react-i18next'
// import ModelIcon from '@/app/components/header/account-setting/model-provider-page/model-icon'
// import ModelName from '@/app/components/header/account-setting/model-provider-page/model-name'
const ModelList = () => {
const { t } = useTranslation()
return (
<div className='px-4 py-2'>
<div className='mb-1 h-6 flex items-center text-text-secondary system-sm-semibold-uppercase'>{t('plugin.detailPanel.modelNum', { num: 3 })}</div>
<div className='h-8 flex items-center'>
{/* <ModelIcon
className='shrink-0 mr-2'
provider={provider}
modelName={model.model}
/>
<ModelName
className='grow text-sm font-normal text-gray-900'
modelItem={model}
showModelType
showMode
showContextSize
>
</ModelName> */}
</div>
</div>
)
}
export default ModelList

View File

@ -16,18 +16,20 @@ type Props = {
className?: string className?: string
locale: Locale // The component is used in both client and server side, so we can't get the locale from both side(getLocaleOnServer and useContext) locale: Locale // The component is used in both client and server side, so we can't get the locale from both side(getLocaleOnServer and useContext)
payload: Plugin payload: Plugin
installed?: boolean
} }
const ProviderCard: FC<Props> = ({ const ProviderCard: FC<Props> = ({
className, className,
locale, locale,
payload, payload,
installed = true,
}) => { }) => {
const { org, label } = payload const { org, label } = payload
return ( return (
<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)}> <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)}>
<Link href={`/plugins/test/card?pluginID=${payload.id}`}> <Link href={`/plugins/test/card?org=${payload.org}&name=${payload.name}`}>
{/* Header */} {/* Header */}
<div className="flex"> <div className="flex">
<Icon src={payload.icon} /> <Icon src={payload.icon} />
@ -51,24 +53,26 @@ const ProviderCard: FC<Props> = ({
<Badge key={tag} text={tag} /> <Badge key={tag} text={tag} />
))} ))}
</div> </div>
<div {!installed && (
className='hidden group-hover:flex items-center gap-2 absolute bottom-0 left-0 right-0 p-4 pt-8' <div
style={{ background: 'linear-gradient(0deg, #F9FAFB 60.27%, rgba(249, 250, 251, 0.00) 100%)' }} className='hidden group-hover:flex items-center gap-2 absolute bottom-0 left-0 right-0 p-4 pt-8'
> style={{ background: 'linear-gradient(0deg, #F9FAFB 60.27%, rgba(249, 250, 251, 0.00) 100%)' }}
<Button
className='flex-grow'
variant='primary'
> >
Install <Button
</Button> className='flex-grow'
<Button variant='primary'
className='flex-grow' >
variant='secondary' Install
> </Button>
Details <Button
<RiArrowRightUpLine className='w-4 h-4' /> className='flex-grow'
</Button> variant='secondary'
</div> >
Details
<RiArrowRightUpLine className='w-4 h-4' />
</Button>
</div>
)}
</Link> </Link>
</div> </div>
) )

View File

@ -8,7 +8,6 @@ export enum PluginType {
} }
export type Plugin = { export type Plugin = {
id: string
'type': PluginType 'type': PluginType
'org': string 'org': string
'name': string 'name': string

View File

@ -3,12 +3,15 @@ const translation = {
endpointsEnabled: '{{num}} sets of endpoints enabled', endpointsEnabled: '{{num}} sets of endpoints enabled',
detailPanel: { detailPanel: {
operation: { operation: {
install: 'Install',
detail: 'Detail',
update: 'Update', update: 'Update',
info: 'Plugin Info', info: 'Plugin Info',
checkUpdate: 'Check Update', checkUpdate: 'Check Update',
viewDetail: 'View Detail', viewDetail: 'View Detail',
remove: 'Remove', remove: 'Remove',
}, },
modelNum: '{{num}} MODELS INCLUDED',
}, },
} }

View File

@ -3,12 +3,15 @@ const translation = {
endpointsEnabled: '{{num}} 组端点已启用', endpointsEnabled: '{{num}} 组端点已启用',
detailPanel: { detailPanel: {
operation: { operation: {
install: '安装',
detail: '详情',
update: '更新', update: '更新',
info: '插件信息', info: '插件信息',
checkUpdate: '检查更新', checkUpdate: '检查更新',
viewDetail: '查看详情', viewDetail: '查看详情',
remove: '移除', remove: '移除',
}, },
modelNum: '{{num}} 模型已包含',
}, },
} }