optimize check children count
This commit is contained in:
1 parent
e4f0686f2f
commit
bd64c785b0
1 file changed
+8
-12
+8
-12
@@ -73,13 +73,13 @@ export const checkNodeData = (data: NodeModel | null | undefined) => {
|
|||||||
}
|
}
|
||||||
let hasError = false;
|
let hasError = false;
|
||||||
const conf = useWorkspace.getState().getNodeDef(data.name);
|
const conf = useWorkspace.getState().getNodeDef(data.name);
|
||||||
if (conf.children !== undefined) {
|
if (conf.children !== undefined && conf.children != -1) {
|
||||||
if (conf.children == 0 && data.children?.length) {
|
const count = data.children?.length || 0;
|
||||||
|
if (conf.children !== count) {
|
||||||
hasError = true;
|
hasError = true;
|
||||||
console.error(`check ${data.id}|${data.name}: no children is required`);
|
console.error(
|
||||||
} else if (conf.children == 1 && data.children?.length !== 1) {
|
`check ${data.id}|${data.name}: expect ${conf.children} children, but got ${count}`
|
||||||
hasError = true;
|
);
|
||||||
console.error(`check ${data.id}|${data.name}: only one child is required`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (conf.input) {
|
if (conf.input) {
|
||||||
@@ -341,12 +341,8 @@ export const calcTreeDataSize = (data: TreeGraphData) => {
|
|||||||
|
|
||||||
export const checkChildrenLimit = (data: TreeGraphData) => {
|
export const checkChildrenLimit = (data: TreeGraphData) => {
|
||||||
const conf = data.def;
|
const conf = data.def;
|
||||||
if (conf.children !== undefined) {
|
if (conf.children !== undefined && conf.children != -1) {
|
||||||
if (conf.children == 0 && data.children?.length) {
|
return (data.children?.length || 0) === conf.children;
|
||||||
return false;
|
|
||||||
} else if (conf.children == 1 && data.children?.length !== 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user