mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-16 10:05:56 +08:00
feat: split tools data to out and add demo
This commit is contained in:
parent
c1e0a939b0
commit
6d0eef12b1
39
web/app/(commonLayout)/plugins/test/tools-picker/page.tsx
Normal file
39
web/app/(commonLayout)/plugins/test/tools-picker/page.tsx
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
'use client'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import AllTools from '@/app/components/workflow/block-selector/all-tools'
|
||||||
|
import {
|
||||||
|
fetchAllBuiltInTools,
|
||||||
|
fetchAllCustomTools,
|
||||||
|
fetchAllWorkflowTools,
|
||||||
|
} from '@/service/tools'
|
||||||
|
import type { ToolWithProvider } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
|
const ToolsPicker = () => {
|
||||||
|
const [buildInTools, setBuildInTools] = useState<ToolWithProvider[]>([])
|
||||||
|
const [customTools, setCustomTools] = useState<ToolWithProvider[]>([])
|
||||||
|
const [workflowTools, setWorkflowTools] = useState<ToolWithProvider[]>([])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
const buildInTools = await fetchAllBuiltInTools()
|
||||||
|
const customTools = await fetchAllCustomTools()
|
||||||
|
const workflowTools = await fetchAllWorkflowTools()
|
||||||
|
setBuildInTools(buildInTools)
|
||||||
|
setCustomTools(customTools)
|
||||||
|
setWorkflowTools(workflowTools)
|
||||||
|
})()
|
||||||
|
})
|
||||||
|
return (
|
||||||
|
<div className="relative mt-5 mx-auto w-[320px] bg-white">
|
||||||
|
<AllTools
|
||||||
|
searchText=""
|
||||||
|
onSelect={() => { }}
|
||||||
|
buildInTools={buildInTools}
|
||||||
|
customTools={customTools}
|
||||||
|
workflowTools={workflowTools}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ToolsPicker
|
@ -6,7 +6,6 @@ import type {
|
|||||||
OnSelectBlock,
|
OnSelectBlock,
|
||||||
ToolWithProvider,
|
ToolWithProvider,
|
||||||
} from '../types'
|
} from '../types'
|
||||||
import { useStore } from '../store'
|
|
||||||
import { ToolTypeEnum } from './types'
|
import { ToolTypeEnum } from './types'
|
||||||
import Tools from './tools'
|
import Tools from './tools'
|
||||||
import { useToolTabs } from './hooks'
|
import { useToolTabs } from './hooks'
|
||||||
@ -15,18 +14,21 @@ import { useGetLanguage } from '@/context/i18n'
|
|||||||
|
|
||||||
type AllToolsProps = {
|
type AllToolsProps = {
|
||||||
searchText: string
|
searchText: string
|
||||||
|
buildInTools: ToolWithProvider[]
|
||||||
|
customTools: ToolWithProvider[]
|
||||||
|
workflowTools: ToolWithProvider[]
|
||||||
onSelect: OnSelectBlock
|
onSelect: OnSelectBlock
|
||||||
}
|
}
|
||||||
const AllTools = ({
|
const AllTools = ({
|
||||||
searchText,
|
searchText,
|
||||||
onSelect,
|
onSelect,
|
||||||
|
buildInTools,
|
||||||
|
workflowTools,
|
||||||
|
customTools,
|
||||||
}: AllToolsProps) => {
|
}: AllToolsProps) => {
|
||||||
const language = useGetLanguage()
|
const language = useGetLanguage()
|
||||||
const tabs = useToolTabs()
|
const tabs = useToolTabs()
|
||||||
const [activeTab, setActiveTab] = useState(ToolTypeEnum.All)
|
const [activeTab, setActiveTab] = useState(ToolTypeEnum.All)
|
||||||
const buildInTools = useStore(s => s.buildInTools)
|
|
||||||
const customTools = useStore(s => s.customTools)
|
|
||||||
const workflowTools = useStore(s => s.workflowTools)
|
|
||||||
|
|
||||||
const tools = useMemo(() => {
|
const tools = useMemo(() => {
|
||||||
let mergedTools: ToolWithProvider[] = []
|
let mergedTools: ToolWithProvider[] = []
|
||||||
|
@ -47,7 +47,7 @@ const IndexBar: FC<IndexBarProps> = ({ letters, itemRefs }) => {
|
|||||||
element.scrollIntoView({ behavior: 'smooth' })
|
element.scrollIntoView({ behavior: 'smooth' })
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="index-bar fixed right-4 top-36 flex flex-col items-center text-xs font-medium text-gray-500">
|
<div className="index-bar absolute right-4 top-36 flex flex-col items-center text-xs font-medium text-gray-500">
|
||||||
{letters.map(letter => (
|
{letters.map(letter => (
|
||||||
<div className="hover:text-gray-900 cursor-pointer" key={letter} onClick={() => handleIndexClick(letter)}>
|
<div className="hover:text-gray-900 cursor-pointer" key={letter} onClick={() => handleIndexClick(letter)}>
|
||||||
{letter}
|
{letter}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import { memo } from 'react'
|
import { memo } from 'react'
|
||||||
|
import { useStore } from '../store'
|
||||||
import type { BlockEnum } from '../types'
|
import type { BlockEnum } from '../types'
|
||||||
import { useTabs } from './hooks'
|
import { useTabs } from './hooks'
|
||||||
import type { ToolDefaultValue } from './types'
|
import type { ToolDefaultValue } from './types'
|
||||||
@ -25,6 +26,9 @@ const Tabs: FC<TabsProps> = ({
|
|||||||
noBlocks,
|
noBlocks,
|
||||||
}) => {
|
}) => {
|
||||||
const tabs = useTabs()
|
const tabs = useTabs()
|
||||||
|
const buildInTools = useStore(s => s.buildInTools)
|
||||||
|
const customTools = useStore(s => s.customTools)
|
||||||
|
const workflowTools = useStore(s => s.workflowTools)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onClick={e => e.stopPropagation()}>
|
<div onClick={e => e.stopPropagation()}>
|
||||||
@ -64,6 +68,9 @@ const Tabs: FC<TabsProps> = ({
|
|||||||
<AllTools
|
<AllTools
|
||||||
searchText={searchText}
|
searchText={searchText}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
|
buildInTools={buildInTools}
|
||||||
|
customTools={customTools}
|
||||||
|
workflowTools={workflowTools}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user