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
|
||||
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 {
|
||||
|
@ -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 (
|
||||
<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>
|
||||
|
Loading…
Reference in New Issue
Block a user