mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 15:09:03 +08:00
fix: workflow search blocks (#7097)
This commit is contained in:
parent
b6d206e095
commit
925f0d2e09
@ -5,6 +5,7 @@ import type {
|
|||||||
import {
|
import {
|
||||||
memo,
|
memo,
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useMemo,
|
||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -17,6 +18,7 @@ import {
|
|||||||
} from '@remixicon/react'
|
} from '@remixicon/react'
|
||||||
import type { BlockEnum, OnSelectBlock } from '../types'
|
import type { BlockEnum, OnSelectBlock } from '../types'
|
||||||
import Tabs from './tabs'
|
import Tabs from './tabs'
|
||||||
|
import { TabsEnum } from './types'
|
||||||
import {
|
import {
|
||||||
PortalToFollowElem,
|
PortalToFollowElem,
|
||||||
PortalToFollowElemContent,
|
PortalToFollowElemContent,
|
||||||
@ -66,6 +68,9 @@ const NodeSelector: FC<NodeSelectorProps> = ({
|
|||||||
const handleOpenChange = useCallback((newOpen: boolean) => {
|
const handleOpenChange = useCallback((newOpen: boolean) => {
|
||||||
setLocalOpen(newOpen)
|
setLocalOpen(newOpen)
|
||||||
|
|
||||||
|
if (!newOpen)
|
||||||
|
setSearchText('')
|
||||||
|
|
||||||
if (onOpenChange)
|
if (onOpenChange)
|
||||||
onOpenChange(newOpen)
|
onOpenChange(newOpen)
|
||||||
}, [onOpenChange])
|
}, [onOpenChange])
|
||||||
@ -80,6 +85,19 @@ const NodeSelector: FC<NodeSelectorProps> = ({
|
|||||||
onSelect(type, toolDefaultValue)
|
onSelect(type, toolDefaultValue)
|
||||||
}, [handleOpenChange, onSelect])
|
}, [handleOpenChange, onSelect])
|
||||||
|
|
||||||
|
const [activeTab, setActiveTab] = useState(noBlocks ? TabsEnum.Tools : TabsEnum.Blocks)
|
||||||
|
const handleActiveTabChange = useCallback((newActiveTab: TabsEnum) => {
|
||||||
|
setActiveTab(newActiveTab)
|
||||||
|
}, [])
|
||||||
|
const searchPlaceholder = useMemo(() => {
|
||||||
|
if (activeTab === TabsEnum.Blocks)
|
||||||
|
return t('workflow.tabs.searchBlock')
|
||||||
|
|
||||||
|
if (activeTab === TabsEnum.Tools)
|
||||||
|
return t('workflow.tabs.searchTool')
|
||||||
|
return ''
|
||||||
|
}, [activeTab, t])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PortalToFollowElem
|
<PortalToFollowElem
|
||||||
placement={placement}
|
placement={placement}
|
||||||
@ -120,7 +138,7 @@ const NodeSelector: FC<NodeSelectorProps> = ({
|
|||||||
<input
|
<input
|
||||||
value={searchText}
|
value={searchText}
|
||||||
className='grow px-0.5 py-[7px] text-[13px] text-gray-700 bg-transparent appearance-none outline-none caret-primary-600 placeholder:text-gray-400'
|
className='grow px-0.5 py-[7px] text-[13px] text-gray-700 bg-transparent appearance-none outline-none caret-primary-600 placeholder:text-gray-400'
|
||||||
placeholder={t('workflow.tabs.searchBlock') || ''}
|
placeholder={searchPlaceholder}
|
||||||
onChange={e => setSearchText(e.target.value)}
|
onChange={e => setSearchText(e.target.value)}
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
@ -137,6 +155,8 @@ const NodeSelector: FC<NodeSelectorProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Tabs
|
<Tabs
|
||||||
|
activeTab={activeTab}
|
||||||
|
onActiveTabChange={handleActiveTabChange}
|
||||||
onSelect={handleSelect}
|
onSelect={handleSelect}
|
||||||
searchText={searchText}
|
searchText={searchText}
|
||||||
availableBlocksTypes={availableBlocksTypes}
|
availableBlocksTypes={availableBlocksTypes}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import {
|
import { memo } from 'react'
|
||||||
memo,
|
|
||||||
useState,
|
|
||||||
} from 'react'
|
|
||||||
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'
|
||||||
@ -12,19 +9,22 @@ import AllTools from './all-tools'
|
|||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
export type TabsProps = {
|
export type TabsProps = {
|
||||||
|
activeTab: TabsEnum
|
||||||
|
onActiveTabChange: (activeTab: TabsEnum) => void
|
||||||
searchText: string
|
searchText: string
|
||||||
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
||||||
availableBlocksTypes?: BlockEnum[]
|
availableBlocksTypes?: BlockEnum[]
|
||||||
noBlocks?: boolean
|
noBlocks?: boolean
|
||||||
}
|
}
|
||||||
const Tabs: FC<TabsProps> = ({
|
const Tabs: FC<TabsProps> = ({
|
||||||
|
activeTab,
|
||||||
|
onActiveTabChange,
|
||||||
searchText,
|
searchText,
|
||||||
onSelect,
|
onSelect,
|
||||||
availableBlocksTypes,
|
availableBlocksTypes,
|
||||||
noBlocks,
|
noBlocks,
|
||||||
}) => {
|
}) => {
|
||||||
const tabs = useTabs()
|
const tabs = useTabs()
|
||||||
const [activeTab, setActiveTab] = useState(noBlocks ? TabsEnum.Tools : TabsEnum.Blocks)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onClick={e => e.stopPropagation()}>
|
<div onClick={e => e.stopPropagation()}>
|
||||||
@ -41,7 +41,7 @@ const Tabs: FC<TabsProps> = ({
|
|||||||
? 'text-gray-700 after:absolute after:bottom-0 after:left-0 after:h-0.5 after:w-full after:bg-primary-600'
|
? 'text-gray-700 after:absolute after:bottom-0 after:left-0 after:h-0.5 after:w-full after:bg-primary-600'
|
||||||
: 'text-gray-500',
|
: 'text-gray-500',
|
||||||
)}
|
)}
|
||||||
onClick={() => setActiveTab(tab.key)}
|
onClick={() => onActiveTabChange(tab.key)}
|
||||||
>
|
>
|
||||||
{tab.name}
|
{tab.name}
|
||||||
</div>
|
</div>
|
||||||
|
@ -149,6 +149,7 @@ const translation = {
|
|||||||
tabs: {
|
tabs: {
|
||||||
'searchBlock': 'Search block',
|
'searchBlock': 'Search block',
|
||||||
'blocks': 'Blocks',
|
'blocks': 'Blocks',
|
||||||
|
'searchTool': 'Search tool',
|
||||||
'tools': 'Tools',
|
'tools': 'Tools',
|
||||||
'allTool': 'All',
|
'allTool': 'All',
|
||||||
'builtInTool': 'Built-in',
|
'builtInTool': 'Built-in',
|
||||||
|
@ -149,6 +149,7 @@ const translation = {
|
|||||||
tabs: {
|
tabs: {
|
||||||
'searchBlock': '搜索节点',
|
'searchBlock': '搜索节点',
|
||||||
'blocks': '节点',
|
'blocks': '节点',
|
||||||
|
'searchTool': '搜索工具',
|
||||||
'tools': '工具',
|
'tools': '工具',
|
||||||
'allTool': '全部',
|
'allTool': '全部',
|
||||||
'builtInTool': '内置',
|
'builtInTool': '内置',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user