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('/')
}
export async function fetchPluginDetail(id: string) {
export async function fetchPluginDetail(org: string, name: string) {
// Fetch plugin detail TODO
return { id }
return { org, name }
}

View File

@ -185,7 +185,7 @@ const ModelProviderPage = () => {
{!collapse && (
<div className='grid grid-cols-2 gap-2'>
{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>
)}

View File

@ -1,7 +1,6 @@
import { PluginType } from '../types'
export const toolNotion = {
id: 'tool-notion',
type: PluginType.tool,
org: 'Notion',
name: 'notion page search',
@ -19,7 +18,6 @@ export const toolNotion = {
}
export const extensionDallE = {
id: 'extension-dalle',
type: PluginType.extension,
org: 'OpenAI',
name: 'DALL-E',
@ -38,7 +36,6 @@ export const extensionDallE = {
}
export const modelGPT4 = {
id: 'model-gpt4',
type: PluginType.model,
org: 'OpenAI',
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 { RiCloseLine, RiVerifiedBadgeLine } from '@remixicon/react'
import type { Plugin } from '../types'
import { PluginType } from '../types'
import Badge from '../../base/badge'
import Description from '../card/base/description'
import Icon from '../card/base/card-icon'
import Title from '../card/base/title'
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 { fetchPluginDetail } from '@/app/(commonLayout)/plugins/test/card/actions'
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 {
// extensionDallE,
// modelGPT4,
toolNotion,
modelGPT4,
// toolNotion,
} from '@/app/components/plugins/card/card-mock'
type Props = {
@ -33,7 +37,8 @@ const PluginDetailPanel: FC<Props> = ({
}) => {
const { t } = useTranslation()
const searchParams = useSearchParams()
const pluginID = searchParams.get('pluginID')
const org = searchParams.get('org')
const name = searchParams.get('name')
const router = useRouter()
const pathname = usePathname()
const [loading, setLoading] = useState(true)
@ -45,12 +50,14 @@ const PluginDetailPanel: FC<Props> = ({
return pluginDetail.latest_version !== pluginDetail.version
}, [pluginDetail])
const getPluginDetail = async (pluginID: string) => {
const getPluginDetail = async (org: string, name: string) => {
console.log('organization: ', org)
console.log('plugin name: ', name)
setLoading(true)
const detail = await fetchPluginDetail(pluginID)
const detail = await fetchPluginDetail(org, name)
setPluginDetail({
...detail,
...toolNotion,
...modelGPT4,
} as any)
setLoading(false)
}
@ -63,11 +70,11 @@ const PluginDetailPanel: FC<Props> = ({
const handleUpdate = () => {}
useEffect(() => {
if (pluginID)
getPluginDetail(pluginID)
}, [pluginID])
if (org && name)
getPluginDetail(org, name)
}, [org, name])
if (!pluginID)
if (!org || !name)
return null
return (
@ -78,11 +85,11 @@ const PluginDetailPanel: FC<Props> = ({
footer={null}
mask={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 && 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="flex">
<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='flex items-center'>
<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' />
</div>
</div>
@ -116,7 +123,18 @@ const PluginDetailPanel: FC<Props> = ({
</div>
<Description className='mt-3' text={pluginDetail.brief[locale]} descriptionLineRows={2}></Description>
</div>
<div className='grow overflow-y-auto'>
{pluginDetail.type === PluginType.model && (
<ModelList />
)}
{pluginDetail.type !== PluginType.model && (
<>
<EndpointList />
<ActionList />
</>
)}
</div>
</>
)}
</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
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
installed?: boolean
}
const ProviderCard: FC<Props> = ({
className,
locale,
payload,
installed = true,
}) => {
const { org, label } = payload
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)}>
<Link href={`/plugins/test/card?pluginID=${payload.id}`}>
<Link href={`/plugins/test/card?org=${payload.org}&name=${payload.name}`}>
{/* Header */}
<div className="flex">
<Icon src={payload.icon} />
@ -51,6 +53,7 @@ const ProviderCard: FC<Props> = ({
<Badge key={tag} text={tag} />
))}
</div>
{!installed && (
<div
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%)' }}
@ -69,6 +72,7 @@ const ProviderCard: FC<Props> = ({
<RiArrowRightUpLine className='w-4 h-4' />
</Button>
</div>
)}
</Link>
</div>
)

View File

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

View File

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

View File

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