From 32527b26d576911a1a5570b32829e6ef570c7262 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Mon, 31 Mar 2025 11:13:05 +0800 Subject: [PATCH] fix: model page switch marketplace (#17147) --- .../model-provider-page/index.tsx | 69 +++------------- .../install-from-marketplace.tsx | 81 +++++++++++++++++++ 2 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 web/app/components/header/account-setting/model-provider-page/install-from-marketplace.tsx diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx index 99570f5430..7c4e2eac3c 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.tsx @@ -1,11 +1,8 @@ -import { useCallback, useMemo, useState } from 'react' +import { useMemo } from 'react' import { useTranslation } from 'react-i18next' -import Link from 'next/link' import { useDebounce } from 'ahooks' import { RiAlertFill, - RiArrowDownSLine, - RiArrowRightUpLine, RiBrainLine, } from '@remixicon/react' import SystemModelSelector from './system-model-selector' @@ -13,7 +10,6 @@ import ProviderAddedCard from './provider-added-card' import type { ConfigurationMethodEnum, CustomConfigurationModelFixedFields, - ModelProvider, } from './declarations' import { @@ -22,18 +18,12 @@ import { } from './declarations' import { useDefaultModel, - useMarketplaceAllPlugins, useModelModalHandler, } from './hooks' -import Divider from '@/app/components/base/divider' -import Loading from '@/app/components/base/loading' -import ProviderCard from '@/app/components/plugins/provider-card' -import List from '@/app/components/plugins/marketplace/list' +import InstallFromMarketplace from './install-from-marketplace' import { useProviderContext } from '@/context/provider-context' -import type { Plugin } from '@/app/components/plugins/types' -import { MARKETPLACE_URL_PREFIX } from '@/config' import cn from '@/utils/classnames' -import { getLocaleOnClient } from '@/i18n' +import { useSelector as useAppContextSelector } from '@/context/app-context' type Props = { searchText: string @@ -50,6 +40,7 @@ const ModelProviderPage = ({ searchText }: Props) => { const { data: speech2textDefaultModel } = useDefaultModel(ModelTypeEnum.speech2text) const { data: ttsDefaultModel } = useDefaultModel(ModelTypeEnum.tts) const { modelProviders: providers } = useProviderContext() + const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) const defaultModelNotConfigured = !textGenerationDefaultModel && !embeddingsDefaultModel && !speech2textDefaultModel && !rerankDefaultModel && !ttsDefaultModel const [configuredProviders, notConfiguredProviders] = useMemo(() => { const configuredProviders: ModelProvider[] = [] @@ -94,19 +85,6 @@ const ModelProviderPage = ({ searchText }: Props) => { }, [configuredProviders, debouncedSearchText, notConfiguredProviders]) const handleOpenModal = useModelModalHandler() - const [collapse, setCollapse] = useState(false) - const locale = getLocaleOnClient() - const { - plugins: allPlugins, - isLoading: isAllPluginsLoading, - } = useMarketplaceAllPlugins(providers, searchText) - - const cardRender = useCallback((plugin: Plugin) => { - if (plugin.type === 'bundle') - return null - - return - }, []) return (
@@ -168,37 +146,14 @@ const ModelProviderPage = ({ searchText }: Props) => {
)} -
- -
-
setCollapse(!collapse)}> - - {t('common.modelProvider.installProvider')} -
-
- {t('common.modelProvider.discoverMore')} - - {t('plugin.marketplace.difyMarketplace')} - - -
-
- {!collapse && isAllPluginsLoading && } - { - !isAllPluginsLoading && !collapse && ( - - ) - } -
+ { + enable_marketplace && ( + + ) + } ) } diff --git a/web/app/components/header/account-setting/model-provider-page/install-from-marketplace.tsx b/web/app/components/header/account-setting/model-provider-page/install-from-marketplace.tsx new file mode 100644 index 0000000000..38f35d6fb4 --- /dev/null +++ b/web/app/components/header/account-setting/model-provider-page/install-from-marketplace.tsx @@ -0,0 +1,81 @@ +import { useCallback, useState } from 'react' +import { useTranslation } from 'react-i18next' +import Link from 'next/link' +import { + RiArrowDownSLine, + RiArrowRightUpLine, +} from '@remixicon/react' +import type { + ModelProvider, +} from './declarations' +import { + useMarketplaceAllPlugins, +} from './hooks' +import Divider from '@/app/components/base/divider' +import Loading from '@/app/components/base/loading' +import ProviderCard from '@/app/components/plugins/provider-card' +import List from '@/app/components/plugins/marketplace/list' +import type { Plugin } from '@/app/components/plugins/types' +import { MARKETPLACE_URL_PREFIX } from '@/config' +import cn from '@/utils/classnames' +import { getLocaleOnClient } from '@/i18n' + +type InstallFromMarketplaceProps = { + providers: ModelProvider[] + searchText: string +} +const InstallFromMarketplace = ({ + providers, + searchText, +}: InstallFromMarketplaceProps) => { + const { t } = useTranslation() + const [collapse, setCollapse] = useState(false) + const locale = getLocaleOnClient() + const { + plugins: allPlugins, + isLoading: isAllPluginsLoading, + } = useMarketplaceAllPlugins(providers, searchText) + + const cardRender = useCallback((plugin: Plugin) => { + if (plugin.type === 'bundle') + return null + + return + }, []) + + return ( +
+ +
+
setCollapse(!collapse)}> + + {t('common.modelProvider.installProvider')} +
+
+ {t('common.modelProvider.discoverMore')} + + {t('plugin.marketplace.difyMarketplace')} + + +
+
+ {!collapse && isAllPluginsLoading && } + { + !isAllPluginsLoading && !collapse && ( + + ) + } +
+ ) +} + +export default InstallFromMarketplace