show error when node data is invalid

This commit is contained in:
codetypes committed 2024-04-18 00:37:40 +08:00
1 parent 0e6aff2855
commit 7ceaf45971
9 files changed
+68 -20

No files matched your search

-1
View File
@@ -13,7 +13,6 @@ dist-ssr
dist-electron
release
*.local
build
settings.json
# Editor directories and files
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 100 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

-3
View File
@@ -32,9 +32,6 @@ if (!app.requestSingleInstanceLock()) {
process.exit(0);
}
app.commandLine.appendArgument("–-allow-file-access-from-files");
app.commandLine.appendArgument("--disable-web-security");
// Remove electron security warnings
// This warning only shows in development mode
// Read more on https://www.electronjs.org/docs/latest/tutorial/security
+8 -7
View File
@@ -2,17 +2,15 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="none" x="0px" y="0px" width="128px" height="128px" viewBox="0 0 128 128">
<defs>
<g id="Layer1_0_FILL">
<path fill="#2F3242" stroke="none" d="
<path fill="#2C2E3A" stroke="none" d="
M 128 64
Q 128 37.55 109.25 18.75 90.5 0 64 0 37.5 0 18.75 18.75 0 37.5 0 64 0 90.5 18.75 109.25 37.5 128 64 128 90.5 128 109.25 109.25 128 90.5 128 64 Z"/>
</g>
<g id="Layer0_0_FILL">
<path fill="#A2ECFB" stroke="none" d="
M 21.05 10.95
Q 21.7 10.95 22.2 10.5 22.65 10.05 22.65 9.4
L 22.65 4.7
Q 22.65 4.05 22.2 3.6 21.7 3.15 21.05 3.15
<path fill="#CFF7FF" stroke="none" d="
M 22.2 3.6
Q 21.7 3.15 21.05 3.15
L 16.4 3.15
Q 15.75 3.15 15.25 3.6 14.8 4.05 14.8 4.7
L 14.8 6.25 14.05 6.25
@@ -41,7 +39,10 @@ L 12.5 9.4
Q 12.5 8.75 12.95 8.3 13.4 7.85 14.05 7.85
L 14.8 7.85 14.8 9.4
Q 14.8 10.05 15.25 10.5 15.75 10.95 16.4 10.95
L 21.05 10.95 Z"/>
L 21.05 10.95
Q 21.7 10.95 22.2 10.5 22.65 10.05 22.65 9.4
L 22.65 4.7
Q 22.65 4.05 22.2 3.6 Z"/>
</g>
</defs>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

+8 -7
View File
@@ -2,17 +2,15 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="none" x="0px" y="0px" width="128px" height="128px" viewBox="0 0 128 128">
<defs>
<g id="Layer1_0_FILL">
<path fill="#2F3242" stroke="none" d="
<path fill="#2C2E3A" stroke="none" d="
M 128 64
Q 128 37.55 109.25 18.75 90.5 0 64 0 37.5 0 18.75 18.75 0 37.5 0 64 0 90.5 18.75 109.25 37.5 128 64 128 90.5 128 109.25 109.25 128 90.5 128 64 Z"/>
</g>
<g id="Layer0_0_FILL">
<path fill="#A2ECFB" stroke="none" d="
M 21.05 10.95
Q 21.7 10.95 22.2 10.5 22.65 10.05 22.65 9.4
L 22.65 4.7
Q 22.65 4.05 22.2 3.6 21.7 3.15 21.05 3.15
<path fill="#CFF7FF" stroke="none" d="
M 22.2 3.6
Q 21.7 3.15 21.05 3.15
L 16.4 3.15
Q 15.75 3.15 15.25 3.6 14.8 4.05 14.8 4.7
L 14.8 6.25 14.05 6.25
@@ -41,7 +39,10 @@ L 12.5 9.4
Q 12.5 8.75 12.95 8.3 13.4 7.85 14.05 7.85
L 14.8 7.85 14.8 9.4
Q 14.8 10.05 15.25 10.5 15.75 10.95 16.4 10.95
L 21.05 10.95 Z"/>
L 21.05 10.95
Q 21.7 10.95 22.2 10.5 22.65 10.05 22.65 9.4
L 22.65 4.7
Q 22.65 4.05 22.2 3.6 Z"/>
</g>
</defs>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

+4 -2
View File
@@ -1,5 +1,6 @@
import { useWorkspace } from "@/contexts/workspace-context";
import { toBreakWord } from "@/misc/b3util";
import { TreeGraphData } from "@/misc/b3type";
import { checkTreeData, toBreakWord } from "@/misc/b3util";
import i18n from "@/misc/i18n";
import G6 from "@antv/g6";
@@ -76,7 +77,8 @@ G6.registerNode(
let color = nodeDef.color || NODE_COLORS[classify] || NODE_COLORS["Other"];
if (
!workspace.hasNodeDef(cfg.name as string) ||
(cfg.path && (!cfg.children || (cfg.children as []).length == 0))
(cfg.path && (!cfg.children || (cfg.children as []).length == 0)) ||
!checkTreeData(cfg as TreeGraphData)
) {
classify = "Error";
color = NODE_COLORS[classify];
+48
View File
@@ -147,6 +147,54 @@ export const calcTreeDataSize = (data: TreeGraphData) => {
return [200, height];
};
export const checkTreeData = (data: TreeGraphData) => {
const conf = data.def;
if (conf.input) {
for (let i = 0; i < conf.input.length; i++) {
if (conf.input[i].indexOf("?") === -1 && !data.input?.[i]) {
return false;
}
}
}
if (conf.output) {
for (let i = 0; i < conf.output.length; i++) {
if (conf.output[i].indexOf("?") === -1 && !data.output?.[i]) {
return false;
}
}
}
if (conf.args) {
for (let i = 0; i < conf.args.length; i++) {
const arg = conf.args[i];
if (arg.type.indexOf("?") === -1) {
const value = data.args?.[arg.name];
if (arg.type === "float") {
if (typeof value !== "number") {
return false;
}
} else if (arg.type === "int") {
if (typeof value !== "number" || value !== Math.floor(value)) {
return false;
}
} else if (arg.type === "string") {
if (!value || typeof value !== "string") {
return false;
}
} else if (arg.type === "enum") {
if (!arg.options?.find((option) => option.value === value)) {
return false;
}
} else if (arg.type == "code") {
if (!value || typeof value !== "string") {
return false;
}
}
}
}
}
return true;
};
export const createTreeData = (node: NodeModel, parent?: string) => {
const workspace = useWorkspace.getState();
let treeData: TreeGraphData = {