support check children limit
This commit is contained in:
1 parent
b4021e487c
commit
e4f0686f2f
7 files changed
+84
-47
No files matched your search
@@ -32,6 +32,7 @@ export interface NodeDef {
|
||||
`${Status}` | `!${Status}` | `|${Status}` | `&${Status}`,
|
||||
"!running" | "&running"
|
||||
>[];
|
||||
children?: -1 | 0 | 1;
|
||||
}
|
||||
|
||||
export interface NodeModel {
|
||||
|
||||
@@ -73,6 +73,15 @@ export const checkNodeData = (data: NodeModel | null | undefined) => {
|
||||
}
|
||||
let hasError = false;
|
||||
const conf = useWorkspace.getState().getNodeDef(data.name);
|
||||
if (conf.children !== undefined) {
|
||||
if (conf.children == 0 && data.children?.length) {
|
||||
hasError = true;
|
||||
console.error(`check ${data.id}|${data.name}: no children is required`);
|
||||
} else if (conf.children == 1 && data.children?.length !== 1) {
|
||||
hasError = true;
|
||||
console.error(`check ${data.id}|${data.name}: only one child is required`);
|
||||
}
|
||||
}
|
||||
if (conf.input) {
|
||||
for (let i = 0; i < conf.input.length; i++) {
|
||||
if (!data.input) {
|
||||
@@ -330,6 +339,18 @@ export const calcTreeDataSize = (data: TreeGraphData) => {
|
||||
return [220, height];
|
||||
};
|
||||
|
||||
export const checkChildrenLimit = (data: TreeGraphData) => {
|
||||
const conf = data.def;
|
||||
if (conf.children !== undefined) {
|
||||
if (conf.children == 0 && data.children?.length) {
|
||||
return false;
|
||||
} else if (conf.children == 1 && data.children?.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
export const checkTreeData = (data: TreeGraphData) => {
|
||||
const conf = data.def;
|
||||
if (conf.input) {
|
||||
@@ -346,6 +367,9 @@ export const checkTreeData = (data: TreeGraphData) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!checkChildrenLimit(data)) {
|
||||
return false;
|
||||
}
|
||||
if (conf.args) {
|
||||
for (let i = 0; i < conf.args.length; i++) {
|
||||
const arg = conf.args[i];
|
||||
|
||||
Reference in new issue
Block a user