fix: marketplace collection condition

pull/12372/head
StyleZhang 2 years ago
parent 3263a6a5f5
commit 4f54ac6ed6

@ -29,6 +29,7 @@ import {
useMarketplaceCollectionsAndPlugins, useMarketplaceCollectionsAndPlugins,
useMarketplacePlugins, useMarketplacePlugins,
} from './hooks' } from './hooks'
import { getMarketplaceListCondition } from './utils'
export type MarketplaceContextValue = { export type MarketplaceContextValue = {
intersected: boolean intersected: boolean
@ -134,6 +135,7 @@ export const MarketplaceContextProvider = ({
if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) { if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) {
queryMarketplaceCollectionsAndPlugins({ queryMarketplaceCollectionsAndPlugins({
category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current, category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current,
condition: getMarketplaceListCondition(activePluginTypeRef.current),
}) })
resetPlugins() resetPlugins()
@ -156,6 +158,7 @@ export const MarketplaceContextProvider = ({
if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) { if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) {
queryMarketplaceCollectionsAndPlugins({ queryMarketplaceCollectionsAndPlugins({
category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current, category: activePluginTypeRef.current === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : activePluginTypeRef.current,
condition: getMarketplaceListCondition(activePluginTypeRef.current),
}) })
resetPlugins() resetPlugins()
@ -178,6 +181,7 @@ export const MarketplaceContextProvider = ({
if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) { if (!searchPluginTextRef.current && !filterPluginTagsRef.current.length) {
queryMarketplaceCollectionsAndPlugins({ queryMarketplaceCollectionsAndPlugins({
category: type === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : type, category: type === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : type,
condition: getMarketplaceListCondition(type),
}) })
resetPlugins() resetPlugins()

@ -36,6 +36,7 @@ export type PluginsSort = {
export type CollectionsAndPluginsSearchParams = { export type CollectionsAndPluginsSearchParams = {
category?: string category?: string
condition?: string
} }
export type SearchParams = { export type SearchParams = {

@ -1,4 +1,5 @@
import type { Plugin } from '@/app/components/plugins/types' import type { Plugin } from '@/app/components/plugins/types'
import { PluginType } from '@/app/components/plugins/types'
import type { import type {
CollectionsAndPluginsSearchParams, CollectionsAndPluginsSearchParams,
MarketplaceCollection, MarketplaceCollection,
@ -14,7 +15,10 @@ export const getMarketplaceCollectionsAndPlugins = async (query?: CollectionsAnd
let marketplaceCollections = [] as MarketplaceCollection[] let marketplaceCollections = [] as MarketplaceCollection[]
let marketplaceCollectionPluginsMap = {} as Record<string, Plugin[]> let marketplaceCollectionPluginsMap = {} as Record<string, Plugin[]>
try { 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() const marketplaceCollectionsDataJson = await marketplaceCollectionsData.json()
marketplaceCollections = marketplaceCollectionsDataJson.data.collections marketplaceCollections = marketplaceCollectionsDataJson.data.collections
await Promise.all(marketplaceCollections.map(async (collection: MarketplaceCollection) => { await Promise.all(marketplaceCollections.map(async (collection: MarketplaceCollection) => {
@ -83,3 +87,16 @@ export const getMarketplacePlugins = async (query: PluginsSearchParams) => {
marketplacePlugins, 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 ''
}

@ -8,6 +8,5 @@ export const getValidTagKeys = (tags: string[]) => {
} }
export const getValidCategoryKeys = (category?: string) => { export const getValidCategoryKeys = (category?: string) => {
const currentCategory = categoryKeys.find(key => key === category) return categoryKeys.find(key => key === category)
return currentCategory ? `${currentCategory}s` : ''
} }

@ -6,6 +6,7 @@ import {
useMarketplacePlugins, useMarketplacePlugins,
} from '@/app/components/plugins/marketplace/hooks' } from '@/app/components/plugins/marketplace/hooks'
import { PluginType } from '@/app/components/plugins/types' import { PluginType } from '@/app/components/plugins/types'
import { getMarketplaceListCondition } from '@/app/components/plugins/marketplace/utils'
export const useMarketplace = (searchPluginText: string, filterPluginTags: string[]) => { export const useMarketplace = (searchPluginText: string, filterPluginTags: string[]) => {
const { const {
@ -39,7 +40,10 @@ export const useMarketplace = (searchPluginText: string, filterPluginTags: strin
}) })
} }
else { else {
queryMarketplaceCollectionsAndPlugins({ category: PluginType.tool }) queryMarketplaceCollectionsAndPlugins({
category: PluginType.tool,
condition: getMarketplaceListCondition(PluginType.tool),
})
resetPlugins() resetPlugins()
} }
}, [searchPluginText, filterPluginTags, queryPlugins, queryMarketplaceCollectionsAndPlugins, queryPluginsWithDebounced, resetPlugins]) }, [searchPluginText, filterPluginTags, queryPlugins, queryMarketplaceCollectionsAndPlugins, queryPluginsWithDebounced, resetPlugins])

Loading…
Cancel
Save