From 86a23c0d9fc6584438e1678f131df4bd988f6762 Mon Sep 17 00:00:00 2001 From: Junyi Date: Wed, 30 Nov 2022 22:48:29 -0800 Subject: [PATCH] fix(plugin-workflow): fix context operand (#1169) --- packages/plugins/workflow/src/client/nodes/condition.tsx | 7 ++++--- .../plugins/workflow/src/client/triggers/collection.tsx | 2 +- .../src/server/__tests__/instructions/calculation.test.ts | 6 +++--- packages/plugins/workflow/src/server/calculators/index.ts | 5 +++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/plugins/workflow/src/client/nodes/condition.tsx b/packages/plugins/workflow/src/client/nodes/condition.tsx index 27fadb73f..026b25250 100644 --- a/packages/plugins/workflow/src/client/nodes/condition.tsx +++ b/packages/plugins/workflow/src/client/nodes/condition.tsx @@ -181,8 +181,9 @@ export default { { label: lang('Branch into "Yes" and "No"'), key: 'branch', value: { rejectOnFalse: false } } ], render(data) { - const { id, config: { rejectOnFalse } } = data; + const { t } = useTranslation(); const { nodes } = useFlowContext(); + const { id, config: { rejectOnFalse } } = data; const trueEntry = nodes.find(item => item.upstreamId === id && item.branchIndex === 1); const falseEntry = nodes.find(item => item.upstreamId === id && item.branchIndex === 0); return ( @@ -217,8 +218,8 @@ export default { } `} > - {lang('No')} - {lang('Yes')} + {t('No')} + {t('Yes')} )} diff --git a/packages/plugins/workflow/src/client/triggers/collection.tsx b/packages/plugins/workflow/src/client/triggers/collection.tsx index 9ba844bca..130993253 100644 --- a/packages/plugins/workflow/src/client/triggers/collection.tsx +++ b/packages/plugins/workflow/src/client/triggers/collection.tsx @@ -155,7 +155,7 @@ export default { collection={workflow.config.collection} value={options?.path} onChange={(path) => { - onChange({ type, options: { ...options, path } }); + onChange({ type, options: { ...options, type: 'data', path } }); }} /> ); diff --git a/packages/plugins/workflow/src/server/__tests__/instructions/calculation.test.ts b/packages/plugins/workflow/src/server/__tests__/instructions/calculation.test.ts index 2e9dcabad..09978be96 100644 --- a/packages/plugins/workflow/src/server/__tests__/instructions/calculation.test.ts +++ b/packages/plugins/workflow/src/server/__tests__/instructions/calculation.test.ts @@ -62,20 +62,20 @@ describe('workflow > instructions > calculation', () => { calculation: { calculator: 'add', operands: [ - { value: 1 }, + { type: '$context', options: { type: 'data', path: 'read' } }, { type: '$context', options: { path: 'data.read' } } ] } } }); - const post = await PostRepo.create({ values: { title: 't1' } }); + const post = await PostRepo.create({ values: { title: 't1', read: 1 } }); await sleep(500); const [execution] = await workflow.getExecutions(); const [job] = await execution.getJobs(); - expect(job.result).toBe(1); + expect(job.result).toBe(2); }); it('context by json-template', async () => { diff --git a/packages/plugins/workflow/src/server/calculators/index.ts b/packages/plugins/workflow/src/server/calculators/index.ts index cd0d65e52..da3a9ac7b 100644 --- a/packages/plugins/workflow/src/server/calculators/index.ts +++ b/packages/plugins/workflow/src/server/calculators/index.ts @@ -12,7 +12,8 @@ export default calculators; export type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation'; export type ObjectGetterOptions = { - path?: string + type?: string; + path?: string; }; export type JobGetterOptions = ObjectGetterOptions & { @@ -69,7 +70,7 @@ export function calculate(operand: Operand, lastJob: JobModel, processor: Proces // @Deprecated // from execution context case '$context': - return get(processor.execution.context, operand.options.path); + return get(processor.execution.context, [operand.options.type, operand.options.path].filter(Boolean).join('.')); // @Deprecated // from last job (or input job)