mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 09:59:12 +08:00
feat: handle value picker in body file selector
This commit is contained in:
parent
dca4f9fe9c
commit
8efc63a705
@ -8,6 +8,7 @@ import {
|
|||||||
} from '@remixicon/react'
|
} from '@remixicon/react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import { useStoreApi } from 'reactflow'
|
import { useStoreApi } from 'reactflow'
|
||||||
|
import RemoveButton from '../remove-button'
|
||||||
import VarReferencePopup from './var-reference-popup'
|
import VarReferencePopup from './var-reference-popup'
|
||||||
import { getNodeInfoById, isConversationVar, isENV, isSystemVar } from './utils'
|
import { getNodeInfoById, isConversationVar, isENV, isSystemVar } from './utils'
|
||||||
import ConstantField from './constant-field'
|
import ConstantField from './constant-field'
|
||||||
@ -52,6 +53,8 @@ type Props = {
|
|||||||
isAddBtnTrigger?: boolean
|
isAddBtnTrigger?: boolean
|
||||||
schema?: Partial<CredentialFormSchema>
|
schema?: Partial<CredentialFormSchema>
|
||||||
valueTypePlaceHolder?: string
|
valueTypePlaceHolder?: string
|
||||||
|
isInTable?: boolean
|
||||||
|
onRemove?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const VarReferencePicker: FC<Props> = ({
|
const VarReferencePicker: FC<Props> = ({
|
||||||
@ -71,6 +74,8 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
isAddBtnTrigger,
|
isAddBtnTrigger,
|
||||||
schema,
|
schema,
|
||||||
valueTypePlaceHolder,
|
valueTypePlaceHolder,
|
||||||
|
isInTable,
|
||||||
|
onRemove,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const store = useStoreApi()
|
const store = useStoreApi()
|
||||||
@ -243,14 +248,15 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
if (readonly)
|
if (readonly)
|
||||||
return
|
return
|
||||||
!isConstant ? setOpen(!open) : setControlFocus(Date.now())
|
!isConstant ? setOpen(!open) : setControlFocus(Date.now())
|
||||||
}} className='!flex'>
|
}} className='!flex group/picker-trigger-wrap relative'>
|
||||||
|
<>
|
||||||
{isAddBtnTrigger
|
{isAddBtnTrigger
|
||||||
? (
|
? (
|
||||||
<div>
|
<div>
|
||||||
<AddButton onClick={() => { }}></AddButton>
|
<AddButton onClick={() => { }}></AddButton>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
: (<div ref={!isSupportConstantValue ? triggerRef : null} className={cn((open || isFocus) ? 'border-gray-300' : 'border-gray-100', 'relative group/wrap flex items-center w-full h-8', !isSupportConstantValue && 'p-1 rounded-lg bg-gray-100 border')}>
|
: (<div ref={!isSupportConstantValue ? triggerRef : null} className={cn((open || isFocus) ? 'border-gray-300' : 'border-gray-100', 'relative group/wrap flex items-center w-full h-8', !isSupportConstantValue && 'p-1 rounded-lg bg-gray-100 border', isInTable && 'bg-transparent border-none')}>
|
||||||
{isSupportConstantValue
|
{isSupportConstantValue
|
||||||
? <div onClick={(e) => {
|
? <div onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
@ -332,7 +338,7 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
|
|
||||||
</VarPickerWrap>
|
</VarPickerWrap>
|
||||||
)}
|
)}
|
||||||
{(hasValue && !readonly) && (<div
|
{(hasValue && !readonly && !isInTable) && (<div
|
||||||
className='invisible group-hover/wrap:visible absolute h-5 right-1 top-[50%] translate-y-[-50%] group p-1 rounded-md hover:bg-black/5 cursor-pointer'
|
className='invisible group-hover/wrap:visible absolute h-5 right-1 top-[50%] translate-y-[-50%] group p-1 rounded-md hover:bg-black/5 cursor-pointer'
|
||||||
onClick={handleClearVar}
|
onClick={handleClearVar}
|
||||||
>
|
>
|
||||||
@ -346,6 +352,13 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>)}
|
</div>)}
|
||||||
|
{!readonly && isInTable && (
|
||||||
|
<RemoveButton
|
||||||
|
className='group-hover/picker-trigger-wrap:block hidden absolute right-1 top-0.5'
|
||||||
|
onClick={() => onRemove?.()}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
</WrapElem>
|
</WrapElem>
|
||||||
<PortalToFollowElemContent style={{
|
<PortalToFollowElemContent style={{
|
||||||
zIndex: 100,
|
zIndex: 100,
|
||||||
|
|||||||
@ -54,7 +54,7 @@ const KeyValueItem: FC<Props> = ({
|
|||||||
})
|
})
|
||||||
onChange(newPayload)
|
onChange(newPayload)
|
||||||
}
|
}
|
||||||
}, [onChange, onAdd, isLastItem, payload])
|
}, [onChange, payload])
|
||||||
|
|
||||||
const filterOnlyFileVariable = (varPayload: Var) => {
|
const filterOnlyFileVariable = (varPayload: Var) => {
|
||||||
return [VarType.file, VarType.arrayFile].includes(varPayload.type)
|
return [VarType.file, VarType.arrayFile].includes(varPayload.type)
|
||||||
@ -109,6 +109,8 @@ const KeyValueItem: FC<Props> = ({
|
|||||||
value={payload.file || []}
|
value={payload.file || []}
|
||||||
onChange={handleChange('file')}
|
onChange={handleChange('file')}
|
||||||
filterVar={filterOnlyFileVariable}
|
filterVar={filterOnlyFileVariable}
|
||||||
|
isInTable
|
||||||
|
onRemove={onRemove}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
: (
|
: (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user