From 3cd17903c5249957a11628d7c0a0445bd2982c22 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Wed, 12 Feb 2025 15:48:24 +0800 Subject: [PATCH] fix: refresh after install plugin --- .../hooks/use-refresh-plugin-list.tsx | 11 ++++++++--- .../install-from-github/index.tsx | 5 +++-- .../install-from-github/steps/loaded.tsx | 6 +++--- .../ready-to-install.tsx | 5 +++-- .../steps/install.tsx | 6 +++--- .../install-from-marketplace/index.tsx | 5 +++-- .../install-from-marketplace/steps/install.tsx | 6 +++--- .../plugin-detail-panel/detail-header.tsx | 2 ++ .../components/plugins/plugin-item/action.tsx | 4 ++++ .../components/plugins/plugin-item/index.tsx | 18 ++++-------------- web/app/components/plugins/types.ts | 2 ++ .../update-plugin/from-market-place.tsx | 2 +- web/app/components/tools/provider-list.tsx | 2 +- web/service/use-plugins.ts | 11 +++++++++-- 14 files changed, 49 insertions(+), 36 deletions(-) diff --git a/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx b/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx index acb486c703d724..bb6c1baedb6a5a 100644 --- a/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx +++ b/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx @@ -1,4 +1,5 @@ -import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks' +import { useModelList } from '@/app/components/header/account-setting/model-provider-page/hooks' +import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { useProviderContext } from '@/context/provider-context' import { useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools' @@ -8,7 +9,9 @@ import { PluginType } from '../../types' const useRefreshPluginList = () => { const invalidateInstalledPluginList = useInvalidateInstalledPluginList() - const updateModelProviders = useUpdateModelProviders() + const { mutate: refetchLLMModelList } = useModelList(ModelTypeEnum.textGeneration) + const { mutate: refetchEmbeddingModelList } = useModelList(ModelTypeEnum.textEmbedding) + const { mutate: refetchRerankModelList } = useModelList(ModelTypeEnum.rerank) const { refreshModelProviders } = useProviderContext() const invalidateAllToolProviders = useInvalidateAllToolProviders() @@ -31,8 +34,10 @@ const useRefreshPluginList = () => { // model select if (PluginType.model.includes(manifest.category) || refreshAllType) { - updateModelProviders() refreshModelProviders() + refetchLLMModelList() + refetchEmbeddingModelList() + refetchRerankModelList() } // agent select diff --git a/web/app/components/plugins/install-plugin/install-from-github/index.tsx b/web/app/components/plugins/install-plugin/install-from-github/index.tsx index 7e43907564abe8..53466000cdf758 100644 --- a/web/app/components/plugins/install-plugin/install-from-github/index.tsx +++ b/web/app/components/plugins/install-plugin/install-from-github/index.tsx @@ -136,9 +136,10 @@ const InstallFromGitHub: React.FC = ({ updatePayload, on setState(prevState => ({ ...prevState, step: InstallStepFromGitHub.uploadFailed })) }, []) - const handleInstalled = useCallback(() => { + const handleInstalled = useCallback((notRefresh?: boolean) => { setState(prevState => ({ ...prevState, step: InstallStepFromGitHub.installed })) - refreshPluginList(manifest) + if (!notRefresh) + refreshPluginList(manifest) setIsInstalling(false) onSuccess() }, [manifest, onSuccess, refreshPluginList, setIsInstalling]) diff --git a/web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx b/web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx index b1bcf01251e255..6c3fa7a7bc5059 100644 --- a/web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx +++ b/web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx @@ -24,7 +24,7 @@ type LoadedProps = { selectedPackage: string onBack: () => void onStartToInstall?: () => void - onInstalled: () => void + onInstalled: (notRefresh?: boolean) => void onFailed: (message?: string) => void } @@ -55,7 +55,7 @@ const Loaded: React.FC = ({ const [isInstalling, setIsInstalling] = React.useState(false) const { mutateAsync: installPackageFromGitHub } = useInstallPackageFromGitHub() - const { handleRefetch } = usePluginTaskList() + const { handleRefetch } = usePluginTaskList(payload.category) const { check } = checkTaskStatus() useEffect(() => { @@ -127,7 +127,7 @@ const Loaded: React.FC = ({ onFailed(error) return } - onInstalled() + onInstalled(true) } catch (e) { if (typeof e === 'string') { diff --git a/web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx b/web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx index cee7e4767f3146..f85cde1e2a8614 100644 --- a/web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx +++ b/web/app/components/plugins/install-plugin/install-from-local-package/ready-to-install.tsx @@ -32,9 +32,10 @@ const ReadyToInstall: FC = ({ }) => { const { refreshPluginList } = useRefreshPluginList() - const handleInstalled = useCallback(() => { + const handleInstalled = useCallback((notRefresh?: boolean) => { onStepChange(InstallStep.installed) - refreshPluginList(manifest) + if (!notRefresh) + refreshPluginList(manifest) setIsInstalling(false) }, [manifest, onStepChange, refreshPluginList, setIsInstalling]) diff --git a/web/app/components/plugins/install-plugin/install-from-local-package/steps/install.tsx b/web/app/components/plugins/install-plugin/install-from-local-package/steps/install.tsx index 1deb8d8282d159..f0d43e9418eed9 100644 --- a/web/app/components/plugins/install-plugin/install-from-local-package/steps/install.tsx +++ b/web/app/components/plugins/install-plugin/install-from-local-package/steps/install.tsx @@ -20,7 +20,7 @@ type Props = { payload: PluginDeclaration onCancel: () => void onStartToInstall?: () => void - onInstalled: () => void + onInstalled: (notRefresh?: boolean) => void onFailed: (message?: string) => void } @@ -62,7 +62,7 @@ const Installed: FC = ({ onCancel() } - const { handleRefetch } = usePluginTaskList() + const { handleRefetch } = usePluginTaskList(payload.category) const handleInstall = async () => { if (isInstalling) return setIsInstalling(true) @@ -92,7 +92,7 @@ const Installed: FC = ({ onFailed(error) return } - onInstalled() + onInstalled(true) } catch (e) { if (typeof e === 'string') { diff --git a/web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx b/web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx index a5ce01d041b3ba..149efd4b40c301 100644 --- a/web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx +++ b/web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx @@ -54,9 +54,10 @@ const InstallFromMarketplace: React.FC = ({ return t(`${i18nPrefix}.installPlugin`) }, [isBundle, step, t]) - const handleInstalled = useCallback(() => { + const handleInstalled = useCallback((notRefresh?: boolean) => { setStep(InstallStep.installed) - refreshPluginList(manifest) + if (!notRefresh) + refreshPluginList(manifest) setIsInstalling(false) }, [manifest, refreshPluginList, setIsInstalling]) diff --git a/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx index 0779f27ef670ba..f70cdc234d0f36 100644 --- a/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx +++ b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx @@ -21,7 +21,7 @@ type Props = { payload: PluginManifestInMarket | Plugin onCancel: () => void onStartToInstall?: () => void - onInstalled: () => void + onInstalled: (notRefresh?: boolean) => void onFailed: (message?: string) => void } @@ -51,7 +51,7 @@ const Installed: FC = ({ check, stop, } = checkTaskStatus() - const { handleRefetch } = usePluginTaskList() + const { handleRefetch } = usePluginTaskList(payload.category) useEffect(() => { if (hasInstalled && uniqueIdentifier === installedInfoPayload.uniqueIdentifier) @@ -106,7 +106,7 @@ const Installed: FC = ({ onFailed(error) return } - onInstalled() + onInstalled(true) } catch (e) { if (typeof e === 'string') { diff --git a/web/app/components/plugins/plugin-detail-panel/detail-header.tsx b/web/app/components/plugins/plugin-detail-panel/detail-header.tsx index 0eded48378ada4..6edb68238f4f96 100644 --- a/web/app/components/plugins/plugin-detail-panel/detail-header.tsx +++ b/web/app/components/plugins/plugin-detail-panel/detail-header.tsx @@ -113,6 +113,7 @@ const DetailHeader = ({ }, payload: { type: PluginSource.github, + category: detail.declaration.category, github: { originalPackageInfo: { id: detail.plugin_unique_identifier, @@ -287,6 +288,7 @@ const DetailHeader = ({ isShowUpdateModal && ( = ({ installationId, pluginUniqueIdentifier, pluginName, + category, isShowFetchNewVersion, isShowInfo, isShowDelete, @@ -67,6 +70,7 @@ const Action: FC = ({ }, payload: { type: PluginSource.github, + category, github: { originalPackageInfo: { id: pluginUniqueIdentifier, diff --git a/web/app/components/plugins/plugin-item/index.tsx b/web/app/components/plugins/plugin-item/index.tsx index 0c74f90a1b4558..d06f4061361626 100644 --- a/web/app/components/plugins/plugin-item/index.tsx +++ b/web/app/components/plugins/plugin-item/index.tsx @@ -20,11 +20,9 @@ import Title from '../card/base/title' import Action from './action' import cn from '@/utils/classnames' import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config' -import { useInvalidateInstalledPluginList } from '@/service/use-plugins' -import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools' import { useSingleCategories } from '../hooks' -import { useProviderContext } from '@/context/provider-context' import { useRenderI18nObject } from '@/hooks/use-i18n' +import useRefreshPluginList from '@/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list' type Props = { className?: string @@ -39,10 +37,7 @@ const PluginItem: FC = ({ const { categoriesMap } = useSingleCategories() const currentPluginID = usePluginPageContext(v => v.currentPluginID) const setCurrentPluginID = usePluginPageContext(v => v.setCurrentPluginID) - const invalidateInstalledPluginList = useInvalidateInstalledPluginList() - const invalidateAllToolProviders = useInvalidateAllToolProviders() - const invalidateAllBuiltinTools = useInvalidateAllBuiltInTools() - const { refreshModelProviders } = useProviderContext() + const { refreshPluginList } = useRefreshPluginList() const { source, @@ -60,13 +55,7 @@ const PluginItem: FC = ({ }, [source, author]) const handleDelete = () => { - invalidateInstalledPluginList() - if (PluginType.model.includes(category)) - refreshModelProviders() - if (PluginType.tool.includes(category)) { - invalidateAllToolProviders() - invalidateAllBuiltinTools() - } + refreshPluginList({ category } as any) } const getValueFromI18nObject = useRenderI18nObject() const title = getValueFromI18nObject(label) @@ -116,6 +105,7 @@ const PluginItem: FC = ({ isShowDelete meta={meta} onDelete={handleDelete} + category={category} /> diff --git a/web/app/components/plugins/types.ts b/web/app/components/plugins/types.ts index 9a94f7740c6660..8fefa5cdfdc073 100644 --- a/web/app/components/plugins/types.ts +++ b/web/app/components/plugins/types.ts @@ -151,6 +151,7 @@ export type Permissions = { } export type UpdateFromMarketPlacePayload = { + category: PluginType originalPackageInfo: { id: string payload: PluginDeclaration @@ -173,6 +174,7 @@ export type UpdateFromGitHubPayload = { export type UpdatePluginPayload = { type: PluginSource + category: PluginType marketPlace?: UpdateFromMarketPlacePayload github?: UpdateFromGitHubPayload } diff --git a/web/app/components/plugins/update-plugin/from-market-place.tsx b/web/app/components/plugins/update-plugin/from-market-place.tsx index 6177ddce1ab135..916f61f4789581 100644 --- a/web/app/components/plugins/update-plugin/from-market-place.tsx +++ b/web/app/components/plugins/update-plugin/from-market-place.tsx @@ -57,7 +57,7 @@ const UpdatePluginModal: FC = ({ } const [uploadStep, setUploadStep] = useState(UploadStep.notStarted) - const { handleRefetch } = usePluginTaskList() + const { handleRefetch } = usePluginTaskList(payload.category) const configBtnText = useMemo(() => { return ({ diff --git a/web/app/components/tools/provider-list.tsx b/web/app/components/tools/provider-list.tsx index ee3690717ae3db..ff21c746685375 100644 --- a/web/app/components/tools/provider-list.tsx +++ b/web/app/components/tools/provider-list.tsx @@ -69,7 +69,7 @@ const ProviderList = () => { className='relative flex flex-col overflow-y-auto bg-background-body grow' >
[]) } const usePluginTaskListKey = [NAME_SPACE, 'pluginTaskList'] -export const usePluginTaskList = () => { +export const usePluginTaskList = (category?: PluginType) => { const { canManagement, } = usePermission() + const { refreshPluginList } = useRefreshPluginList() const { data, isFetched, @@ -383,8 +386,12 @@ export const usePluginTaskList = () => { refetchInterval: (lastQuery) => { const lastData = lastQuery.state.data const taskDone = lastData?.tasks.every(task => task.status === TaskStatus.success || task.status === TaskStatus.failed) - if (taskDone) + const taskAllFailed = lastData?.tasks.every(task => task.status === TaskStatus.failed) + if (taskDone) { + if (lastData?.tasks.length && !taskAllFailed) + refreshPluginList(category ? { category } as any : undefined, !category) return false + } return 5000 },