From 9b4139e28aa234ef440576aecace1d1f588d6652 Mon Sep 17 00:00:00 2001 From: lyf-coder <58352715+lyf-coder@users.noreply.github.com> Date: Wed, 23 Nov 2022 18:29:18 +0800 Subject: [PATCH] feat(workflow): support Http Request Node (#1102) * feat(workflow): support Http Request Node * style(workflow): hTTP Request ui title * style(workflow): request node ui title fix * feat(workflow): support timeout config,ignoreFail etc * refactor(workflow): request node Instruction remove unused input.result from templateVars * fix(workflow): fix locale * fix(workflow): perfect request implementation --- packages/plugins/workflow/package.json | 5 +- .../src/client/components/EjsTextArea.tsx | 121 +++++++++ .../workflow/src/client/locale/en-US.ts | 18 ++ .../workflow/src/client/locale/zh-CN.ts | 18 ++ .../workflow/src/client/nodes/index.tsx | 2 + .../workflow/src/client/nodes/request.tsx | 142 ++++++++++ .../__tests__/instructions/request.test.ts | 247 ++++++++++++++++++ .../workflow/src/server/instructions/index.ts | 3 +- .../src/server/instructions/request.ts | 95 +++++++ yarn.lock | 60 ++++- 10 files changed, 708 insertions(+), 3 deletions(-) create mode 100644 packages/plugins/workflow/src/client/components/EjsTextArea.tsx create mode 100644 packages/plugins/workflow/src/client/nodes/request.tsx create mode 100644 packages/plugins/workflow/src/server/__tests__/instructions/request.test.ts create mode 100644 packages/plugins/workflow/src/server/instructions/request.ts 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', + }, + }); + }} + > + +