mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-17 01:15:56 +08:00
feat: support choose var
This commit is contained in:
parent
f55a0dd269
commit
a1684791fc
@ -8,22 +8,27 @@ import cn from '@/utils/classnames'
|
|||||||
import TreeIndentLine from '../tree-indent-line'
|
import TreeIndentLine from '../tree-indent-line'
|
||||||
import { RiMoreFill } from '@remixicon/react'
|
import { RiMoreFill } from '@remixicon/react'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
|
import type { ValueSelector } from '@/app/components/workflow/types'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
const MAX_DEPTH = 10
|
const MAX_DEPTH = 10
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
valueSelector: ValueSelector
|
||||||
name: string,
|
name: string,
|
||||||
payload: FieldType,
|
payload: FieldType,
|
||||||
depth?: number
|
depth?: number
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
|
onSelect?: (valueSelector: ValueSelector) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const Field: FC<Props> = ({
|
const Field: FC<Props> = ({
|
||||||
|
valueSelector,
|
||||||
name,
|
name,
|
||||||
payload,
|
payload,
|
||||||
depth = 1,
|
depth = 1,
|
||||||
readonly,
|
readonly,
|
||||||
|
onSelect,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const isLastFieldHighlight = readonly
|
const isLastFieldHighlight = readonly
|
||||||
@ -34,7 +39,10 @@ const Field: FC<Props> = ({
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Tooltip popupContent={t('app.structOutput.moreFillTip')} disabled={depth !== MAX_DEPTH + 1}>
|
<Tooltip popupContent={t('app.structOutput.moreFillTip')} disabled={depth !== MAX_DEPTH + 1}>
|
||||||
<div className={cn('flex pr-2 items-center justify-between rounded-md', !readonly && 'hover:bg-state-base-hover', depth !== MAX_DEPTH + 1 && 'cursor-pointer')}>
|
<div
|
||||||
|
className={cn('flex pr-2 items-center justify-between rounded-md', !readonly && 'hover:bg-state-base-hover', depth !== MAX_DEPTH + 1 && 'cursor-pointer')}
|
||||||
|
onClick={() => !readonly && onSelect?.([...valueSelector, name])}
|
||||||
|
>
|
||||||
<div className='grow flex items-stretch'>
|
<div className='grow flex items-stretch'>
|
||||||
<TreeIndentLine depth={depth} />
|
<TreeIndentLine depth={depth} />
|
||||||
{depth === MAX_DEPTH + 1 ? (
|
{depth === MAX_DEPTH + 1 ? (
|
||||||
@ -57,6 +65,8 @@ const Field: FC<Props> = ({
|
|||||||
payload={payload.properties?.[name] as FieldType}
|
payload={payload.properties?.[name] as FieldType}
|
||||||
depth={depth + 1}
|
depth={depth + 1}
|
||||||
readonly={readonly}
|
readonly={readonly}
|
||||||
|
valueSelector={[...valueSelector, name]}
|
||||||
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useRef } from 'react'
|
import React, { useRef } from 'react'
|
||||||
import type { Field as FieldType, StructuredOutput } from '../../../../../llm/types'
|
import type { StructuredOutput } from '../../../../../llm/types'
|
||||||
import Field from './field'
|
import Field from './field'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import { useHover } from 'ahooks'
|
import { useHover } from 'ahooks'
|
||||||
|
import type { ValueSelector } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
className?: string
|
className?: string
|
||||||
root: { nodeName?: string, attrName: string }
|
root: { nodeId?: string, nodeName?: string, attrName: string }
|
||||||
payload: StructuredOutput
|
payload: StructuredOutput
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
onSelect?: (field: FieldType) => void
|
onSelect?: (valueSelector: ValueSelector) => void
|
||||||
onHovering?: (value: boolean) => void
|
onHovering?: (value: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ export const PickerPanelMain: FC<Props> = ({
|
|||||||
payload,
|
payload,
|
||||||
readonly,
|
readonly,
|
||||||
onHovering,
|
onHovering,
|
||||||
|
onSelect,
|
||||||
}) => {
|
}) => {
|
||||||
const ref = useRef<HTMLDivElement>(null)
|
const ref = useRef<HTMLDivElement>(null)
|
||||||
useHover(ref, {
|
useHover(ref, {
|
||||||
@ -59,6 +61,8 @@ export const PickerPanelMain: FC<Props> = ({
|
|||||||
name={name}
|
name={name}
|
||||||
payload={schema.properties[name]}
|
payload={schema.properties[name]}
|
||||||
readonly={readonly}
|
readonly={readonly}
|
||||||
|
valueSelector={[root.nodeId!, root.attrName]}
|
||||||
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
@ -138,9 +138,12 @@ const Item: FC<ItemProps> = ({
|
|||||||
}}>
|
}}>
|
||||||
{isStructureOutput && (
|
{isStructureOutput && (
|
||||||
<PickerStructurePanel
|
<PickerStructurePanel
|
||||||
root={{ attrName: itemData.variable }}
|
root={{ nodeId, nodeName: title, attrName: itemData.variable }}
|
||||||
payload={itemData.children as StructuredOutput}
|
payload={itemData.children as StructuredOutput}
|
||||||
onHovering={setIsChildrenHovering}
|
onHovering={setIsChildrenHovering}
|
||||||
|
onSelect={(valueSelector) => {
|
||||||
|
onChange(valueSelector, itemData)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{(isObj && !isFile) && (
|
{(isObj && !isFile) && (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user