import { memo, useRef, } from 'react' import cn from 'classnames' import { useTranslation } from 'react-i18next' import { useClickAway } from 'ahooks' import ShortcutsName from './shortcuts-name' import { useStore } from './store' import { useNodesInteractions, usePanelInteractions, useWorkflowStartRun, } from './hooks' import AddBlock from './operator/add-block' import { useOperator } from './operator/hooks' import { exportAppConfig } from '@/service/apps' import { useToastContext } from '@/app/components/base/toast' import { useStore as useAppStore } from '@/app/components/app/store' const PanelContextmenu = () => { const { t } = useTranslation() const { notify } = useToastContext() const ref = useRef(null) const panelMenu = useStore(s => s.panelMenu) const clipboardElements = useStore(s => s.clipboardElements) const appDetail = useAppStore(s => s.appDetail) const { handleNodesPaste } = useNodesInteractions() const { handlePaneContextmenuCancel } = usePanelInteractions() const { handleStartWorkflowRun } = useWorkflowStartRun() const { handleAddNote } = useOperator() useClickAway(() => { handlePaneContextmenuCancel() }, ref) const onExport = async () => { if (!appDetail) return try { const { data } = await exportAppConfig(appDetail.id) const a = document.createElement('a') const file = new Blob([data], { type: 'application/yaml' }) a.href = URL.createObjectURL(file) a.download = `${appDetail.name}.yml` a.click() } catch (e) { notify({ type: 'error', message: t('app.exportFailed') }) } } const renderTrigger = () => { return (
{t('workflow.common.addBlock')}
) } if (!panelMenu) return null return (
{ e.stopPropagation() handleAddNote() handlePaneContextmenuCancel() }} > {t('workflow.nodes.note.addNote')}
{ handleStartWorkflowRun() handlePaneContextmenuCancel() }} > {t('workflow.common.run')}
{ if (clipboardElements.length) { handleNodesPaste() handlePaneContextmenuCancel() } }} > {t('workflow.common.pasteHere')}
onExport()} > {t('app.export')}
) } export default memo(PanelContextmenu)