mirror of
https://github.com/langgenius/dify.git
synced 2026-01-06 06:26:00 +00:00
fix: marketplace collection condition
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ export type PluginsSort = {
|
||||
|
||||
export type CollectionsAndPluginsSearchParams = {
|
||||
category?: string
|
||||
condition?: string
|
||||
}
|
||||
|
||||
export type SearchParams = {
|
||||
|
||||
@@ -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<string, Plugin[]>
|
||||
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 ''
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user