fix(plugin-workflow): fix loop scope variable (#2989)

This commit is contained in:
Junyi 2023-11-07 22:17:07 +08:00 committed by GitHub
parent 3802ca38f8
commit 30de7865c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -8,7 +8,14 @@ import { Branch } from '../Branch';
import { useFlowContext } from '../FlowContext';
import { NAMESPACE, lang } from '../locale';
import useStyles from '../style';
import { VariableOption, WorkflowVariableInput, defaultFieldNames, nodesOptions, triggerOptions } from '../variable';
import {
VariableOption,
WorkflowVariableInput,
defaultFieldNames,
nodesOptions,
scopeOptions,
triggerOptions,
} from '../variable';
function findOption(options: VariableOption[], paths: string[]) {
let opts = options;
@ -121,8 +128,8 @@ export default {
.split('.')
.map((path) => path.trim());
const targetOptions = [nodesOptions, triggerOptions].map((item: any) => {
const opts = item.useOptions(options).filter(Boolean);
const targetOptions = [scopeOptions, nodesOptions, triggerOptions].map((item: any) => {
const opts = item.useOptions({ ...options, current: node }).filter(Boolean);
return {
[fieldNames.label]: compile(item.label),
[fieldNames.value]: item.value,

View File

@ -34,6 +34,7 @@ export type OptionsOfUseVariableOptions = {
};
appends?: string[] | null;
depth?: number;
current?: any;
};
export const defaultFieldNames = { label: 'label', value: 'value', children: 'children' } as const;
@ -70,9 +71,10 @@ export const scopeOptions = {
label: `{{t("Scope variables", { ns: "${NAMESPACE}" })}}`,
value: '$scopes',
useOptions(options: OptionsOfUseVariableOptions) {
const { fieldNames = defaultFieldNames } = options;
const current = useNodeContext();
const scopes = useUpstreamScopes(current);
const { fieldNames = defaultFieldNames, current } = options;
const source = useNodeContext();
const from = current ?? source;
const scopes = useUpstreamScopes(from);
const result: VariableOption[] = [];
scopes.forEach((node) => {
const instruction = instructions.get(node.type);