mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
endpoints list
This commit is contained in:
parent
cee51ac084
commit
ebebbb684b
|
@ -1,30 +1,35 @@
|
||||||
import React, { useMemo } from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import useSWR from 'swr'
|
||||||
import { useBoolean } from 'ahooks'
|
import { useBoolean } from 'ahooks'
|
||||||
import { RiAddLine } from '@remixicon/react'
|
import { RiAddLine } from '@remixicon/react'
|
||||||
import type { EndpointListItem, PluginEndpointDeclaration } from '../types'
|
|
||||||
import EndpointModal from './endpoint-modal'
|
import EndpointModal from './endpoint-modal'
|
||||||
import EndpointCard from './endpoint-card'
|
import EndpointCard from './endpoint-card'
|
||||||
import { toolCredentialToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
|
import { toolCredentialToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
|
||||||
import ActionButton from '@/app/components/base/action-button'
|
import ActionButton from '@/app/components/base/action-button'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
|
import { usePluginPageContext } from '@/app/components/plugins/plugin-page/context'
|
||||||
import {
|
import {
|
||||||
createEndpoint,
|
createEndpoint,
|
||||||
|
fetchEndpointList,
|
||||||
} from '@/service/plugins'
|
} from '@/service/plugins'
|
||||||
|
|
||||||
type Props = {
|
const EndpointList = () => {
|
||||||
pluginUniqueID: string
|
|
||||||
declaration: PluginEndpointDeclaration
|
|
||||||
list: EndpointListItem[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const EndpointList = ({
|
|
||||||
pluginUniqueID,
|
|
||||||
declaration,
|
|
||||||
list,
|
|
||||||
}: Props) => {
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const pluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
||||||
|
const pluginUniqueID = pluginDetail.plugin_unique_identifier
|
||||||
|
const declaration = pluginDetail.declaration.endpoint
|
||||||
|
const { data } = useSWR(
|
||||||
|
{
|
||||||
|
url: '/workspaces/current/endpoints/list/plugin',
|
||||||
|
params: {
|
||||||
|
plugin_id: pluginDetail.plugin_id,
|
||||||
|
page: 1,
|
||||||
|
limit: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetchEndpointList,
|
||||||
|
)
|
||||||
const [isShowEndpointModal, {
|
const [isShowEndpointModal, {
|
||||||
setTrue: showEndpointModal,
|
setTrue: showEndpointModal,
|
||||||
setFalse: hideEndpointModal,
|
setFalse: hideEndpointModal,
|
||||||
|
@ -50,6 +55,9 @@ const EndpointList = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='px-4 py-2 border-t border-divider-subtle'>
|
<div className='px-4 py-2 border-t border-divider-subtle'>
|
||||||
<div className='mb-1 h-6 flex items-center justify-between text-text-secondary system-sm-semibold-uppercase'>
|
<div className='mb-1 h-6 flex items-center justify-between text-text-secondary system-sm-semibold-uppercase'>
|
||||||
|
@ -65,11 +73,11 @@ const EndpointList = ({
|
||||||
<RiAddLine className='w-4 h-4' />
|
<RiAddLine className='w-4 h-4' />
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
</div>
|
</div>
|
||||||
{list.length === 0 && (
|
{data.endpoints.length === 0 && (
|
||||||
<div className='mb-1 p-3 flex justify-center rounded-[10px] bg-background-section text-text-tertiary system-xs-regular'>{t('plugin.detailPanel.endpointsEmpty')}</div>
|
<div className='mb-1 p-3 flex justify-center rounded-[10px] bg-background-section text-text-tertiary system-xs-regular'>{t('plugin.detailPanel.endpointsEmpty')}</div>
|
||||||
)}
|
)}
|
||||||
<div className='flex flex-col gap-2'>
|
<div className='flex flex-col gap-2'>
|
||||||
{list.map((item, index) => (
|
{data.endpoints.map((item, index) => (
|
||||||
<EndpointCard
|
<EndpointCard
|
||||||
key={index}
|
key={index}
|
||||||
data={item}
|
data={item}
|
||||||
|
|
|
@ -1,27 +1,26 @@
|
||||||
'use client'
|
'use client'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import type { EndpointListItem, InstalledPlugin } from '../types'
|
|
||||||
import DetailHeader from './detail-header'
|
import DetailHeader from './detail-header'
|
||||||
import EndpointList from './endpoint-list'
|
import EndpointList from './endpoint-list'
|
||||||
import ActionList from './action-list'
|
import ActionList from './action-list'
|
||||||
import ModelList from './model-list'
|
import ModelList from './model-list'
|
||||||
import Drawer from '@/app/components/base/drawer'
|
import Drawer from '@/app/components/base/drawer'
|
||||||
|
import { usePluginPageContext } from '@/app/components/plugins/plugin-page/context'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
pluginDetail: InstalledPlugin | undefined
|
|
||||||
endpointList: EndpointListItem[]
|
|
||||||
onHide: () => void
|
|
||||||
onDelete: () => void
|
onDelete: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const PluginDetailPanel: FC<Props> = ({
|
const PluginDetailPanel: FC<Props> = ({
|
||||||
pluginDetail,
|
|
||||||
endpointList = [],
|
|
||||||
onHide,
|
|
||||||
onDelete,
|
onDelete,
|
||||||
}) => {
|
}) => {
|
||||||
|
const pluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
||||||
|
const setCurrentPluginDetail = usePluginPageContext(v => v.setCurrentPluginDetail)
|
||||||
|
|
||||||
|
const handleHide = () => setCurrentPluginDetail(undefined)
|
||||||
|
|
||||||
if (!pluginDetail)
|
if (!pluginDetail)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ const PluginDetailPanel: FC<Props> = ({
|
||||||
<Drawer
|
<Drawer
|
||||||
isOpen={!!pluginDetail}
|
isOpen={!!pluginDetail}
|
||||||
clickOutsideNotOpen={false}
|
clickOutsideNotOpen={false}
|
||||||
onClose={onHide}
|
onClose={handleHide}
|
||||||
footer={null}
|
footer={null}
|
||||||
mask={false}
|
mask={false}
|
||||||
positionCenter={false}
|
positionCenter={false}
|
||||||
|
@ -39,17 +38,11 @@ const PluginDetailPanel: FC<Props> = ({
|
||||||
<>
|
<>
|
||||||
<DetailHeader
|
<DetailHeader
|
||||||
detail={pluginDetail}
|
detail={pluginDetail}
|
||||||
onHide={onHide}
|
onHide={handleHide}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
/>
|
/>
|
||||||
<div className='grow overflow-y-auto'>
|
<div className='grow overflow-y-auto'>
|
||||||
{!!pluginDetail.declaration.endpoint && (
|
{!!pluginDetail.declaration.endpoint && <EndpointList />}
|
||||||
<EndpointList
|
|
||||||
pluginUniqueID={pluginDetail.plugin_unique_identifier}
|
|
||||||
list={endpointList}
|
|
||||||
declaration={pluginDetail.declaration.endpoint}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{!!pluginDetail.declaration.tool && <ActionList />}
|
{!!pluginDetail.declaration.tool && <ActionList />}
|
||||||
{!!pluginDetail.declaration.model && <ModelList />}
|
{!!pluginDetail.declaration.model && <ModelList />}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
'use client'
|
'use client'
|
||||||
import { useMemo, useState } from 'react'
|
import { useMemo } from 'react'
|
||||||
import type { EndpointListItem, InstalledPlugin } from '../types'
|
import type { InstalledPlugin } from '../types'
|
||||||
import type { FilterState } from './filter-management'
|
import type { FilterState } from './filter-management'
|
||||||
import FilterManagement from './filter-management'
|
import FilterManagement from './filter-management'
|
||||||
import List from './list'
|
import List from './list'
|
||||||
import PluginDetailPanel from '@/app/components/plugins/plugin-detail-panel'
|
import PluginDetailPanel from '@/app/components/plugins/plugin-detail-panel'
|
||||||
import { toolNotionEndpoints } from '@/app/components/plugins/plugin-detail-panel/mock'
|
|
||||||
import { usePluginPageContext } from './context'
|
import { usePluginPageContext } from './context'
|
||||||
import { useDebounceFn } from 'ahooks'
|
import { useDebounceFn } from 'ahooks'
|
||||||
|
|
||||||
|
@ -13,8 +12,6 @@ const PluginsPanel = () => {
|
||||||
const [filters, setFilters] = usePluginPageContext(v => [v.filters, v.setFilters])
|
const [filters, setFilters] = usePluginPageContext(v => [v.filters, v.setFilters])
|
||||||
const pluginList = usePluginPageContext(v => v.installedPluginList) as InstalledPlugin[]
|
const pluginList = usePluginPageContext(v => v.installedPluginList) as InstalledPlugin[]
|
||||||
const mutateInstalledPluginList = usePluginPageContext(v => v.mutateInstalledPluginList)
|
const mutateInstalledPluginList = usePluginPageContext(v => v.mutateInstalledPluginList)
|
||||||
const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
|
||||||
const setCurrentPluginDetail = usePluginPageContext(v => v.setCurrentPluginDetail)
|
|
||||||
|
|
||||||
const { run: handleFilterChange } = useDebounceFn((filters: FilterState) => {
|
const { run: handleFilterChange } = useDebounceFn((filters: FilterState) => {
|
||||||
setFilters(filters)
|
setFilters(filters)
|
||||||
|
@ -32,7 +29,6 @@ const PluginsPanel = () => {
|
||||||
return filteredList
|
return filteredList
|
||||||
}, [pluginList, filters])
|
}, [pluginList, filters])
|
||||||
|
|
||||||
const [currentPluginEndpoints, setCurrentEndpoints] = useState<EndpointListItem[]>(toolNotionEndpoints as any)
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='flex flex-col pt-1 pb-3 px-12 justify-center items-start gap-3 self-stretch'>
|
<div className='flex flex-col pt-1 pb-3 px-12 justify-center items-start gap-3 self-stretch'>
|
||||||
|
@ -46,17 +42,7 @@ const PluginsPanel = () => {
|
||||||
<List pluginList={filteredList} />
|
<List pluginList={filteredList} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<PluginDetailPanel
|
<PluginDetailPanel onDelete={() => mutateInstalledPluginList()}/>
|
||||||
pluginDetail={currentPluginDetail}
|
|
||||||
endpointList={currentPluginEndpoints}
|
|
||||||
onHide={() => {
|
|
||||||
setCurrentPluginDetail(undefined)
|
|
||||||
}}
|
|
||||||
onDelete={() => {
|
|
||||||
setCurrentPluginDetail(undefined)
|
|
||||||
mutateInstalledPluginList()
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user