这些界面改动和专家服务草稿停在工作区,没有随上一笔主分支提交进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
171 lines
6.3 KiB
TypeScript
171 lines
6.3 KiB
TypeScript
import type { NodeActionsMenuProps } from './types'
|
|
import {
|
|
ContextMenuContent,
|
|
ContextMenuGroup,
|
|
ContextMenuItem,
|
|
ContextMenuLinkItem,
|
|
ContextMenuSeparator,
|
|
} from '@langgenius/dify-ui/context-menu'
|
|
import {
|
|
Popover,
|
|
PopoverBackdrop,
|
|
PopoverPortal,
|
|
PopoverPositioner,
|
|
PopoverTrigger,
|
|
} from '@langgenius/dify-ui/popover'
|
|
import { useRef } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { isOfficialDifyUrl } from '@/utils/official-link'
|
|
import { visibleAuthorName } from '@/utils/visible-author'
|
|
import { useStoreApi } from 'reactflow'
|
|
import { handleWorkflowMenuKeyDown } from '../shortcuts/handle-workflow-menu-key-down'
|
|
import { ChangeBlockPopup } from './change-block-popup'
|
|
import {
|
|
NODE_ACTIONS_MENU_ITEM_WITH_SHORTCUT_CLASS_NAME,
|
|
NODE_ACTIONS_MENU_WIDTH_CLASS_NAME,
|
|
NodeActionsMenuAbout,
|
|
NodeActionsMenuItemContent,
|
|
} from './shared'
|
|
import { useNodeActionsMenuModel } from './use-node-actions-menu-model'
|
|
|
|
export function NodeActionsContextMenuContent(props: NodeActionsMenuProps) {
|
|
const { t } = useTranslation(['common', 'workflow', 'workflowDebug'])
|
|
const model = useNodeActionsMenuModel(props)
|
|
const helpHref = model.helpLinkUri
|
|
const showNodeHelp = Boolean(helpHref) && !isOfficialDifyUrl(helpHref)
|
|
const authorName = visibleAuthorName(model.about.author)
|
|
const authorLabel = authorName
|
|
? `${t(($) => $['panel.createdBy'], { ns: 'workflow' })} ${authorName}`
|
|
: undefined
|
|
const flowStore = useStoreApi()
|
|
const deletingRef = useRef(false)
|
|
const hasRunGroup = model.canRun || model.canChangeBlock
|
|
const hasEditGroup = !model.nodesReadOnly && !model.isSingleton
|
|
const hasDeleteGroup = !model.nodesReadOnly && !model.isUndeletable
|
|
const singleRunActionLabel = model.isSingleRunning
|
|
? t(($) => $['debug.variableInspect.trigger.stop'], { ns: 'workflowDebug' })
|
|
: t(($) => $['panel.runThisStep'], { ns: 'workflow' })
|
|
|
|
function handleDelete() {
|
|
deletingRef.current = true
|
|
model.handleDelete()
|
|
}
|
|
|
|
return (
|
|
<ContextMenuContent
|
|
finalFocus={() => (deletingRef.current ? (flowStore.getState().domNode ?? true) : true)}
|
|
className={NODE_ACTIONS_MENU_WIDTH_CLASS_NAME}
|
|
onKeyDown={(event) =>
|
|
handleWorkflowMenuKeyDown(event, [
|
|
['workflow.copy', hasEditGroup ? model.handleCopy : undefined],
|
|
['workflow.duplicate', hasEditGroup ? model.handleDuplicate : undefined],
|
|
['workflow.delete', hasDeleteGroup ? handleDelete : undefined],
|
|
])
|
|
}
|
|
>
|
|
{hasRunGroup && (
|
|
<ContextMenuGroup>
|
|
{model.canRun && (
|
|
<ContextMenuItem onClick={model.handleRun}>{singleRunActionLabel}</ContextMenuItem>
|
|
)}
|
|
{model.canChangeBlock && (
|
|
<Popover modal="trap-focus">
|
|
<ContextMenuItem
|
|
closeOnClick={false}
|
|
// The menu row owns the focus treatment, so the trigger adds no ring.
|
|
render={
|
|
<PopoverTrigger
|
|
nativeButton={false}
|
|
className="focus-visible:ring-0"
|
|
render={<div />}
|
|
/>
|
|
}
|
|
className="data-popup-open:bg-state-base-hover"
|
|
>
|
|
{t(($) => $['panel.changeBlock'], { ns: 'workflow' })}
|
|
</ContextMenuItem>
|
|
<PopoverPortal>
|
|
<PopoverBackdrop />
|
|
<PopoverPositioner side="right" align="start" positionMethod="fixed">
|
|
<ChangeBlockPopup
|
|
nodeId={model.id}
|
|
nodeData={model.data}
|
|
sourceHandle={model.sourceHandle}
|
|
onComplete={props.onClose}
|
|
/>
|
|
</PopoverPositioner>
|
|
</PopoverPortal>
|
|
</Popover>
|
|
)}
|
|
</ContextMenuGroup>
|
|
)}
|
|
{hasRunGroup &&
|
|
(hasEditGroup || hasDeleteGroup || model.workflowAppHref || showNodeHelp) && (
|
|
<ContextMenuSeparator />
|
|
)}
|
|
{hasEditGroup && (
|
|
<ContextMenuGroup>
|
|
<ContextMenuItem
|
|
className={NODE_ACTIONS_MENU_ITEM_WITH_SHORTCUT_CLASS_NAME}
|
|
onClick={model.handleCopy}
|
|
>
|
|
<NodeActionsMenuItemContent shortcut="workflow.copy">
|
|
{t(($) => $['common.copy'], { ns: 'workflow' })}
|
|
</NodeActionsMenuItemContent>
|
|
</ContextMenuItem>
|
|
<ContextMenuItem
|
|
className={NODE_ACTIONS_MENU_ITEM_WITH_SHORTCUT_CLASS_NAME}
|
|
onClick={model.handleDuplicate}
|
|
>
|
|
<NodeActionsMenuItemContent shortcut="workflow.duplicate">
|
|
{t(($) => $['common.duplicate'], { ns: 'workflow' })}
|
|
</NodeActionsMenuItemContent>
|
|
</ContextMenuItem>
|
|
</ContextMenuGroup>
|
|
)}
|
|
{hasEditGroup && (hasDeleteGroup || model.workflowAppHref || showNodeHelp) && (
|
|
<ContextMenuSeparator />
|
|
)}
|
|
{hasDeleteGroup && (
|
|
<ContextMenuGroup>
|
|
<ContextMenuItem
|
|
variant="destructive"
|
|
className={NODE_ACTIONS_MENU_ITEM_WITH_SHORTCUT_CLASS_NAME}
|
|
onClick={handleDelete}
|
|
>
|
|
<NodeActionsMenuItemContent shortcut="workflow.delete">
|
|
{t(($) => $['operation.delete'], { ns: 'common' })}
|
|
</NodeActionsMenuItemContent>
|
|
</ContextMenuItem>
|
|
</ContextMenuGroup>
|
|
)}
|
|
{hasDeleteGroup && (model.workflowAppHref || showNodeHelp) && <ContextMenuSeparator />}
|
|
{model.workflowAppHref && (
|
|
<ContextMenuGroup>
|
|
<ContextMenuLinkItem
|
|
href={model.workflowAppHref}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
{t(($) => $['panel.openWorkflow'], { ns: 'workflow' })}
|
|
</ContextMenuLinkItem>
|
|
</ContextMenuGroup>
|
|
)}
|
|
{model.workflowAppHref && showNodeHelp && <ContextMenuSeparator />}
|
|
{showNodeHelp && (
|
|
<ContextMenuGroup>
|
|
<ContextMenuLinkItem href={helpHref} target="_blank" rel="noopener noreferrer">
|
|
{t(($) => $['panel.helpLink'], { ns: 'workflow' })}
|
|
</ContextMenuLinkItem>
|
|
</ContextMenuGroup>
|
|
)}
|
|
<ContextMenuSeparator />
|
|
<NodeActionsMenuAbout
|
|
title={t(($) => $['panel.about'], { ns: 'workflow' })}
|
|
description={model.about.description}
|
|
author={authorLabel}
|
|
/>
|
|
</ContextMenuContent>
|
|
)
|
|
}
|