feat(plugin-workflow): add array mapping support in processor (#1662)

This commit is contained in:
Junyi 2023-04-07 15:08:25 +07:00 committed by GitHub
parent 3ec8b2d45f
commit 0d0c5ff9e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -6,7 +6,7 @@ import formulajs from "../utils/formulajs";
export { Evaluator } from '../utils';
export { Evaluator, evaluate, appendArrayColumn } from '../utils';
export const evaluators = new Registry<Evaluator>();

View File

@ -6,7 +6,7 @@ export type Scope = { [key: string]: any };
export type Evaluator = (expression: string, scope?: Scope) => any;
function appendArrayColumn(scope, key) {
export function appendArrayColumn(scope, key) {
const paths = key.split('.');
let data = scope;
for (let p = 0; p < paths.length && data != null; p++) {

View File

@ -2,6 +2,7 @@ import { Transaction, Transactionable } from 'sequelize';
import parse from 'json-templates';
import { Model } from "@nocobase/database";
import { appendArrayColumn } from '@nocobase/evaluators';
import Plugin from '.';
import ExecutionModel from './models/Execution';
@ -296,6 +297,11 @@ export default class Processor {
}
public getParsedValue(value, node?) {
return parse(value)(this.getScope(node));
const template = parse(value);
const scope = this.getScope(node);
template.parameters.forEach(({ key }) => {
appendArrayColumn(scope, key);
});
return template(scope);
}
}