Skip to content

Commit

Permalink
perf: check invalid reference
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Nov 26, 2024
1 parent ade7da0 commit a4c7335
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const PluginOutputEditModal = ({

data.key = data?.key?.trim();
data.label = data.key;
data.required = true;

onSubmit({
data,
Expand Down
38 changes: 21 additions & 17 deletions projects/app/src/web/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ export const checkWorkflowNodeAndConnection = ({
nodes: Node<FlowNodeItemType, string | undefined>[];
edges: Edge<any>[];
}): string[] | undefined => {
const nodeIds: string[] = nodes.map((node) => node.data.nodeId);
// 1. reference check. Required value
for (const node of nodes) {
const data = node.data;
Expand Down Expand Up @@ -392,32 +391,37 @@ export const checkWorkflowNodeAndConnection = ({
}

if (input.required) {
if (Array.isArray(input.value) && input.value.length === 0) return true;
if (input.value === undefined) return true;
if (Array.isArray(input.value) && input.value.length === 0) return true;
}

// Check plugin output
// if (
// node.data.flowNodeType === FlowNodeTypeEnum.pluginOutput &&
// (input.value?.length === 0 ||
// (isValidReferenceValue(input.value, nodeIds) && !input.value?.[1]))
// ) {
// return true;
// }

// check reference invalid
const renderType = input.renderTypeList[input.selectedTypeIndex || 0];
if (renderType === FlowNodeInputTypeEnum.reference) {
// 无效引用时,返回 true
const checkValueValid = (value: ReferenceItemValueType) => {
const nodeId = value?.[0];
const outputId = value?.[1];

if (!nodeId || !outputId) return false;

return !!nodes
.find((node) => node.data.nodeId === nodeId)
?.data.outputs.find((output) => output.id === outputId);
};

if (input.valueType?.startsWith('array')) {
if (input.required && (!input.value || input.value.length === 0)) {
input.value = input.value ?? [];
// 如果内容为空,则报错
if (input.required && input.value.length === 0) {
return true;
}

return !isValidArrayReferenceValue(input.value, nodeIds);
} else {
// Single reference
if (input.required) {
return !checkValueValid(input.value);
}
}

// Single reference
return input.required && !isValidReferenceValue(input.value, nodeIds);
}
return false;
})
Expand Down

0 comments on commit a4c7335

Please sign in to comment.