chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import type { CommonNodeType } from '../../types'
|
||||
import { renderWorkflowComponent } from '../../__tests__/workflow-test-env'
|
||||
import { BlockEnum, NodeRunningStatus } from '../../types'
|
||||
import SimpleNode from '../index'
|
||||
|
||||
const control = vi.fn()
|
||||
const handle = vi.fn()
|
||||
// Controls and connection handles have independent interaction coverage.
|
||||
vi.mock('@/app/components/workflow/nodes/_base/components/node-control', () => ({
|
||||
default: (props: { id: string }) => {
|
||||
control(props)
|
||||
return null
|
||||
},
|
||||
}))
|
||||
vi.mock('@/app/components/workflow/nodes/_base/components/node-handle', () => ({
|
||||
NodeTargetHandle: (props: { id: string; handleId: string }) => {
|
||||
handle(props)
|
||||
return null
|
||||
},
|
||||
}))
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: 'editable',
|
||||
readOnly: false,
|
||||
candidate: false,
|
||||
status: undefined,
|
||||
controls: true,
|
||||
connection: true,
|
||||
},
|
||||
{
|
||||
name: 'running',
|
||||
readOnly: false,
|
||||
candidate: false,
|
||||
status: NodeRunningStatus.Running,
|
||||
controls: false,
|
||||
connection: true,
|
||||
},
|
||||
{
|
||||
name: 'candidate',
|
||||
readOnly: false,
|
||||
candidate: true,
|
||||
status: undefined,
|
||||
controls: false,
|
||||
connection: false,
|
||||
},
|
||||
{
|
||||
name: 'readonly',
|
||||
readOnly: true,
|
||||
candidate: false,
|
||||
status: undefined,
|
||||
controls: false,
|
||||
connection: true,
|
||||
},
|
||||
])(
|
||||
'exposes the appropriate controls for an $name node',
|
||||
({ readOnly, candidate, status, controls, connection }) => {
|
||||
const data: CommonNodeType = {
|
||||
title: 'Answer',
|
||||
desc: '',
|
||||
type: BlockEnum.Answer,
|
||||
_isCandidate: candidate,
|
||||
_runningStatus: status,
|
||||
}
|
||||
renderWorkflowComponent(<SimpleNode id="simple-node" data={data} />, {
|
||||
initialStoreState: { canvasReadOnly: readOnly },
|
||||
})
|
||||
if (controls)
|
||||
expect(control).toHaveBeenCalledWith(expect.objectContaining({ id: 'simple-node' }))
|
||||
else expect(control).not.toHaveBeenCalled()
|
||||
if (connection)
|
||||
expect(handle).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: 'simple-node', handleId: 'target' }),
|
||||
)
|
||||
else expect(handle).not.toHaveBeenCalled()
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
export const CUSTOM_SIMPLE_NODE = 'custom-simple'
|
||||
@@ -0,0 +1,98 @@
|
||||
import type { FC } from 'react'
|
||||
import type { NodeProps } from '@/app/components/workflow/types'
|
||||
import { cn } from '@langgenius/dify-ui/cn'
|
||||
import {
|
||||
RiAlertFill,
|
||||
RiCheckboxCircleFill,
|
||||
RiErrorWarningFill,
|
||||
RiLoader2Line,
|
||||
} from '@remixicon/react'
|
||||
import { memo, useMemo } from 'react'
|
||||
import BlockIcon from '@/app/components/workflow/block-icon'
|
||||
import NodeControl from '@/app/components/workflow/nodes/_base/components/node-control'
|
||||
import { NodeTargetHandle } from '@/app/components/workflow/nodes/_base/components/node-handle'
|
||||
import { NodeRunningStatus } from '@/app/components/workflow/types'
|
||||
import { useNodesReadOnly } from '../hooks/use-workflow'
|
||||
|
||||
const SimpleNode: FC<NodeProps> = ({ id, data }) => {
|
||||
const { nodesReadOnly } = useNodesReadOnly()
|
||||
|
||||
const showSelectedBorder = data.selected || data._isBundled || data._isEntering
|
||||
const { showRunningBorder, showSuccessBorder, showFailedBorder, showExceptionBorder } =
|
||||
useMemo(() => {
|
||||
return {
|
||||
showRunningBorder: data._runningStatus === NodeRunningStatus.Running && !showSelectedBorder,
|
||||
showSuccessBorder:
|
||||
data._runningStatus === NodeRunningStatus.Succeeded && !showSelectedBorder,
|
||||
showFailedBorder: data._runningStatus === NodeRunningStatus.Failed && !showSelectedBorder,
|
||||
showExceptionBorder:
|
||||
data._runningStatus === NodeRunningStatus.Exception && !showSelectedBorder,
|
||||
}
|
||||
}, [data._runningStatus, showSelectedBorder])
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'flex rounded-2xl border-2',
|
||||
showSelectedBorder
|
||||
? 'border-components-option-card-option-selected-border'
|
||||
: 'border-transparent',
|
||||
data._waitingRun && 'opacity-70',
|
||||
)}
|
||||
style={{
|
||||
width: 'auto',
|
||||
height: 'auto',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'group relative pb-1 shadow-xs',
|
||||
'rounded-[15px] border border-transparent',
|
||||
'w-60 bg-workflow-block-bg',
|
||||
!data._runningStatus && 'hover:shadow-lg',
|
||||
showRunningBorder && 'border-state-accent-solid!',
|
||||
showSuccessBorder && 'border-state-success-solid!',
|
||||
showFailedBorder && 'border-state-destructive-solid!',
|
||||
showExceptionBorder && 'border-state-warning-solid!',
|
||||
data._isBundled && 'shadow-lg!',
|
||||
)}
|
||||
>
|
||||
{!data._isCandidate && (
|
||||
<NodeTargetHandle
|
||||
id={id}
|
||||
data={data}
|
||||
handleClassName="top-4! -left-[9px]! translate-y-0!"
|
||||
handleId="target"
|
||||
/>
|
||||
)}
|
||||
{!data._runningStatus && !nodesReadOnly && !data._isCandidate && (
|
||||
<NodeControl id={id} data={data} />
|
||||
)}
|
||||
<div className={cn('flex items-center rounded-t-2xl px-3 pt-3 pb-2')}>
|
||||
<BlockIcon className="mr-2 shrink-0" type={data.type} size="md" />
|
||||
<div
|
||||
title={data.title}
|
||||
className="mr-1 flex grow items-center truncate system-sm-semibold-uppercase text-text-primary"
|
||||
>
|
||||
<div>{data.title}</div>
|
||||
</div>
|
||||
{(data._runningStatus === NodeRunningStatus.Running ||
|
||||
data._singleRunningStatus === NodeRunningStatus.Running) && (
|
||||
<RiLoader2Line className="size-3.5 animate-spin text-text-accent" />
|
||||
)}
|
||||
{data._runningStatus === NodeRunningStatus.Succeeded && (
|
||||
<RiCheckboxCircleFill className="size-3.5 text-text-success" />
|
||||
)}
|
||||
{data._runningStatus === NodeRunningStatus.Failed && (
|
||||
<RiErrorWarningFill className="size-3.5 text-text-destructive" />
|
||||
)}
|
||||
{data._runningStatus === NodeRunningStatus.Exception && (
|
||||
<RiAlertFill className="size-3.5 text-text-warning-secondary" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(SimpleNode)
|
||||
Reference in new issue
Block a user