dify/web/app/components/integrations/section-renderer.tsx
Wu Tianwei 33edf97f81
feat: RBAC (#37107)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: fatelei <fatelei@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: 盐粒 Yanli <yanli@dify.ai>
Co-authored-by: Charles Yao <chongbinyao33@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: yunlu.wen <yunlu.wen@dify.ai>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
Co-authored-by: Jingyi <jingyi.qi@dify.ai>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
Co-authored-by: gigglewang <gigglewang@dify.ai>
Co-authored-by: chariri <w@chariri.moe>
Co-authored-by: Evan <2869018789@qq.com>
Co-authored-by: zyssyz123 <916125788@qq.com>
2026-06-18 16:35:29 +00:00

125 lines
4.2 KiB
TypeScript

'use client'
import type { ReactNode } from 'react'
import type { IntegrationSection } from './routes'
import { ApiBasedExtensionPage } from '@/app/components/header/account-setting/api-based-extension-page'
import DataSourcePage from '@/app/components/header/account-setting/data-source-page-new'
import ModelProviderPage from '@/app/components/header/account-setting/model-provider-page'
import { PluginCategoryEnum } from '@/app/components/plugins/types'
import { toolsContentFrameClassNames, toolsContentInsetClassNames } from '@/app/components/tools/content-inset'
import { IntegrationPageHeader } from './page-header'
import PluginCategoryPage from './plugin-category-page'
import { IntegrationSectionLayout } from './section-layout'
import ToolProviderList from './tool-provider-list'
type IntegrationSectionRendererProps = {
canInstallPlugin?: boolean
canManagePlugin?: boolean
canUpdatePlugin?: boolean
canViewInstalledPlugins?: boolean
description?: ReactNode
onProviderSearchTextChange: (value: string) => void
onSwitchToMarketplace?: () => void
pluginCategoryToolbarAction?: ReactNode
providerSearchText: string
scrollAreaLabel?: string
section: IntegrationSection
title?: ReactNode
}
const IntegrationSectionRenderer = ({
canInstallPlugin = true,
canManagePlugin = true,
canUpdatePlugin = true,
canViewInstalledPlugins = true,
description,
onProviderSearchTextChange,
onSwitchToMarketplace,
pluginCategoryToolbarAction,
providerSearchText,
scrollAreaLabel,
section,
title,
}: IntegrationSectionRendererProps) => {
const compactFrameClassName = `${toolsContentFrameClassNames.compact} ${toolsContentInsetClassNames.compact}`
const renderHeader = (toolbar?: ReactNode) => (
<IntegrationPageHeader
align="start"
title={title}
description={description}
descriptionClassName="system-xs-regular"
frameClassName={compactFrameClassName}
toolbar={toolbar}
/>
)
const renderScrollBody = (body: ReactNode) => (
<IntegrationSectionLayout
label={scrollAreaLabel}
bodyClassName={`${compactFrameClassName} pt-1`}
>
{body}
</IntegrationSectionLayout>
)
const renderScrollableLayout = ({ body, toolbar }: { body: ReactNode, toolbar: ReactNode }) => (
<>
{renderHeader(toolbar)}
{renderScrollBody(body)}
</>
)
const renderDirectLayout = ({ body, toolbar }: { body: ReactNode, toolbar: ReactNode }) => (
<>
{renderHeader(toolbar)}
{body}
</>
)
const renderPluginCategoryPage = (category: PluginCategoryEnum) => (
<PluginCategoryPage
canInstall={canInstallPlugin}
canManagePlugin={canManagePlugin}
canUpdatePlugin={canUpdatePlugin}
canViewInstalledPlugins={canViewInstalledPlugins}
category={category}
layout={renderDirectLayout}
onSwitchToMarketplace={onSwitchToMarketplace}
toolbarAction={pluginCategoryToolbarAction}
/>
)
switch (section) {
case 'provider':
return (
<ModelProviderPage
hideSystemModelSelectorProviderSettingsFooter
layout={renderScrollableLayout}
searchText={providerSearchText}
stickyToolbar
onSearchTextChange={onProviderSearchTextChange}
/>
)
case 'builtin':
return renderPluginCategoryPage(PluginCategoryEnum.tool)
case 'mcp':
return <ToolProviderList category="mcp" contentInset="compact" layout={renderDirectLayout} />
case 'custom-tool':
return <ToolProviderList category="api" contentInset="compact" layout={renderDirectLayout} />
case 'workflow-tool':
return <ToolProviderList category="workflow" contentInset="compact" layout={renderDirectLayout} />
case 'data-source':
return (
<DataSourcePage stickyToolbar layout={renderScrollableLayout} />
)
case 'custom-endpoint':
return <ApiBasedExtensionPage layout={renderScrollableLayout} />
case 'trigger':
return renderPluginCategoryPage(PluginCategoryEnum.trigger)
case 'agent-strategy':
return renderPluginCategoryPage(PluginCategoryEnum.agent)
case 'extension':
return renderPluginCategoryPage(PluginCategoryEnum.extension)
default:
return null
}
}
export default IntegrationSectionRenderer