import { useClickAway } from 'ahooks' import { memo, useRef, } from 'react' import { useTranslation } from 'react-i18next' import { useFeatures } from '@/app/components/base/features/hooks' import { cn } from '@/utils/classnames' import Divider from '../base/divider' import { useDSL, useNodesInteractions, usePanelInteractions, useWorkflowMoveMode, useWorkflowStartRun, } from './hooks' import AddBlock from './operator/add-block' import { useOperator } from './operator/hooks' import ShortcutsName from './shortcuts-name' import { useStore } from './store' const PanelContextmenu = () => { const { t } = useTranslation() const ref = useRef(null) const panelMenu = useStore(s => s.panelMenu) const clipboardElements = useStore(s => s.clipboardElements) const setShowImportDSLModal = useStore(s => s.setShowImportDSLModal) const setShowUpgradeRuntimeModal = useStore(s => s.setShowUpgradeRuntimeModal) const pendingComment = useStore(s => s.pendingComment) const setCommentPlacing = useStore(s => s.setCommentPlacing) const setCommentQuickAdd = useStore(s => s.setCommentQuickAdd) const sandboxEnabled = !!useFeatures(s => s.features.sandbox?.enabled) const { handleNodesPaste } = useNodesInteractions() const { handlePaneContextmenuCancel } = usePanelInteractions() const { handleStartWorkflowRun } = useWorkflowStartRun() const { handleAddNote } = useOperator() const { isCommentModeAvailable } = useWorkflowMoveMode() const { exportCheck } = useDSL() const pipelineId = useStore(s => s.pipelineId) useClickAway(() => { handlePaneContextmenuCancel() }, ref) const renderTrigger = () => { return (
{t('common.addBlock', { ns: 'workflow' })}
) } if (!panelMenu) return null return (
{ e.stopPropagation() handleAddNote() handlePaneContextmenuCancel() }} > {t('nodes.note.addNote', { ns: 'workflow' })}
{isCommentModeAvailable && (
{ e.stopPropagation() if (pendingComment) return setCommentQuickAdd(true) setCommentPlacing(true) handlePaneContextmenuCancel() }} > {t('comments.actions.addComment', { ns: 'workflow' })}
)}
{ handleStartWorkflowRun() handlePaneContextmenuCancel() }} > {t('common.run', { ns: 'workflow' })}
{ if (clipboardElements.length) { handleNodesPaste() handlePaneContextmenuCancel() } }} > {t('common.pasteHere', { ns: 'workflow' })}
exportCheck?.()} > {t('export', { ns: 'app' })}
setShowImportDSLModal(true)} > {!pipelineId ? t('importApp', { ns: 'app' }) : t('common.importDSL', { ns: 'workflow' })}
{!sandboxEnabled && ( <>
{ setShowUpgradeRuntimeModal(true) handlePaneContextmenuCancel() }} > {t('sandboxMigrationModal.upgrade', { ns: 'workflow' })}
)}
) } export default memo(PanelContextmenu)