fix(workflow/request-var): fix request node var editor (#1223)
This commit is contained in:
parent
0ddd73cf3b
commit
f4ee872a16
@ -386,7 +386,7 @@ export function Operand({
|
|||||||
`}>
|
`}>
|
||||||
<Cascader
|
<Cascader
|
||||||
allowClear={false}
|
allowClear={false}
|
||||||
value={[type, ...(appendTypeValue ? appendTypeValue(operand) : [])]}
|
value={[Types[type] ? type : '', ...(appendTypeValue ? appendTypeValue(operand) : [])]}
|
||||||
options={Object.values(Types).map((item: any) => {
|
options={Object.values(Types).map((item: any) => {
|
||||||
const options = typeof item.options === 'function' ? item.options() : item.options;
|
const options = typeof item.options === 'function' ? item.options() : item.options;
|
||||||
return {
|
return {
|
||||||
|
@ -3,51 +3,58 @@ import { Row, Col } from 'antd';
|
|||||||
import { CopyOutlined, ToolOutlined } from '@ant-design/icons';
|
import { CopyOutlined, ToolOutlined } from '@ant-design/icons';
|
||||||
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
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 { Button, Input, message, Tooltip } from 'antd';
|
||||||
import { useFlowContext } from '../FlowContext';
|
import { useFlowContext } from '../FlowContext';
|
||||||
import { useCollectionManager, useCompile } from '@nocobase/client';
|
import { useCollectionManager, useCompile } from '@nocobase/client';
|
||||||
import { useWorkflowTranslation } from '../locale';
|
import {useWorkflowTranslation} from '../locale';
|
||||||
|
|
||||||
function getVal(operand) {
|
function getVal(operand) {
|
||||||
const { options } = operand;
|
|
||||||
const { t } = useWorkflowTranslation();
|
const { t } = useWorkflowTranslation();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const { getCollectionFields } = useCollectionManager();
|
const { getCollectionFields } = useCollectionManager();
|
||||||
const { nodes } = useFlowContext();
|
const { nodes } = useFlowContext();
|
||||||
|
|
||||||
switch (operand.type) {
|
if (typeof operand === 'string') {
|
||||||
case '$context':
|
let pathArr = operand.replace('{{', '').replace('}}', '').split('.');
|
||||||
if (options?.path) {
|
if (pathArr.length > 0) {
|
||||||
return `<%=ctx.${options.path}%>`;
|
const type = pathArr[0];
|
||||||
|
if (type == '$context') {
|
||||||
|
return `<%=${pathArr.map((value, index) => {
|
||||||
|
if (index === 0) {
|
||||||
|
return 'ctx';
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}).join('.')}%>`;
|
||||||
}
|
}
|
||||||
break;
|
if (pathArr.length>1 && type == '$jobsMapByNodeId') {
|
||||||
case '$jobsMapByNodeId':
|
const nodeId = pathArr[1]
|
||||||
if (options?.nodeId) {
|
const node = nodes.find((n) => n.id == nodeId);
|
||||||
const node = nodes.find((n) => n.id == options.nodeId);
|
|
||||||
if (node) {
|
if (node) {
|
||||||
if (node.type === 'calculation') {
|
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 fields = getCollectionFields(node?.config?.collection);
|
||||||
const field = fields.find((f) => f.name == options.path);
|
const field = fields.find((f) => f.name == fieldName);
|
||||||
if (field) {
|
if (field) {
|
||||||
return `<%= node[${options.nodeId}].${options.path} // ${compile(
|
return `<%= node[${nodeId}].${fieldName} // ${compile(
|
||||||
field.uiSchema?.title || field.name,
|
field.uiSchema?.title || field.name,
|
||||||
)} %>`;
|
)} %>`;
|
||||||
}
|
}
|
||||||
return `<%= node[${options.nodeId}].${options.path}%>`;
|
return `<%= node[${nodeId}].${fieldName}%>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const AvailableVariableTool = (props) => {
|
const AvailableVariableTool = (props) => {
|
||||||
const { t } = useWorkflowTranslation();
|
const { t } = useWorkflowTranslation();
|
||||||
const [operand, setOperand] = useState({ type: '$context', value: '' });
|
const [operand, setOperand] = useState('');
|
||||||
return (
|
return (
|
||||||
<Row style={{ width: '100%' }}>
|
<Row style={{ width: '100%' }}>
|
||||||
<Col span={10}>
|
<Col span={10}>
|
||||||
@ -105,13 +112,10 @@ export default function (props) {
|
|||||||
<Row>
|
<Row>
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
<div className="ant-formily-item-extra">
|
<div className="ant-formily-item-extra">
|
||||||
{props.description}
|
{props.description} {t('Syntax see')}{' '}
|
||||||
{' '}
|
|
||||||
{t('Syntax see')}{' '}
|
|
||||||
<a target={'_blank'} href={'https://ejs.co'}>
|
<a target={'_blank'} href={'https://ejs.co'}>
|
||||||
ejs
|
ejs
|
||||||
</a>
|
</a>{' '}
|
||||||
{' '}
|
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
Loading…
Reference in New Issue
Block a user