diff --git a/packages/plugins/workflow/package.json b/packages/plugins/workflow/package.json index e82759f3d..f0328133d 100644 --- a/packages/plugins/workflow/package.json +++ b/packages/plugins/workflow/package.json @@ -18,9 +18,12 @@ "classnames": "^2.3.1", "cron-parser": "4.4.0", "json-templates": "^4.2.0", - "react-js-cron": "^1.4.0" + "react-js-cron": "^1.4.0", + "ejs": "^3.1.8", + "react-copy-to-clipboard": "^5.1.0" }, "devDependencies": { + "@types/ejs": "^3.1.1", "@nocobase/test": "0.8.0-alpha.13" }, "gitHead": "ce588eefb0bfc50f7d5bbee575e0b5e843bf6644" diff --git a/packages/plugins/workflow/src/client/components/EjsTextArea.tsx b/packages/plugins/workflow/src/client/components/EjsTextArea.tsx new file mode 100644 index 000000000..b8a756ae8 --- /dev/null +++ b/packages/plugins/workflow/src/client/components/EjsTextArea.tsx @@ -0,0 +1,121 @@ +import React, { useState } from 'react'; +import { Row, Col } from 'antd'; +import { CopyOutlined, ToolOutlined } from '@ant-design/icons'; +import { CopyToClipboard } from 'react-copy-to-clipboard'; + +import { Operand, VariableTypes, VariableTypesContext } from '../calculators'; +import { Button, Input, message, Tooltip } from 'antd'; +import { useFlowContext } from '../FlowContext'; +import { useCollectionManager, useCompile } from '@nocobase/client'; +import { useWorkflowTranslation } from '../locale'; + +function getVal(operand) { + const { options } = operand; + const { t } = useWorkflowTranslation(); + const compile = useCompile(); + const { getCollectionFields } = useCollectionManager(); + const { nodes } = useFlowContext(); + + switch (operand.type) { + case '$context': + if (options?.path) { + return `<%=ctx.${options.path}%>`; + } + break; + case '$jobsMapByNodeId': + if (options?.nodeId) { + const node = nodes.find((n) => n.id == options.nodeId); + if (node) { + if (node.type === 'calculation') { + return `<%= node.${options.nodeId} // ${t('Calculation result')} %>`; + } + if (options.path && node?.config?.collection) { + const fields = getCollectionFields(node?.config?.collection); + const field = fields.find((f) => f.name == options.path); + if (field) { + return `<%= node[${options.nodeId}].${options.path} // ${compile( + field.uiSchema?.title || field.name, + )} %>`; + } + return `<%= node[${options.nodeId}].${options.path}%>`; + } + } + } + } + return ''; +} + +const AvailableVariableTool = (props) => { + const { t } = useWorkflowTranslation(); + const [operand, setOperand] = useState({ type: '$context', value: '' }); + return ( + + + setOperand(v)} /> + + + + + + { + message.success({ + content: t('Copy success!'), + duration: 1, + style: { + marginTop: '20vh', + }, + }); + }} + > + +