mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 21:05:53 +08:00
feat: support view choose
This commit is contained in:
parent
fc61fd0f50
commit
b8cd6ea478
@ -9,6 +9,7 @@ import type {
|
|||||||
import { ToolTypeEnum } from './types'
|
import { ToolTypeEnum } from './types'
|
||||||
import Tools from './tools'
|
import Tools from './tools'
|
||||||
import { useToolTabs } from './hooks'
|
import { useToolTabs } from './hooks'
|
||||||
|
import ViewTypeSelect, { ViewType } from './view-type-select'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import { useGetLanguage } from '@/context/i18n'
|
import { useGetLanguage } from '@/context/i18n'
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ const AllTools = ({
|
|||||||
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 [activeView, setActiveView] = useState<ViewType>(ViewType.list)
|
||||||
|
|
||||||
const tools = useMemo(() => {
|
const tools = useMemo(() => {
|
||||||
let mergedTools: ToolWithProvider[] = []
|
let mergedTools: ToolWithProvider[] = []
|
||||||
@ -49,22 +51,25 @@ const AllTools = ({
|
|||||||
}, [activeTab, buildInTools, customTools, workflowTools, searchText, language])
|
}, [activeTab, buildInTools, customTools, workflowTools, searchText, language])
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className='flex items-center px-3 h-8 space-x-1 bg-gray-25 border-b-[0.5px] border-black/[0.08] shadow-xs'>
|
<div className='flex items-center justify-between px-3 bg-background-default-hover border-b-[0.5px] border-black/[0.08] shadow-xs'>
|
||||||
{
|
<div className='flex items-center h-8 space-x-1'>
|
||||||
tabs.map(tab => (
|
{
|
||||||
<div
|
tabs.map(tab => (
|
||||||
className={cn(
|
<div
|
||||||
'flex items-center px-2 h-6 rounded-md hover:bg-gray-100 cursor-pointer',
|
className={cn(
|
||||||
'text-xs font-medium text-gray-700',
|
'flex items-center px-2 h-6 rounded-md hover:bg-gray-100 cursor-pointer',
|
||||||
activeTab === tab.key && 'bg-gray-200',
|
'text-xs font-medium text-gray-700',
|
||||||
)}
|
activeTab === tab.key && 'bg-gray-200',
|
||||||
key={tab.key}
|
)}
|
||||||
onClick={() => setActiveTab(tab.key)}
|
key={tab.key}
|
||||||
>
|
onClick={() => setActiveTab(tab.key)}
|
||||||
{tab.name}
|
>
|
||||||
</div>
|
{tab.name}
|
||||||
))
|
</div>
|
||||||
}
|
))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<ViewTypeSelect viewType={activeView} onChange={setActiveView} />
|
||||||
</div>
|
</div>
|
||||||
<Tools
|
<Tools
|
||||||
showWorkflowEmpty={activeTab === ToolTypeEnum.Workflow}
|
showWorkflowEmpty={activeTab === ToolTypeEnum.Workflow}
|
||||||
|
@ -41,7 +41,7 @@ export const useToolTabs = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: ToolTypeEnum.BuiltIn,
|
key: ToolTypeEnum.BuiltIn,
|
||||||
name: t('workflow.tabs.builtInTool'),
|
name: t('workflow.tabs.plugin'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: ToolTypeEnum.Custom,
|
key: ToolTypeEnum.Custom,
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
} from 'react'
|
} from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { BlockEnum, ToolWithProvider } from '../types'
|
import type { BlockEnum, ToolWithProvider } from '../types'
|
||||||
|
import { CollectionType } from '../../tools/types'
|
||||||
import IndexBar, { groupItems } from './index-bar'
|
import IndexBar, { groupItems } from './index-bar'
|
||||||
import type { ToolDefaultValue } from './types'
|
import type { ToolDefaultValue } from './types'
|
||||||
import ToolItem from './tool-item'
|
import ToolItem from './tool-item'
|
||||||
@ -42,7 +43,7 @@ const Blocks = ({
|
|||||||
list.map(tool => (
|
list.map(tool => (
|
||||||
<ToolItem
|
<ToolItem
|
||||||
key={tool.name}
|
key={tool.name}
|
||||||
isToolPlugin={toolWithProvider.type === 'builtin'}
|
isToolPlugin={toolWithProvider.type === CollectionType.builtIn}
|
||||||
provider={toolWithProvider}
|
provider={toolWithProvider}
|
||||||
payload={tool}
|
payload={tool}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
'use client'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import React, { useCallback } from 'react'
|
||||||
|
import { RiNodeTree, RiSortAlphabetAsc } from '@remixicon/react'
|
||||||
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
|
export enum ViewType {
|
||||||
|
list = 'list',
|
||||||
|
tree = 'tree',
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
viewType: ViewType
|
||||||
|
onChange: (viewType: ViewType) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const ViewTypeSelect: FC<Props> = ({
|
||||||
|
viewType,
|
||||||
|
onChange,
|
||||||
|
}) => {
|
||||||
|
const handleChange = useCallback((nextViewType: ViewType) => {
|
||||||
|
return () => {
|
||||||
|
if (nextViewType === viewType)
|
||||||
|
return
|
||||||
|
onChange(nextViewType)
|
||||||
|
}
|
||||||
|
}, [viewType, onChange])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='flex items-center rounded-lg bg-components-segmented-control-bg-normal p-px'>
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
cn('p-[3px] rounded-lg',
|
||||||
|
viewType === ViewType.list
|
||||||
|
? 'bg-components-segmented-control-item-active-bg shadow-xs text-text-accent-light-mode-only'
|
||||||
|
: 'text-text-tertiary cursor-pointer',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onClick={handleChange(ViewType.list)}
|
||||||
|
>
|
||||||
|
<RiSortAlphabetAsc className='w-4 h-4' />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
cn('p-[3px] rounded-lg',
|
||||||
|
viewType === ViewType.tree
|
||||||
|
? 'bg-components-segmented-control-item-active-bg shadow-xs text-text-accent-light-mode-only'
|
||||||
|
: 'text-text-tertiary cursor-pointer',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onClick={handleChange(ViewType.tree)}
|
||||||
|
>
|
||||||
|
<RiNodeTree className='w-4 h-4 ' />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(ViewTypeSelect)
|
@ -197,7 +197,7 @@ const translation = {
|
|||||||
'searchTool': '搜索工具',
|
'searchTool': '搜索工具',
|
||||||
'tools': '工具',
|
'tools': '工具',
|
||||||
'allTool': '全部',
|
'allTool': '全部',
|
||||||
'builtInTool': '内置',
|
'plugin': '插件',
|
||||||
'customTool': '自定义',
|
'customTool': '自定义',
|
||||||
'workflowTool': '工作流',
|
'workflowTool': '工作流',
|
||||||
'question-understand': '问题理解',
|
'question-understand': '问题理解',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user