From f4ee872a16132c1bc3e5ead2e36c311fc007a109 Mon Sep 17 00:00:00 2001 From: lyf-coder <58352715+lyf-coder@users.noreply.github.com> Date: Fri, 9 Dec 2022 22:01:19 +0800 Subject: [PATCH] fix(workflow/request-var): fix request node var editor (#1223) --- .../workflow/src/client/calculators.tsx | 2 +- .../src/client/components/EjsTextArea.tsx | 48 ++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/plugins/workflow/src/client/calculators.tsx b/packages/plugins/workflow/src/client/calculators.tsx index 0a8654886..76ea93067 100644 --- a/packages/plugins/workflow/src/client/calculators.tsx +++ b/packages/plugins/workflow/src/client/calculators.tsx @@ -386,7 +386,7 @@ export function Operand({ `}> { const options = typeof item.options === 'function' ? item.options() : item.options; return { diff --git a/packages/plugins/workflow/src/client/components/EjsTextArea.tsx b/packages/plugins/workflow/src/client/components/EjsTextArea.tsx index b8a756ae8..35c1f248b 100644 --- a/packages/plugins/workflow/src/client/components/EjsTextArea.tsx +++ b/packages/plugins/workflow/src/client/components/EjsTextArea.tsx @@ -3,51 +3,58 @@ 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 {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'; +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}%>`; + if (typeof operand === 'string') { + let pathArr = operand.replace('{{', '').replace('}}', '').split('.'); + if (pathArr.length > 0) { + const type = pathArr[0]; + if (type == '$context') { + return `<%=${pathArr.map((value, index) => { + if (index === 0) { + return 'ctx'; + } + return value; + }).join('.')}%>`; } - break; - case '$jobsMapByNodeId': - if (options?.nodeId) { - const node = nodes.find((n) => n.id == options.nodeId); + if (pathArr.length>1 && type == '$jobsMapByNodeId') { + const nodeId = pathArr[1] + const node = nodes.find((n) => n.id == nodeId); if (node) { if (node.type === 'calculation') { - return `<%= node.${options.nodeId} // ${t('Calculation result')} %>`; + return `<%= node[${nodeId}] // ${t('Calculation result')} %>`; } - if (options.path && node?.config?.collection) { + if (pathArr.length>2 && node?.config?.collection) { + const fieldName = pathArr[2] const fields = getCollectionFields(node?.config?.collection); - const field = fields.find((f) => f.name == options.path); + const field = fields.find((f) => f.name == fieldName); if (field) { - return `<%= node[${options.nodeId}].${options.path} // ${compile( + return `<%= node[${nodeId}].${fieldName} // ${compile( field.uiSchema?.title || field.name, )} %>`; } - return `<%= node[${options.nodeId}].${options.path}%>`; + return `<%= node[${nodeId}].${fieldName}%>`; } } } + } } return ''; } const AvailableVariableTool = (props) => { const { t } = useWorkflowTranslation(); - const [operand, setOperand] = useState({ type: '$context', value: '' }); + const [operand, setOperand] = useState(''); return ( @@ -105,13 +112,10 @@ export default function (props) {
- {props.description} - {' '} - {t('Syntax see')}{' '} + {props.description} {t('Syntax see')}{' '} ejs - - {' '} + {' '}