fix(plugin-workflow): fix context operand (#1169)

This commit is contained in:
Junyi 2022-11-30 22:48:29 -08:00 committed by GitHub
parent 22f1b9b541
commit 86a23c0d9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 9 deletions

View File

@ -181,8 +181,9 @@ export default {
{ label: lang('Branch into "Yes" and "No"'), key: 'branch', value: { rejectOnFalse: false } } { label: lang('Branch into "Yes" and "No"'), key: 'branch', value: { rejectOnFalse: false } }
], ],
render(data) { render(data) {
const { id, config: { rejectOnFalse } } = data; const { t } = useTranslation();
const { nodes } = useFlowContext(); const { nodes } = useFlowContext();
const { id, config: { rejectOnFalse } } = data;
const trueEntry = nodes.find(item => item.upstreamId === id && item.branchIndex === 1); const trueEntry = nodes.find(item => item.upstreamId === id && item.branchIndex === 1);
const falseEntry = nodes.find(item => item.upstreamId === id && item.branchIndex === 0); const falseEntry = nodes.find(item => item.upstreamId === id && item.branchIndex === 0);
return ( return (
@ -217,8 +218,8 @@ export default {
} }
`} `}
> >
<span className={css`right: 4em;`}>{lang('No')}</span> <span className={css`right: 4em;`}>{t('No')}</span>
<span className={css`left: 4em;`}>{lang('Yes')}</span> <span className={css`left: 4em;`}>{t('Yes')}</span>
</div> </div>
</div> </div>
)} )}

View File

@ -155,7 +155,7 @@ export default {
collection={workflow.config.collection} collection={workflow.config.collection}
value={options?.path} value={options?.path}
onChange={(path) => { onChange={(path) => {
onChange({ type, options: { ...options, path } }); onChange({ type, options: { ...options, type: 'data', path } });
}} }}
/> />
); );

View File

@ -62,20 +62,20 @@ describe('workflow > instructions > calculation', () => {
calculation: { calculation: {
calculator: 'add', calculator: 'add',
operands: [ operands: [
{ value: 1 }, { type: '$context', options: { type: 'data', path: 'read' } },
{ type: '$context', options: { path: 'data.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); await sleep(500);
const [execution] = await workflow.getExecutions(); const [execution] = await workflow.getExecutions();
const [job] = await execution.getJobs(); const [job] = await execution.getJobs();
expect(job.result).toBe(1); expect(job.result).toBe(2);
}); });
it('context by json-template', async () => { it('context by json-template', async () => {

View File

@ -12,7 +12,8 @@ export default calculators;
export type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation'; export type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';
export type ObjectGetterOptions = { export type ObjectGetterOptions = {
path?: string type?: string;
path?: string;
}; };
export type JobGetterOptions = ObjectGetterOptions & { export type JobGetterOptions = ObjectGetterOptions & {
@ -69,7 +70,7 @@ export function calculate(operand: Operand, lastJob: JobModel, processor: Proces
// @Deprecated // @Deprecated
// from execution context // from execution context
case '$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 // @Deprecated
// from last job (or input job) // from last job (or input job)