mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 23:45:51 +08:00
chore: use new add sub variables
This commit is contained in:
parent
afc9630cd0
commit
66953d57a2
@ -289,20 +289,26 @@ type PortalSelectProps = {
|
|||||||
onSelect: (value: Item) => void
|
onSelect: (value: Item) => void
|
||||||
items: Item[]
|
items: Item[]
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
|
renderTrigger?: (value?: Item) => JSX.Element | null
|
||||||
triggerClassName?: string
|
triggerClassName?: string
|
||||||
triggerClassNameFn?: (open: boolean) => string
|
triggerClassNameFn?: (open: boolean) => string
|
||||||
popupClassName?: string
|
popupClassName?: string
|
||||||
|
popupInnerClassName?: string
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
|
hideChecked?: boolean
|
||||||
}
|
}
|
||||||
const PortalSelect: FC<PortalSelectProps> = ({
|
const PortalSelect: FC<PortalSelectProps> = ({
|
||||||
value,
|
value,
|
||||||
onSelect,
|
onSelect,
|
||||||
items,
|
items,
|
||||||
placeholder,
|
placeholder,
|
||||||
|
renderTrigger,
|
||||||
triggerClassName,
|
triggerClassName,
|
||||||
triggerClassNameFn,
|
triggerClassNameFn,
|
||||||
popupClassName,
|
popupClassName,
|
||||||
|
popupInnerClassName,
|
||||||
readonly,
|
readonly,
|
||||||
|
hideChecked,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
@ -317,26 +323,31 @@ const PortalSelect: FC<PortalSelectProps> = ({
|
|||||||
offset={4}
|
offset={4}
|
||||||
>
|
>
|
||||||
<PortalToFollowElemTrigger onClick={() => !readonly && setOpen(v => !v)} className='w-full'>
|
<PortalToFollowElemTrigger onClick={() => !readonly && setOpen(v => !v)} className='w-full'>
|
||||||
<div
|
{renderTrigger
|
||||||
className={classNames(`
|
? renderTrigger(selectedItem)
|
||||||
|
: (
|
||||||
|
<div
|
||||||
|
className={classNames(`
|
||||||
flex items-center justify-between px-2.5 h-9 rounded-lg border-0 bg-gray-100 text-sm ${readonly ? 'cursor-not-allowed' : 'cursor-pointer'}
|
flex items-center justify-between px-2.5 h-9 rounded-lg border-0 bg-gray-100 text-sm ${readonly ? 'cursor-not-allowed' : 'cursor-pointer'}
|
||||||
`, triggerClassName, triggerClassNameFn?.(open))}
|
`, triggerClassName, triggerClassNameFn?.(open))}
|
||||||
title={selectedItem?.name}
|
title={selectedItem?.name}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className={`
|
className={`
|
||||||
grow truncate
|
grow truncate
|
||||||
${!selectedItem?.name && 'text-gray-400'}
|
${!selectedItem?.name && 'text-gray-400'}
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
{selectedItem?.name ?? localPlaceholder}
|
{selectedItem?.name ?? localPlaceholder}
|
||||||
</span>
|
</span>
|
||||||
<ChevronDownIcon className='shrink-0 h-4 w-4 text-gray-400' />
|
<ChevronDownIcon className='shrink-0 h-4 w-4 text-gray-400' />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
</PortalToFollowElemTrigger>
|
</PortalToFollowElemTrigger>
|
||||||
<PortalToFollowElemContent className={`z-20 ${popupClassName}`}>
|
<PortalToFollowElemContent className={`z-20 ${popupClassName}`}>
|
||||||
<div
|
<div
|
||||||
className='px-1 py-1 max-h-60 overflow-auto rounded-md bg-white text-base shadow-lg border-gray-200 border-[0.5px] focus:outline-none sm:text-sm'
|
className={classNames('px-1 py-1 max-h-60 overflow-auto rounded-md bg-white text-base shadow-lg border-gray-200 border-[0.5px] focus:outline-none sm:text-sm', popupInnerClassName)}
|
||||||
>
|
>
|
||||||
{items.map((item: Item) => (
|
{items.map((item: Item) => (
|
||||||
<div
|
<div
|
||||||
@ -357,7 +368,7 @@ const PortalSelect: FC<PortalSelectProps> = ({
|
|||||||
>
|
>
|
||||||
{item.name}
|
{item.name}
|
||||||
</span>
|
</span>
|
||||||
{item.value === value && (
|
{!hideChecked && item.value === value && (
|
||||||
<CheckIcon className='shrink-0 h-4 w-4 text-text-accent' />
|
<CheckIcon className='shrink-0 h-4 w-4 text-text-accent' />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,10 +12,12 @@ import type { CaseItem, HandleAddCondition, HandleAddSubVariableCondition, Handl
|
|||||||
import type { Node, NodeOutPutVar, Var } from '../../../types'
|
import type { Node, NodeOutPutVar, Var } from '../../../types'
|
||||||
import { VarType } from '../../../types'
|
import { VarType } from '../../../types'
|
||||||
import { useGetAvailableVars } from '../../variable-assigner/hooks'
|
import { useGetAvailableVars } from '../../variable-assigner/hooks'
|
||||||
|
import { SUB_VARIABLES } from '../default'
|
||||||
import ConditionList from './condition-list'
|
import ConditionList from './condition-list'
|
||||||
import ConditionAdd from './condition-add'
|
import ConditionAdd from './condition-add'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
|
import { PortalSelect as Select } from '@/app/components/base/select'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isSubVariable?: boolean
|
isSubVariable?: boolean
|
||||||
@ -73,6 +75,11 @@ const ConditionWrap: FC<Props> = ({
|
|||||||
return varPayload.type === VarType.number
|
return varPayload.type === VarType.number
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const subVarOptions = SUB_VARIABLES.map(item => ({
|
||||||
|
name: item,
|
||||||
|
value: item,
|
||||||
|
}))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ReactSortable
|
<ReactSortable
|
||||||
@ -151,14 +158,22 @@ const ConditionWrap: FC<Props> = ({
|
|||||||
)}>
|
)}>
|
||||||
{isSubVariable
|
{isSubVariable
|
||||||
? (
|
? (
|
||||||
<Button
|
<Select
|
||||||
size='small'
|
popupInnerClassName='w-[165px] max-h-none'
|
||||||
disabled={readOnly}
|
onSelect={value => handleAddSubVariableCondition?.(caseId!, conditionId!, value.value as string)}
|
||||||
onClick={() => handleAddSubVariableCondition?.(caseId!, conditionId!)}
|
items={subVarOptions}
|
||||||
>
|
value=''
|
||||||
<RiAddLine className='mr-1 w-3.5 h-3.5' />
|
renderTrigger={() => (
|
||||||
{t('workflow.nodes.ifElse.addSubVariable')}
|
<Button
|
||||||
</Button>
|
size='small'
|
||||||
|
disabled={readOnly}
|
||||||
|
>
|
||||||
|
<RiAddLine className='mr-1 w-3.5 h-3.5' />
|
||||||
|
{t('workflow.nodes.ifElse.addSubVariable')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
hideChecked
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
: (
|
: (
|
||||||
<ConditionAdd
|
<ConditionAdd
|
||||||
|
@ -64,7 +64,7 @@ export type HandleRemoveCondition = (caseId: string, conditionId: string) => voi
|
|||||||
export type HandleUpdateCondition = (caseId: string, conditionId: string, newCondition: Condition) => void
|
export type HandleUpdateCondition = (caseId: string, conditionId: string, newCondition: Condition) => void
|
||||||
export type HandleToggleConditionLogicalOperator = (caseId: string) => void
|
export type HandleToggleConditionLogicalOperator = (caseId: string) => void
|
||||||
|
|
||||||
export type HandleAddSubVariableCondition = (caseId: string, conditionId: string) => void
|
export type HandleAddSubVariableCondition = (caseId: string, conditionId: string, key?: string) => void
|
||||||
export type handleRemoveSubVariableCondition = (caseId: string, conditionId: string, subConditionId: string) => void
|
export type handleRemoveSubVariableCondition = (caseId: string, conditionId: string, subConditionId: string) => void
|
||||||
export type HandleUpdateSubVariableCondition = (caseId: string, conditionId: string, subConditionId: string, newSubCondition: Condition) => void
|
export type HandleUpdateSubVariableCondition = (caseId: string, conditionId: string, subConditionId: string, newSubCondition: Condition) => void
|
||||||
export type HandleToggleSubVariableConditionLogicalOperator = (caseId: string, conditionId: string) => void
|
export type HandleToggleSubVariableConditionLogicalOperator = (caseId: string, conditionId: string) => void
|
||||||
|
@ -180,7 +180,7 @@ const useConfig = (id: string, payload: IfElseNodeType) => {
|
|||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
const handleAddSubVariableCondition = useCallback<HandleAddSubVariableCondition>((caseId: string, conditionId: string) => {
|
const handleAddSubVariableCondition = useCallback<HandleAddSubVariableCondition>((caseId: string, conditionId: string, key?: string) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
const condition = draft.cases?.find(item => item.case_id === caseId)?.conditions.find(item => item.id === conditionId)
|
const condition = draft.cases?.find(item => item.case_id === caseId)?.conditions.find(item => item.id === conditionId)
|
||||||
if (!condition)
|
if (!condition)
|
||||||
@ -199,7 +199,7 @@ const useConfig = (id: string, payload: IfElseNodeType) => {
|
|||||||
|
|
||||||
subVarCondition.conditions.push({
|
subVarCondition.conditions.push({
|
||||||
id: uuid4(),
|
id: uuid4(),
|
||||||
key: '',
|
key: key || '',
|
||||||
varType: VarType.string,
|
varType: VarType.string,
|
||||||
comparison_operator: undefined,
|
comparison_operator: undefined,
|
||||||
value: '',
|
value: '',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user