feat: tool list use query

pull/12372/head
StyleZhang 2 years ago
parent a0a62db6ad
commit 6a63a03cb2

@ -1,9 +1,13 @@
import { RiArrowUpDoubleLine } from '@remixicon/react' import {
RiArrowRightUpLine,
RiArrowUpDoubleLine,
} from '@remixicon/react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useMarketplace } from './hooks' import { useMarketplace } from './hooks'
import List from '@/app/components/plugins/marketplace/list' import List from '@/app/components/plugins/marketplace/list'
import Loading from '@/app/components/base/loading' import Loading from '@/app/components/base/loading'
import { getLocaleOnClient } from '@/i18n' import { getLocaleOnClient } from '@/i18n'
import { MARKETPLACE_URL_PREFIX } from '@/config'
type MarketplaceProps = { type MarketplaceProps = {
searchPluginText: string searchPluginText: string
@ -51,7 +55,15 @@ const Marketplace = ({
<span className="relative ml-1 mr-1 body-md-medium text-text-secondary after:content-[''] after:absolute after:left-0 after:bottom-[1.5px] after:w-full after:h-2 after:bg-text-text-selected"> <span className="relative ml-1 mr-1 body-md-medium text-text-secondary after:content-[''] after:absolute after:left-0 after:bottom-[1.5px] after:w-full after:h-2 after:bg-text-text-selected">
{t('plugin.category.bundles')} {t('plugin.category.bundles')}
</span> </span>
{t('plugin.marketplace.inDifyMarketplace')} {t('common.operation.in')}
<a
href={`${MARKETPLACE_URL_PREFIX}`}
className='flex items-center ml-1 system-sm-medium text-text-accent'
target='_blank'
>
{t('plugin.marketplace.difyMarketplace')}
<RiArrowRightUpLine className='w-4 h-4' />
</a>
</div> </div>
</div> </div>
{ {

@ -10,10 +10,10 @@ import LabelFilter from '@/app/components/tools/labels/filter'
import Input from '@/app/components/base/input' import Input from '@/app/components/base/input'
import ProviderDetail from '@/app/components/tools/provider/detail' import ProviderDetail from '@/app/components/tools/provider/detail'
import Empty from '@/app/components/tools/add-tool-modal/empty' import Empty from '@/app/components/tools/add-tool-modal/empty'
import { fetchCollectionList } from '@/service/tools'
import Card from '@/app/components/plugins/card' import Card from '@/app/components/plugins/card'
import CardMoreInfo from '@/app/components/plugins/card/card-more-info' import CardMoreInfo from '@/app/components/plugins/card/card-more-info'
import { useSelector as useAppContextSelector } from '@/context/app-context' import { useSelector as useAppContextSelector } from '@/context/app-context'
import { useAllToolProviders } from '@/service/use-tools'
const ProviderList = () => { const ProviderList = () => {
const { t } = useTranslation() const { t } = useTranslation()
@ -36,8 +36,7 @@ const ProviderList = () => {
const handleKeywordsChange = (value: string) => { const handleKeywordsChange = (value: string) => {
setKeywords(value) setKeywords(value)
} }
const { data: collectionList, refetch } = useAllToolProviders()
const [collectionList, setCollectionList] = useState<Collection[]>([])
const filteredCollectionList = useMemo(() => { const filteredCollectionList = useMemo(() => {
return collectionList.filter((collection) => { return collectionList.filter((collection) => {
if (collection.type !== activeTab) if (collection.type !== activeTab)
@ -49,13 +48,6 @@ const ProviderList = () => {
return true return true
}) })
}, [activeTab, tagFilterValue, keywords, collectionList]) }, [activeTab, tagFilterValue, keywords, collectionList])
const getProviderList = async () => {
const list = await fetchCollectionList()
setCollectionList([...list])
}
useEffect(() => {
getProviderList()
}, [])
const [currentProvider, setCurrentProvider] = useState<Collection | undefined>() const [currentProvider, setCurrentProvider] = useState<Collection | undefined>()
useEffect(() => { useEffect(() => {
@ -106,7 +98,7 @@ const ProviderList = () => {
> >
<Card <Card
className={cn( className={cn(
'border-[1.5px] border-transparent', 'border-[1.5px] border-transparent cursor-pointer',
currentProvider?.id === collection.id && 'border-components-option-card-option-selected-border', currentProvider?.id === collection.id && 'border-components-option-card-option-selected-border',
)} )}
hideCornerMark hideCornerMark
@ -140,7 +132,7 @@ const ProviderList = () => {
<ProviderDetail <ProviderDetail
collection={currentProvider} collection={currentProvider}
onHide={() => setCurrentProvider(undefined)} onHide={() => setCurrentProvider(undefined)}
onRefreshData={getProviderList} onRefreshData={refetch}
/> />
)} )}
</div> </div>

@ -44,6 +44,7 @@ const translation = {
zoomOut: 'Zoom Out', zoomOut: 'Zoom Out',
zoomIn: 'Zoom In', zoomIn: 'Zoom In',
openInNewTab: 'Open in new tab', openInNewTab: 'Open in new tab',
in: 'in',
}, },
errorMsg: { errorMsg: {
fieldRequired: '{{field}} is required', fieldRequired: '{{field}} is required',

@ -126,7 +126,7 @@ const translation = {
empower: 'Empower your AI development', empower: 'Empower your AI development',
discover: 'Discover', discover: 'Discover',
and: 'and', and: 'and',
inDifyMarketplace: 'in Dify Marketplace', difyMarketplace: 'Dify Marketplace',
moreFrom: 'More from Marketplace', moreFrom: 'More from Marketplace',
noPluginFound: 'No plugin found', noPluginFound: 'No plugin found',
pluginsResult: '{{num}} results', pluginsResult: '{{num}} results',

@ -44,6 +44,7 @@ const translation = {
zoomOut: '缩小', zoomOut: '缩小',
zoomIn: '放大', zoomIn: '放大',
openInNewTab: '在新标签页打开', openInNewTab: '在新标签页打开',
in: '在',
}, },
errorMsg: { errorMsg: {
fieldRequired: '{{field}} 为必填项', fieldRequired: '{{field}} 为必填项',

@ -126,7 +126,7 @@ const translation = {
empower: '助力您的 AI 开发', empower: '助力您的 AI 开发',
discover: '探索', discover: '探索',
and: '和', and: '和',
inDifyMarketplace: '在 Dify 市场中', difyMarketplace: 'Dify 市场',
moreFrom: '更多来自市场', moreFrom: '更多来自市场',
noPluginFound: '未找到插件', noPluginFound: '未找到插件',
pluginsResult: '{{num}} 个插件结果', pluginsResult: '{{num}} 个插件结果',

@ -13,6 +13,15 @@ import {
const NAME_SPACE = 'tools' const NAME_SPACE = 'tools'
const useAllToolProvidersKey = [NAME_SPACE, 'allToolProviders']
export const useAllToolProviders = () => {
return useQuery({
queryKey: useAllToolProvidersKey,
queryFn: () => get<Collection[]>('/workspaces/current/tool-providers'),
initialData: [],
})
}
const useAllBuiltInToolsKey = [NAME_SPACE, 'builtIn'] const useAllBuiltInToolsKey = [NAME_SPACE, 'builtIn']
export const useAllBuiltInTools = () => { export const useAllBuiltInTools = () => {
return useQuery<ToolWithProvider[]>({ return useQuery<ToolWithProvider[]>({

Loading…
Cancel
Save