diff --git a/web/app/components/base/tab-slider/index.tsx b/web/app/components/base/tab-slider/index.tsx index fd6b876d02..56cde52154 100644 --- a/web/app/components/base/tab-slider/index.tsx +++ b/web/app/components/base/tab-slider/index.tsx @@ -40,7 +40,7 @@ const TabSlider: FC = ({ const newIndex = options.findIndex(option => option.value === value) setActiveIndex(newIndex) updateSliderStyle(newIndex) - }, [value, options, pluginList]) + }, [value, options, pluginList?.total]) return (
@@ -69,13 +69,13 @@ const TabSlider: FC = ({ {option.text} {/* if no plugin installed, the badge won't show */} {option.value === 'plugins' - && (pluginList?.plugins.length ?? 0) > 0 + && (pluginList?.total ?? 0) > 0 && - {pluginList?.plugins.length} + {pluginList?.total} }
diff --git a/web/app/components/plugins/plugin-page/plugins-panel.tsx b/web/app/components/plugins/plugin-page/plugins-panel.tsx index 513641f4b9..a5f411c37e 100644 --- a/web/app/components/plugins/plugin-page/plugins-panel.tsx +++ b/web/app/components/plugins/plugin-page/plugins-panel.tsx @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next' import type { FilterState } from './filter-management' import FilterManagement from './filter-management' import List from './list' -import { useInstalledLatestVersion, useInstalledPluginListWithPagination, useInvalidateInstalledPluginList } from '@/service/use-plugins' +import { useInstalledLatestVersion, useInstalledPluginList, useInvalidateInstalledPluginList } from '@/service/use-plugins' import PluginDetailPanel from '@/app/components/plugins/plugin-detail-panel' import { usePluginPageContext } from './context' import { useDebounceFn } from 'ahooks' @@ -17,7 +17,7 @@ const PluginsPanel = () => { const { t } = useTranslation() const filters = usePluginPageContext(v => v.filters) as FilterState const setFilters = usePluginPageContext(v => v.setFilters) - const { data: pluginList, isLoading: isPluginListLoading, isFetching, isLastPage, loadNextPage } = useInstalledPluginListWithPagination() + const { data: pluginList, isLoading: isPluginListLoading, isFetching, isLastPage, loadNextPage } = useInstalledPluginList() const { data: installedLatestVersion } = useInstalledLatestVersion( pluginList?.plugins .filter(plugin => plugin.source === PluginSource.marketplace) diff --git a/web/service/use-plugins.ts b/web/service/use-plugins.ts index 871b6f0649..ecfdbcf993 100644 --- a/web/service/use-plugins.ts +++ b/web/service/use-plugins.ts @@ -10,7 +10,6 @@ import type { GitHubItemAndMarketPlaceDependency, InstallPackageResponse, InstalledLatestVersionResponse, - InstalledPluginListResponse, InstalledPluginListWithTotalResponse, PackageDependency, Permissions, @@ -67,16 +66,7 @@ export const useCheckInstalled = ({ }) } -export const useInstalledPluginList = (disable?: boolean) => { - return useQuery({ - queryKey: useInstalledPluginListKey, - queryFn: () => get('/workspaces/current/plugin/list'), - enabled: !disable, - initialData: !disable ? undefined : { plugins: [] }, - }) -} - -export const useInstalledPluginListWithPagination = (pageSize = 100) => { +export const useInstalledPluginList = (disable?: boolean, pageSize = 100) => { const fetchPlugins = async ({ pageParam = 1 }) => { const response = await get( `/workspaces/current/plugin/list?page=${pageParam}&page_size=${pageSize}`, @@ -91,8 +81,10 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => { hasNextPage, isFetchingNextPage, isLoading, + isSuccess, } = useInfiniteQuery({ - queryKey: ['installed-plugins', pageSize], + enabled: !disable, + queryKey: useInstalledPluginListKey, queryFn: fetchPlugins, getNextPageParam: (lastPage, pages) => { const totalItems = lastPage.total @@ -108,10 +100,12 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => { }) const plugins = data?.pages.flatMap(page => page.plugins) ?? [] + const total = data?.pages[0].total ?? 0 return { - data: { + data: disable ? undefined : { plugins, + total, }, isLastPage: !hasNextPage, loadNextPage: () => { @@ -120,6 +114,7 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => { isLoading, isFetching: isFetchingNextPage, error, + isSuccess, } }