mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 08:26:27 +08:00
feat: support var search
This commit is contained in:
parent
b5fe1f7c46
commit
2ebd8d9fdc
@ -12,6 +12,10 @@ import {
|
|||||||
PortalToFollowElemContent,
|
PortalToFollowElemContent,
|
||||||
PortalToFollowElemTrigger,
|
PortalToFollowElemTrigger,
|
||||||
} from '@/app/components/base/portal-to-follow-elem'
|
} from '@/app/components/base/portal-to-follow-elem'
|
||||||
|
import {
|
||||||
|
SearchLg,
|
||||||
|
} from '@/app/components/base/icons/src/vender/line/general'
|
||||||
|
import { XCircle } from '@/app/components/base/icons/src/vender/solid/general'
|
||||||
|
|
||||||
type ObjectChildrenProps = {
|
type ObjectChildrenProps = {
|
||||||
nodeId: string
|
nodeId: string
|
||||||
@ -51,9 +55,14 @@ const Item: FC<ItemProps> = ({
|
|||||||
setIsItemHovering(true)
|
setIsItemHovering(true)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setTimeout(() => {
|
if (isObj) {
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsItemHovering(false)
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
else {
|
||||||
setIsItemHovering(false)
|
setIsItemHovering(false)
|
||||||
}, 100)
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -185,30 +194,72 @@ const VarReferencePopup: FC<Props> = ({
|
|||||||
itemWidth,
|
itemWidth,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const [searchText, setSearchText] = useState('')
|
||||||
|
const filteredVars = vars.filter((v) => {
|
||||||
|
if (!searchText)
|
||||||
|
return v
|
||||||
|
const children = v.vars.filter(v => v.variable.toLowerCase().includes(searchText.toLowerCase()))
|
||||||
|
return children.length > 0
|
||||||
|
}).map((v) => {
|
||||||
|
if (!searchText)
|
||||||
|
return v
|
||||||
|
const children = v.vars.filter(v => v.variable.toLowerCase().includes(searchText.toLowerCase()))
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
vars: children,
|
||||||
|
}
|
||||||
|
})
|
||||||
// max-h-[300px] overflow-y-auto todo: use portal to handle long list
|
// max-h-[300px] overflow-y-auto todo: use portal to handle long list
|
||||||
return (
|
return (
|
||||||
<div className='p-1 bg-white rounded-lg border border-gray-200 shadow-lg space-y-1' style={{
|
<div className='p-1 bg-white rounded-lg border border-gray-200 shadow-lg space-y-1' style={{
|
||||||
width: itemWidth || 228,
|
width: itemWidth || 228,
|
||||||
}}>
|
}}>
|
||||||
{vars.length > 0
|
<div
|
||||||
? vars.map((item, i) => (
|
className='mt-1 mb-2 mx-2 flex items-center px-2 rounded-lg bg-gray-100'
|
||||||
<div key={i}>
|
onClick={e => e.stopPropagation()}
|
||||||
<div className='flex items-center h-[22px] px-3 text-xs font-medium text-gray-500 uppercase'>{item.title}</div>
|
>
|
||||||
{item.vars.map((v, j) => (
|
<SearchLg className='shrink-0 ml-[1px] mr-[5px] w-3.5 h-3.5 text-gray-400' />
|
||||||
<Item
|
<input
|
||||||
key={j}
|
value={searchText}
|
||||||
title={item.title}
|
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'
|
||||||
nodeId={item.nodeId}
|
placeholder={t('workflow.common.searchVar') || ''}
|
||||||
objPath={[]}
|
onChange={e => setSearchText(e.target.value)}
|
||||||
itemData={v}
|
autoFocus
|
||||||
onChange={onChange}
|
/>
|
||||||
itemWidth={itemWidth}
|
{
|
||||||
/>
|
searchText && (
|
||||||
))}
|
<div
|
||||||
</div>
|
className='flex items-center justify-center ml-[5px] w-[18px] h-[18px] cursor-pointer'
|
||||||
))
|
onClick={() => setSearchText('')}
|
||||||
|
>
|
||||||
|
<XCircle className='w-[14px] h-[14px] text-gray-400' />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
{filteredVars.length > 0
|
||||||
|
? <div>
|
||||||
|
|
||||||
|
{
|
||||||
|
filteredVars.map((item, i) => (
|
||||||
|
<div key={i}>
|
||||||
|
<div className='flex items-center h-[22px] px-3 text-xs font-medium text-gray-500 uppercase'>{item.title}</div>
|
||||||
|
{item.vars.map((v, j) => (
|
||||||
|
<Item
|
||||||
|
key={j}
|
||||||
|
title={item.title}
|
||||||
|
nodeId={item.nodeId}
|
||||||
|
objPath={[]}
|
||||||
|
itemData={v}
|
||||||
|
onChange={onChange}
|
||||||
|
itemWidth={itemWidth}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
: <div className='pl-3 leading-[18px] text-xs font-medium text-gray-500 uppercase'>{t('workflow.common.noVar')}</div>}
|
: <div className='pl-3 leading-[18px] text-xs font-medium text-gray-500 uppercase'>{t('workflow.common.noVar')}</div>}
|
||||||
</div>
|
</div >
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
export default React.memo(VarReferencePopup)
|
export default React.memo(VarReferencePopup)
|
||||||
|
|||||||
@ -24,6 +24,7 @@ const translation = {
|
|||||||
addTitle: 'Add title...',
|
addTitle: 'Add title...',
|
||||||
addDescription: 'Add description...',
|
addDescription: 'Add description...',
|
||||||
noVar: 'No variable',
|
noVar: 'No variable',
|
||||||
|
searchVar: 'Search variable',
|
||||||
variableNamePlaceholder: 'Variable name',
|
variableNamePlaceholder: 'Variable name',
|
||||||
setVarValuePlaceholder: 'Set variable',
|
setVarValuePlaceholder: 'Set variable',
|
||||||
needConnecttip: 'This step is not connected to anything',
|
needConnecttip: 'This step is not connected to anything',
|
||||||
|
|||||||
@ -25,6 +25,7 @@ const translation = {
|
|||||||
addDescription: '添加描述...',
|
addDescription: '添加描述...',
|
||||||
noVar: '没有变量',
|
noVar: '没有变量',
|
||||||
variableNamePlaceholder: '变量名',
|
variableNamePlaceholder: '变量名',
|
||||||
|
searchVar: '搜索变量',
|
||||||
setVarValuePlaceholder: '设置变量值',
|
setVarValuePlaceholder: '设置变量值',
|
||||||
needConnecttip: '此节点尚未连接到其他节点',
|
needConnecttip: '此节点尚未连接到其他节点',
|
||||||
maxTreeDepth: '每个分支最大限制 {{depth}} 个节点',
|
maxTreeDepth: '每个分支最大限制 {{depth}} 个节点',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user