From 2df0e463181cde5c743e23004a8c5bf0a900f3be Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 13 May 2022 13:26:49 +0800 Subject: [PATCH] Fix(plugin workflow): fix cannot get job result properties (#382) * fix(plugin-workflow): card drawer title * fix(plugin-workflow): fix job result to use raw object than proxied model (#380) --- .../core/client/src/workflow/nodes/index.tsx | 5 ++- .../client/src/workflow/triggers/index.tsx | 3 +- .../src/__tests__/instructions/update.test.ts | 40 ++++++++++++++++++- .../workflow/src/collections/flow_nodes.ts | 11 +---- .../workflow/src/instructions/create.ts | 3 +- .../workflow/src/instructions/query.ts | 4 ++ .../workflow/src/instructions/update.ts | 3 +- 7 files changed, 54 insertions(+), 15 deletions(-) diff --git a/packages/core/client/src/workflow/nodes/index.tsx b/packages/core/client/src/workflow/nodes/index.tsx index 257a70952a..c5ab2a534f 100644 --- a/packages/core/client/src/workflow/nodes/index.tsx +++ b/packages/core/client/src/workflow/nodes/index.tsx @@ -165,13 +165,14 @@ export function NodeDefaultView(props) { const { data, children } = props; const instruction = instructions.get(data.type); const detailText = workflow.executed ? '{{t("View")}}' : '{{t("Configure")}}'; + const typeText = compile(instruction.title); return (
- {compile(instruction.title)} + {typeText}

{data.title} @@ -196,7 +197,7 @@ export function NodeDefaultView(props) { properties: { drawer: { type: 'void', - title: detailText, + title: typeText, 'x-component': 'Action.Drawer', 'x-decorator': 'Form', 'x-decorator-props': { diff --git a/packages/core/client/src/workflow/triggers/index.tsx b/packages/core/client/src/workflow/triggers/index.tsx index 66c7db30ff..c722a9e683 100644 --- a/packages/core/client/src/workflow/triggers/index.tsx +++ b/packages/core/client/src/workflow/triggers/index.tsx @@ -61,6 +61,7 @@ export const TriggerConfig = () => { const { type, config, executed } = data.data; const { title, fieldset, scope, components } = triggers.get(type); const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}'; + const titleText = `${t('Trigger')}: ${compile(title)}`; return (
@@ -77,7 +78,7 @@ export const TriggerConfig = () => { properties: { drawer: { type: 'void', - title: detailText, + title: titleText, 'x-component': 'Action.Drawer', 'x-decorator': 'Form', 'x-decorator-props': { diff --git a/packages/plugins/workflow/src/__tests__/instructions/update.test.ts b/packages/plugins/workflow/src/__tests__/instructions/update.test.ts index d70cb06a92..b66a357c41 100644 --- a/packages/plugins/workflow/src/__tests__/instructions/update.test.ts +++ b/packages/plugins/workflow/src/__tests__/instructions/update.test.ts @@ -33,7 +33,7 @@ describe('workflow > instructions > update', () => { describe('update one', () => { it('params: from context', async () => { - const n2 = await workflow.createNode({ + const n1 = await workflow.createNode({ type: 'update', config: { collection: 'posts', @@ -59,4 +59,42 @@ describe('workflow > instructions > update', () => { expect(updatedPost.published).toBe(true); }); }); + + it('params: from job of node', async () => { + const n1 = await workflow.createNode({ + type: 'query', + config: { + collection: 'posts', + params: { + filter: { + title: 'test' + } + } + } + }); + + const n2 = await workflow.createNode({ + type: 'update', + config: { + collection: 'posts', + params: { + filter: { + id: `{{$jobsMapByNodeId.${n1.id}.id}}` + }, + values: { + title: 'changed' + } + } + }, + upstreamId: n1.id + }); + + await n1.setDownstream(n2); + + // NOTE: the result of post immediately created will not be changed by workflow + const { id } = await PostModel.create({ title: 'test' }); + // should get from db + const post = await PostModel.findByPk(id); + expect(post.title).toBe('changed'); + }); }); diff --git a/packages/plugins/workflow/src/collections/flow_nodes.ts b/packages/plugins/workflow/src/collections/flow_nodes.ts index 77422a2158..75c7151a6a 100644 --- a/packages/plugins/workflow/src/collections/flow_nodes.ts +++ b/packages/plugins/workflow/src/collections/flow_nodes.ts @@ -40,7 +40,7 @@ export default { type: 'integer', title: 'branch index' }, - // for reasons: + // Note: for reasons: // 1. redirect type node to solve cycle flow. // 2. recognize as real next node after branches. { @@ -53,14 +53,7 @@ export default { interface: 'select', type: 'string', name: 'type', - title: '类型', - // TODO: data for test only now - dataSource: [ - { label: '数据处理', value: 'data' }, - { label: '数据查询', value: 'query' }, - { label: '等待人工输入', value: 'prompt' }, - { label: '条件判断', value: 'condition' }, - ] + title: '类型' }, { interface: 'json', diff --git a/packages/plugins/workflow/src/instructions/create.ts b/packages/plugins/workflow/src/instructions/create.ts index 8757ba774a..93eb777546 100644 --- a/packages/plugins/workflow/src/instructions/create.ts +++ b/packages/plugins/workflow/src/instructions/create.ts @@ -16,7 +16,8 @@ export default { }); return { - result, + // NOTE: get() for non-proxied instance (#380) + result: result.get(), status: JOB_STATUS.RESOLVED }; } diff --git a/packages/plugins/workflow/src/instructions/query.ts b/packages/plugins/workflow/src/instructions/query.ts index 717422a641..d0a6339255 100644 --- a/packages/plugins/workflow/src/instructions/query.ts +++ b/packages/plugins/workflow/src/instructions/query.ts @@ -13,6 +13,10 @@ export default { const options = execution.getParsedValue(params); const result = await (multiple ? repo.find : repo.findOne).call(repo, { ...options, + // NOTE: `raw` to avoid getting undefined value from Proxied model instance (#380) + // e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false + // so the properties can not be get by json-templates(object-path) + raw: true, transaction: execution.tx }); diff --git a/packages/plugins/workflow/src/instructions/update.ts b/packages/plugins/workflow/src/instructions/update.ts index ccc6438c8b..d49faa7c40 100644 --- a/packages/plugins/workflow/src/instructions/update.ts +++ b/packages/plugins/workflow/src/instructions/update.ts @@ -1,8 +1,9 @@ import { JOB_STATUS } from "../constants"; +import ExecutionModel from "../models/Execution"; import FlowNodeModel from "../models/FlowNode"; export default { - async run(this: FlowNodeModel, input, execution) { + async run(this: FlowNodeModel, input, execution: ExecutionModel) { const { collection, multiple = false,