mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 05:55:59 +08:00
feat: prompt var popup
This commit is contained in:
parent
7a2c831ef3
commit
5c7a6db6b3
@ -11,6 +11,7 @@ import { mergeRegister } from '@lexical/utils'
|
|||||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
||||||
import {
|
import {
|
||||||
RiErrorWarningFill,
|
RiErrorWarningFill,
|
||||||
|
RiMoreLine,
|
||||||
} from '@remixicon/react'
|
} from '@remixicon/react'
|
||||||
import { useSelectOrDelete } from '../../hooks'
|
import { useSelectOrDelete } from '../../hooks'
|
||||||
import type { WorkflowNodesMap } from './node'
|
import type { WorkflowNodesMap } from './node'
|
||||||
@ -27,6 +28,8 @@ import { Line3 } from '@/app/components/base/icons/src/public/common'
|
|||||||
import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils'
|
import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
import { isExceptionVariable } from '@/app/components/workflow/utils'
|
import { isExceptionVariable } from '@/app/components/workflow/utils'
|
||||||
|
import VarFullPathPanel from '@/app/components/workflow/nodes/_base/components/variable/var-full-path-panel'
|
||||||
|
import { Type } from '@/app/components/workflow/nodes/llm/types'
|
||||||
|
|
||||||
type WorkflowVariableBlockComponentProps = {
|
type WorkflowVariableBlockComponentProps = {
|
||||||
nodeKey: string
|
nodeKey: string
|
||||||
@ -43,10 +46,11 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
const [editor] = useLexicalComposerContext()
|
const [editor] = useLexicalComposerContext()
|
||||||
const [ref, isSelected] = useSelectOrDelete(nodeKey, DELETE_WORKFLOW_VARIABLE_BLOCK_COMMAND)
|
const [ref, isSelected] = useSelectOrDelete(nodeKey, DELETE_WORKFLOW_VARIABLE_BLOCK_COMMAND)
|
||||||
const variablesLength = variables.length
|
const variablesLength = variables.length
|
||||||
|
const isShowAPart = variablesLength > 2
|
||||||
const varName = (
|
const varName = (
|
||||||
() => {
|
() => {
|
||||||
const isSystem = isSystemVar(variables)
|
const isSystem = isSystemVar(variables)
|
||||||
const varName = variablesLength >= 3 ? (variables).slice(-2).join('.') : variables[variablesLength - 1]
|
const varName = variables[variablesLength - 1]
|
||||||
return `${isSystem ? 'sys.' : ''}${varName}`
|
return `${isSystem ? 'sys.' : ''}${varName}`
|
||||||
}
|
}
|
||||||
)()
|
)()
|
||||||
@ -76,7 +80,7 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
const Item = (
|
const Item = (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'mx-0.5 relative group/wrap flex items-center h-[18px] pl-0.5 pr-[3px] rounded-[5px] border select-none',
|
'mx-0.5 relative group/wrap flex items-center h-[18px] pl-0.5 pr-[3px] rounded-[5px] border select-none hover:border-state-accent-solid hover:bg-state-accent-hover',
|
||||||
isSelected ? ' border-state-accent-solid bg-state-accent-hover' : ' border-components-panel-border-subtle bg-components-badge-white-to-dark',
|
isSelected ? ' border-state-accent-solid bg-state-accent-hover' : ' border-components-panel-border-subtle bg-components-badge-white-to-dark',
|
||||||
!node && !isEnv && !isChatVar && '!border-state-destructive-solid !bg-state-destructive-hover',
|
!node && !isEnv && !isChatVar && '!border-state-destructive-solid !bg-state-destructive-hover',
|
||||||
)}
|
)}
|
||||||
@ -99,6 +103,13 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
<Line3 className='mr-0.5 text-divider-deep'></Line3>
|
<Line3 className='mr-0.5 text-divider-deep'></Line3>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{isShowAPart && (
|
||||||
|
<div className='flex items-center'>
|
||||||
|
<RiMoreLine className='w-3 h-3 text-text-secondary' />
|
||||||
|
<Line3 className='mr-0.5 text-divider-deep'></Line3>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className='flex items-center text-text-accent'>
|
<div className='flex items-center text-text-accent'>
|
||||||
{!isEnv && !isChatVar && <Variable02 className={cn('shrink-0 w-3.5 h-3.5', isException && 'text-text-warning')} />}
|
{!isEnv && !isChatVar && <Variable02 className={cn('shrink-0 w-3.5 h-3.5', isException && 'text-text-warning')} />}
|
||||||
{isEnv && <Env className='shrink-0 w-3.5 h-3.5 text-util-colors-violet-violet-600' />}
|
{isEnv && <Env className='shrink-0 w-3.5 h-3.5 text-util-colors-violet-violet-600' />}
|
||||||
@ -126,7 +137,21 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Item
|
return (
|
||||||
|
<Tooltip
|
||||||
|
noDecoration
|
||||||
|
popupContent={
|
||||||
|
<VarFullPathPanel
|
||||||
|
nodeName={node.title}
|
||||||
|
path={variables.slice(1)}
|
||||||
|
varType={Type.string}
|
||||||
|
nodeType={node?.type}
|
||||||
|
/>}
|
||||||
|
disabled={!isShowAPart}
|
||||||
|
>
|
||||||
|
{Item}
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default memo(WorkflowVariableBlockComponent)
|
export default memo(WorkflowVariableBlockComponent)
|
||||||
|
@ -6,16 +6,19 @@ import { Type } from '../../../llm/types'
|
|||||||
import { PickerPanelMain as Panel } from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker'
|
import { PickerPanelMain as Panel } from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker'
|
||||||
import BlockIcon from '@/app/components/workflow/block-icon'
|
import BlockIcon from '@/app/components/workflow/block-icon'
|
||||||
import { BlockEnum } from '@/app/components/workflow/types'
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
nodeName: string
|
nodeName: string
|
||||||
path: string[]
|
path: string[]
|
||||||
varType: TypeWithArray
|
varType: TypeWithArray
|
||||||
|
nodeType?: BlockEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
const VarFullPathPanel: FC<Props> = ({
|
const VarFullPathPanel: FC<Props> = ({
|
||||||
nodeName,
|
nodeName,
|
||||||
path,
|
path,
|
||||||
varType,
|
varType,
|
||||||
|
nodeType = BlockEnum.LLM,
|
||||||
}) => {
|
}) => {
|
||||||
const schema: StructuredOutput = (() => {
|
const schema: StructuredOutput = (() => {
|
||||||
const schema: StructuredOutput['schema'] = {
|
const schema: StructuredOutput['schema'] = {
|
||||||
@ -41,7 +44,7 @@ const VarFullPathPanel: FC<Props> = ({
|
|||||||
return (
|
return (
|
||||||
<div className='w-[280px] pb-0 rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur shadow-lg backdrop-blur-[5px]'>
|
<div className='w-[280px] pb-0 rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur shadow-lg backdrop-blur-[5px]'>
|
||||||
<div className='flex p-3 pb-2 border-b-[0.5px] border-divider-subtle space-x-1 '>
|
<div className='flex p-3 pb-2 border-b-[0.5px] border-divider-subtle space-x-1 '>
|
||||||
<BlockIcon size='xs' type={BlockEnum.LLM} />
|
<BlockIcon size='xs' type={nodeType} />
|
||||||
<div className='w-0 grow system-xs-medium text-text-secondary truncate'>{nodeName}</div>
|
<div className='w-0 grow system-xs-medium text-text-secondary truncate'>{nodeName}</div>
|
||||||
</div>
|
</div>
|
||||||
<Panel
|
<Panel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user