From 4f54ac6ed69929697d2233ed3a06883907a8c1fc Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Mon, 25 Nov 2024 12:03:49 +0800 Subject: [PATCH] fix: marketplace collection condition --- .../plugins/marketplace/context.tsx | 4 ++++ .../components/plugins/marketplace/types.ts | 1 + .../components/plugins/marketplace/utils.ts | 19 ++++++++++++++++++- web/app/components/plugins/utils.ts | 3 +-- web/app/components/tools/marketplace/hooks.ts | 6 +++++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/web/app/components/plugins/marketplace/context.tsx b/web/app/components/plugins/marketplace/context.tsx index 31fe2ced5e..4b692cac28 100644 --- a/web/app/components/plugins/marketplace/context.tsx +++ b/web/app/components/plugins/marketplace/context.tsx @@ -29,6 +29,7 @@ import { useMarketplaceCollectionsAndPlugins, useMarketplacePlugins, } from './hooks' +import { getMarketplaceListCondition } from './utils' export type MarketplaceContextValue = { intersected: boolean @@ -134,6 +135,7 @@ export const MarketplaceContextProvider = ({ if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) { queryMarketplaceCollectionsAndPlugins({ category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current, + condition: getMarketplaceListCondition(activePluginTypeRef.current), }) resetPlugins() @@ -156,6 +158,7 @@ export const MarketplaceContextProvider = ({ if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) { queryMarketplaceCollectionsAndPlugins({ category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current, + condition: getMarketplaceListCondition(activePluginTypeRef.current), }) resetPlugins() @@ -178,6 +181,7 @@ export const MarketplaceContextProvider = ({ if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) { queryMarketplaceCollectionsAndPlugins({ category: type === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : type, + condition: getMarketplaceListCondition(type), }) resetPlugins() diff --git a/web/app/components/plugins/marketplace/types.ts b/web/app/components/plugins/marketplace/types.ts index fbe4595322..58424d6c68 100644 --- a/web/app/components/plugins/marketplace/types.ts +++ b/web/app/components/plugins/marketplace/types.ts @@ -36,6 +36,7 @@ export type PluginsSort = { export type CollectionsAndPluginsSearchParams = { category?: string + condition?: string } export type SearchParams = { diff --git a/web/app/components/plugins/marketplace/utils.ts b/web/app/components/plugins/marketplace/utils.ts index a8e50b5e20..c9f77318f7 100644 --- a/web/app/components/plugins/marketplace/utils.ts +++ b/web/app/components/plugins/marketplace/utils.ts @@ -1,4 +1,5 @@ import type { Plugin } from '@/app/components/plugins/types' +import { PluginType } from '@/app/components/plugins/types' import type { CollectionsAndPluginsSearchParams, MarketplaceCollection, @@ -14,7 +15,10 @@ export const getMarketplaceCollectionsAndPlugins = async (query?: CollectionsAnd let marketplaceCollections = [] as MarketplaceCollection[] let marketplaceCollectionPluginsMap = {} as Record try { - const marketplaceCollectionsData = await globalThis.fetch(`${MARKETPLACE_API_PREFIX}/collections?page=1&page_size=100`, { cache: 'no-store' }) + let marketplaceUrl = `${MARKETPLACE_API_PREFIX}/collections?page=1&page_size=100` + if (query?.condition) + marketplaceUrl += `&condition=${query.condition}` + const marketplaceCollectionsData = await globalThis.fetch(marketplaceUrl, { cache: 'no-store' }) const marketplaceCollectionsDataJson = await marketplaceCollectionsData.json() marketplaceCollections = marketplaceCollectionsDataJson.data.collections await Promise.all(marketplaceCollections.map(async (collection: MarketplaceCollection) => { @@ -83,3 +87,16 @@ export const getMarketplacePlugins = async (query: PluginsSearchParams) => { marketplacePlugins, } } + +export const getMarketplaceListCondition = (pluginType: string) => { + if (pluginType === PluginType.tool) + return 'category=tool' + + if (pluginType === PluginType.model) + return 'category=model' + + if (pluginType === PluginType.extension) + return 'category=endpoint' + + return '' +} diff --git a/web/app/components/plugins/utils.ts b/web/app/components/plugins/utils.ts index a87ee021eb..95f6d716d9 100644 --- a/web/app/components/plugins/utils.ts +++ b/web/app/components/plugins/utils.ts @@ -8,6 +8,5 @@ export const getValidTagKeys = (tags: string[]) => { } export const getValidCategoryKeys = (category?: string) => { - const currentCategory = categoryKeys.find(key => key === category) - return currentCategory ? `${currentCategory}s` : '' + return categoryKeys.find(key => key === category) } diff --git a/web/app/components/tools/marketplace/hooks.ts b/web/app/components/tools/marketplace/hooks.ts index 45cbd8a389..3aec42be75 100644 --- a/web/app/components/tools/marketplace/hooks.ts +++ b/web/app/components/tools/marketplace/hooks.ts @@ -6,6 +6,7 @@ import { useMarketplacePlugins, } from '@/app/components/plugins/marketplace/hooks' import { PluginType } from '@/app/components/plugins/types' +import { getMarketplaceListCondition } from '@/app/components/plugins/marketplace/utils' export const useMarketplace = (searchPluginText: string, filterPluginTags: string[]) => { const { @@ -39,7 +40,10 @@ export const useMarketplace = (searchPluginText: string, filterPluginTags: strin }) } else { - queryMarketplaceCollectionsAndPlugins({ category: PluginType.tool }) + queryMarketplaceCollectionsAndPlugins({ + category: PluginType.tool, + condition: getMarketplaceListCondition(PluginType.tool), + }) resetPlugins() } }, [searchPluginText, filterPluginTags, queryPlugins, queryMarketplaceCollectionsAndPlugins, queryPluginsWithDebounced, resetPlugins])