fix(workflow/request-var): fix request node var editor (#1223)

This commit is contained in:
lyf-coder 2022-12-09 22:01:19 +08:00 committed by GitHub
parent 0ddd73cf3b
commit f4ee872a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 23 deletions

View File

@ -386,7 +386,7 @@ export function Operand({
`}>
<Cascader
allowClear={false}
value={[type, ...(appendTypeValue ? appendTypeValue(operand) : [])]}
value={[Types[type] ? type : '', ...(appendTypeValue ? appendTypeValue(operand) : [])]}
options={Object.values(Types).map((item: any) => {
const options = typeof item.options === 'function' ? item.options() : item.options;
return {

View File

@ -10,34 +10,41 @@ 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}%>`;
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';
}
break;
case '$jobsMapByNodeId':
if (options?.nodeId) {
const node = nodes.find((n) => n.id == options.nodeId);
return value;
}).join('.')}%>`;
}
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}%>`;
}
}
}
}
@ -47,7 +54,7 @@ function getVal(operand) {
const AvailableVariableTool = (props) => {
const { t } = useWorkflowTranslation();
const [operand, setOperand] = useState({ type: '$context', value: '' });
const [operand, setOperand] = useState('');
return (
<Row style={{ width: '100%' }}>
<Col span={10}>
@ -105,13 +112,10 @@ export default function (props) {
<Row>
<Col span={24}>
<div className="ant-formily-item-extra">
{props.description}
{' '}
{t('Syntax see')}{' '}
{props.description} {t('Syntax see')}{' '}
<a target={'_blank'} href={'https://ejs.co'}>
ejs
</a>
{' '}
</a>{' '}
</div>
</Col>
</Row>