From c988c3705a96a84beae88c39de807763e62d03e4 Mon Sep 17 00:00:00 2001 From: Junyi Date: Wed, 17 May 2023 16:29:18 +0700 Subject: [PATCH] fix(plugin-workflow): fix variable api caller in loop (#1877) --- .../plugins/workflow/src/client/nodes/aggregate.tsx | 2 +- .../plugins/workflow/src/client/nodes/condition.tsx | 2 +- .../plugins/workflow/src/client/nodes/index.tsx | 2 +- packages/plugins/workflow/src/client/nodes/loop.tsx | 8 ++++---- packages/plugins/workflow/src/client/variable.tsx | 13 +++++++------ 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/plugins/workflow/src/client/nodes/aggregate.tsx b/packages/plugins/workflow/src/client/nodes/aggregate.tsx index 8e794ec3f..9215e23b6 100644 --- a/packages/plugins/workflow/src/client/nodes/aggregate.tsx +++ b/packages/plugins/workflow/src/client/nodes/aggregate.tsx @@ -28,7 +28,7 @@ function AssociatedConfig({ value, onChange, ...props }): JSX.Element { const { getCollection } = useCollectionManager(); const current = useNodeContext(); const options = [nodesOptions, triggerOptions].map((item) => { - const children = item.useOptions(current, { types: [matchToManyField] })?.filter(Boolean); + const children = item.useOptions({ types: [matchToManyField] })?.filter(Boolean); return { label: compile(item.label), value: item.value, diff --git a/packages/plugins/workflow/src/client/nodes/condition.tsx b/packages/plugins/workflow/src/client/nodes/condition.tsx index 5f5901e80..58609bedd 100644 --- a/packages/plugins/workflow/src/client/nodes/condition.tsx +++ b/packages/plugins/workflow/src/client/nodes/condition.tsx @@ -411,7 +411,7 @@ export default { value: { rejectOnFalse: false }, }, ], - render(data) { + render: function Renderer(data) { const { t } = useTranslation(); const { nodes } = useFlowContext(); const { diff --git a/packages/plugins/workflow/src/client/nodes/index.tsx b/packages/plugins/workflow/src/client/nodes/index.tsx index 0f91cefe4..09c747d76 100644 --- a/packages/plugins/workflow/src/client/nodes/index.tsx +++ b/packages/plugins/workflow/src/client/nodes/index.tsx @@ -49,7 +49,7 @@ export interface Instruction { view?: ISchema; scope?: { [key: string]: any }; components?: { [key: string]: any }; - render?(props): React.ReactNode; + render?(props): JSX.Element; endding?: boolean; useVariables?(node, options?): VariableOptions; useScopeVariables?(node, options?): VariableOptions; diff --git a/packages/plugins/workflow/src/client/nodes/loop.tsx b/packages/plugins/workflow/src/client/nodes/loop.tsx index bbda35339..512d08ada 100644 --- a/packages/plugins/workflow/src/client/nodes/loop.tsx +++ b/packages/plugins/workflow/src/client/nodes/loop.tsx @@ -116,7 +116,7 @@ export default { useWorkflowVariableOptions, }, components: {}, - useScopeVariables(node, types) { + useScopeVariables(node, options) { const compile = useCompile(); const { target } = node.config; if (!target) { @@ -137,8 +137,8 @@ export default { .split('.') .map((path) => path.trim()); - const options = [nodesOptions, triggerOptions].map((item: any) => { - const opts = typeof item.useOptions === 'function' ? item.useOptions(node, { types }).filter(Boolean) : null; + const targetOptions = [nodesOptions, triggerOptions].map((item: any) => { + const opts = typeof item.useOptions === 'function' ? item.useOptions(options).filter(Boolean) : null; return { label: compile(item.title), value: item.value, @@ -148,7 +148,7 @@ export default { }; }); - targetOption.children = findOption(options, paths); + targetOption.children = findOption(targetOptions, paths); } return [ diff --git a/packages/plugins/workflow/src/client/variable.tsx b/packages/plugins/workflow/src/client/variable.tsx index 7b266c796..a57459441 100644 --- a/packages/plugins/workflow/src/client/variable.tsx +++ b/packages/plugins/workflow/src/client/variable.tsx @@ -16,7 +16,8 @@ export type VariableOptions = VariableOption[] | null; export const nodesOptions = { label: `{{t("Node result", { ns: "${NAMESPACE}" })}}`, value: '$jobsMapByNodeId', - useOptions(current, options) { + useOptions(options) { + const current = useNodeContext(); const upstreams = useAvailableUpstreams(current); const result: VariableOption[] = []; upstreams.forEach((node) => { @@ -38,7 +39,7 @@ export const nodesOptions = { export const triggerOptions = { label: `{{t("Trigger variables", { ns: "${NAMESPACE}" })}}`, value: '$context', - useOptions(current, options) { + useOptions(options) { const { workflow } = useFlowContext(); const trigger = triggers.get(workflow.type); return trigger?.useVariables?.(workflow.config, options) ?? null; @@ -48,7 +49,8 @@ export const triggerOptions = { export const scopeOptions = { label: `{{t("Scope variables", { ns: "${NAMESPACE}" })}}`, value: '$scopes', - useOptions(current, options) { + useOptions(options) { + const current = useNodeContext(); const scopes = useUpstreamScopes(current); const result: VariableOption[] = []; scopes.forEach((node) => { @@ -70,7 +72,7 @@ export const scopeOptions = { export const systemOptions = { label: `{{t("System variables", { ns: "${NAMESPACE}" })}}`, value: '$system', - useOptions(current, { types }) { + useOptions({ types }) { return [ ...(!types || types.includes('date') ? [ @@ -158,9 +160,8 @@ export function filterTypedFields(fields, types, depth = 1) { export function useWorkflowVariableOptions(options = {}) { const compile = useCompile(); - const current = useNodeContext(); const result = [scopeOptions, nodesOptions, triggerOptions, systemOptions].map((item: any) => { - const opts = typeof item.useOptions === 'function' ? item.useOptions(current, options).filter(Boolean) : null; + const opts = typeof item.useOptions === 'function' ? item.useOptions(options).filter(Boolean) : null; return { label: compile(item.label), value: item.value,