merge check NodeData and TreeGraphData
This commit is contained in:
1 parent
6d6fdf8c07
commit
54c0ff7356
5 files changed
+111
-124
No files matched your search
@@ -9,6 +9,7 @@
|
||||
"buildFailed": "Build failed, more information can be found in the console.",
|
||||
"cancel": "Cancel",
|
||||
"copy": "Copy",
|
||||
"console": "Console",
|
||||
"cut": "Cut",
|
||||
"createProject": "Create Project",
|
||||
"delete": "Delete",
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"buildFailed": "构建出现错误,详情请查看控制台!",
|
||||
"cancel": "取消",
|
||||
"copy": "复制",
|
||||
"console": "控制台",
|
||||
"cut": "替换",
|
||||
"createProject": "新建项目",
|
||||
"delete": "删除",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { EditNode, EditTree, useWorkspace } from "@/contexts/workspace-context";
|
||||
import { NodeArg, NodeArgType, NodeModel, TreeGraphData } from "@/misc/b3type";
|
||||
import { checkOneof } from "@/misc/b3util";
|
||||
import { Hotkey, isMacos } from "@/misc/keys";
|
||||
import { EditOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
@@ -337,12 +338,7 @@ const NodeInspector: FC = () => {
|
||||
const arg = def.args?.find((a) => a.oneof && v.startsWith(a.oneof));
|
||||
if (arg) {
|
||||
const argName = `args.${arg.name}`;
|
||||
const argValue = getFieldValue(argName) ?? "";
|
||||
value = value ?? "";
|
||||
if (
|
||||
(value === "" && argValue === "") ||
|
||||
(value !== "" && argValue !== "")
|
||||
) {
|
||||
if (!checkOneof(getFieldValue(argName), value)) {
|
||||
if (!isFieldValidating(argName)) {
|
||||
setFieldValue(`input.${i}`, value);
|
||||
validateFields([argName]);
|
||||
@@ -420,12 +416,7 @@ const NodeInspector: FC = () => {
|
||||
);
|
||||
}
|
||||
const inputName = `input.${idx}`;
|
||||
const inputValue = getFieldValue(inputName) ?? "";
|
||||
value = value ?? "";
|
||||
if (
|
||||
(value === "" && inputValue === "") ||
|
||||
(value !== "" && inputValue !== "")
|
||||
) {
|
||||
if (!checkOneof(getFieldValue(inputName), value)) {
|
||||
if (!isFieldValidating(inputName)) {
|
||||
setFieldValue(`args.${v.name}`, value);
|
||||
validateFields([inputName]);
|
||||
|
||||
+15
-8
@@ -214,22 +214,22 @@ export const Menu: FC<LayoutProps> = () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'menu.edit.cut',
|
||||
label: t('cut'),
|
||||
id: "menu.edit.cut",
|
||||
label: t("cut"),
|
||||
enabled: enabled,
|
||||
accelerator: Hotkey.Cut,
|
||||
click: () => {
|
||||
getFocusedWebContents()?.cut()
|
||||
}
|
||||
getFocusedWebContents()?.cut();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'menu.edit.selectAll',
|
||||
label: t('selectAll'),
|
||||
id: "menu.edit.selectAll",
|
||||
label: t("selectAll"),
|
||||
enabled: enabled,
|
||||
accelerator: Hotkey.SelectAll,
|
||||
click: () => {
|
||||
getFocusedWebContents()?.selectAll()
|
||||
}
|
||||
getFocusedWebContents()?.selectAll();
|
||||
},
|
||||
},
|
||||
{ type: "separator" },
|
||||
{
|
||||
@@ -273,6 +273,13 @@ export const Menu: FC<LayoutProps> = () => {
|
||||
getFocusedWebContents()?.openDevTools();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "menu.view.console",
|
||||
label: t("console"),
|
||||
click: () => {
|
||||
getFocusedWebContents()?.openDevTools();
|
||||
},
|
||||
},
|
||||
{ type: "separator" },
|
||||
{
|
||||
id: "menu.view.actualSize",
|
||||
|
||||
+91
-104
@@ -1,5 +1,5 @@
|
||||
import { useWorkspace } from "@/contexts/workspace-context";
|
||||
import { NodeArg, NodeArgType, NodeModel, TreeGraphData, TreeModel } from "@/misc/b3type";
|
||||
import { NodeArg, NodeArgType, NodeDef, NodeModel, TreeGraphData, TreeModel } from "@/misc/b3type";
|
||||
import * as fs from "fs";
|
||||
import { message } from "./hooks";
|
||||
import Path from "./path";
|
||||
@@ -67,10 +67,97 @@ export const isNodeEqual = (node1: NodeModel, node2: NodeModel) => {
|
||||
return false;
|
||||
};
|
||||
|
||||
const error = (data: NodeModel, msg: string) => {
|
||||
const error = (data: NodeModel | TreeGraphData, msg: string) => {
|
||||
console.error(`check ${data.id}|${data.name}: ${msg}`);
|
||||
};
|
||||
|
||||
const checkNodeArg = (
|
||||
data: NodeModel | TreeGraphData,
|
||||
conf: NodeDef,
|
||||
i: number,
|
||||
verbose?: boolean
|
||||
) => {
|
||||
let hasError = false;
|
||||
const arg = conf.args![i] as NodeArg;
|
||||
const type = arg.type.replace("?", "") as NodeArgType;
|
||||
const value = data.args?.[arg.name];
|
||||
if (type === "float") {
|
||||
const isNumber = typeof value === "number";
|
||||
const isOptional = value === undefined && arg.type === "float?";
|
||||
if (!(isNumber || isOptional)) {
|
||||
if (verbose) {
|
||||
error(data, `'${arg.name}=${value}' is not a number`);
|
||||
}
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type === "int") {
|
||||
const isInt = typeof value === "number" && value === Math.floor(value);
|
||||
const isOptional = value === undefined && arg.type === "int?";
|
||||
if (!(isInt || isOptional)) {
|
||||
if (verbose) {
|
||||
error(data, `'${arg.name}=${value}' is not a int`);
|
||||
}
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type === "string") {
|
||||
const isString = typeof value === "string" && value;
|
||||
const isOptional = (value === undefined || value === "") && arg.type === "string?";
|
||||
if (!(isString || isOptional)) {
|
||||
if (verbose) {
|
||||
error(data, `'${arg.name}=${value}' is not a string`);
|
||||
}
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type === "enum") {
|
||||
const isEnum = !!arg.options?.find((option) => option.value === value);
|
||||
const isOptional = value === undefined && arg.type === "enum?";
|
||||
if (!(isEnum || isOptional)) {
|
||||
if (verbose) {
|
||||
error(data, `'${arg.name}=${value}' is not a one of the option values`);
|
||||
}
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type === "code") {
|
||||
const isCode = typeof value === "string" && value;
|
||||
const isOptional = (value === undefined || value === "") && arg.type === "code?";
|
||||
if (!(isCode || isOptional)) {
|
||||
if (verbose) {
|
||||
error(data, `'${arg.name}=${value}' is not a string`);
|
||||
}
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type == "json") {
|
||||
const isJson = value !== undefined && value !== null && value !== "";
|
||||
const isOptional = arg.type === "json?";
|
||||
if (!(isJson || isOptional)) {
|
||||
if (verbose) {
|
||||
error(data, `'${arg.name}=${value}' is not an invalid object`);
|
||||
}
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
if (arg.oneof !== undefined) {
|
||||
const idx = conf.input?.findIndex((v) => v.startsWith(arg.oneof!)) ?? -1;
|
||||
if (!checkOneof(data.args?.[arg.name], data.input?.[idx])) {
|
||||
if (verbose) {
|
||||
error(
|
||||
data,
|
||||
`only one is allowed for between argument '${arg.name}' and input '${data.input?.[idx]}'`
|
||||
);
|
||||
}
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
return !hasError;
|
||||
};
|
||||
|
||||
export const checkOneof = (argValue: unknown, inputValue: unknown) => {
|
||||
argValue = argValue ?? "";
|
||||
inputValue = inputValue ?? "";
|
||||
return (argValue !== "" && inputValue === "") || (argValue === "" && inputValue !== "");
|
||||
};
|
||||
|
||||
export const checkNodeData = (data: NodeModel | null | undefined) => {
|
||||
if (!data) {
|
||||
return false;
|
||||
@@ -120,64 +207,9 @@ export const checkNodeData = (data: NodeModel | null | undefined) => {
|
||||
}
|
||||
if (conf.args) {
|
||||
for (let i = 0; i < conf.args.length; i++) {
|
||||
const arg = conf.args[i] as NodeArg;
|
||||
const type = arg.type.replace("?", "") as NodeArgType;
|
||||
const value = data.args?.[arg.name];
|
||||
if (type === "float") {
|
||||
const isNumber = typeof value === "number";
|
||||
const isOptional = value === undefined && arg.type === "float?";
|
||||
if (!(isNumber || isOptional)) {
|
||||
error(data, `'${arg.name}=${value}' is not a number`);
|
||||
if (!checkNodeArg(data, conf, i, true)) {
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type === "int") {
|
||||
const isInt = typeof value === "number" && value === Math.floor(value);
|
||||
const isOptional = value === undefined && arg.type === "int?";
|
||||
if (!(isInt || isOptional)) {
|
||||
error(data, `'${arg.name}=${value}' is not a int`);
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type === "string") {
|
||||
const isString = typeof value === "string" && value;
|
||||
const isOptional = (value === undefined || value === "") && arg.type === "string?";
|
||||
if (!(isString || isOptional)) {
|
||||
error(data, `'${arg.name}=${value}' is not a string`);
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type === "enum") {
|
||||
const isEnum = !!arg.options?.find((option) => option.value === value);
|
||||
const isOptional = value === undefined && arg.type === "enum?";
|
||||
if (!(isEnum || isOptional)) {
|
||||
error(data, `'${arg.name}=${value}' is not a one of the option values`);
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type == "code") {
|
||||
const isCode = typeof value === "string" && value;
|
||||
const isOptional = (value === undefined || value === "") && arg.type === "code?";
|
||||
if (!(isCode || isOptional)) {
|
||||
error(data, `'${arg.name}=${value}' is not a string`);
|
||||
hasError = true;
|
||||
}
|
||||
} else if (type == "json") {
|
||||
const isJson = value !== undefined && value !== null && value !== "";
|
||||
const isOptional = arg.type === "json?";
|
||||
if (!(isJson || isOptional)) {
|
||||
error(data, `'${arg.name}=${value}' is not an invalid object`);
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
if (arg.oneof !== undefined) {
|
||||
const idx = conf.input?.findIndex((v) => v.startsWith(arg.oneof!)) ?? -1;
|
||||
const inputValue = data.input?.[idx] ?? "";
|
||||
const argValue = data.args?.[arg.name] ?? "";
|
||||
if ((inputValue !== "" && argValue !== "") || (inputValue === "" && argValue === "")) {
|
||||
error(
|
||||
data,
|
||||
`only one is allowed for between argument '${arg.name}' and input '${data.input?.[idx]}'`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,54 +431,9 @@ export const checkTreeData = (data: TreeGraphData) => {
|
||||
}
|
||||
if (conf.args) {
|
||||
for (let i = 0; i < conf.args.length; i++) {
|
||||
const arg = conf.args[i] as NodeArg;
|
||||
const type = arg.type.replace("?", "") as NodeArgType;
|
||||
const value = data.args?.[arg.name];
|
||||
if (type === "float") {
|
||||
const isNumber = typeof value === "number";
|
||||
const isOptional = value === undefined && arg.type === "float?";
|
||||
if (!(isNumber || isOptional)) {
|
||||
if (!checkNodeArg(data, conf, i, false)) {
|
||||
return false;
|
||||
}
|
||||
} else if (type === "int") {
|
||||
const isInt = typeof value === "number" && value === Math.floor(value);
|
||||
const isOptional = value === undefined && arg.type === "int?";
|
||||
if (!(isInt || isOptional)) {
|
||||
return false;
|
||||
}
|
||||
} else if (type === "string") {
|
||||
const isString = typeof value === "string" && value;
|
||||
const isOptional = (value === undefined || value === "") && arg.type === "string?";
|
||||
if (!(isString || isOptional)) {
|
||||
return false;
|
||||
}
|
||||
} else if (type === "enum") {
|
||||
const isEnum = !!arg.options?.find((option) => option.value === value);
|
||||
const isOptional = value === undefined && arg.type === "enum?";
|
||||
if (!(isEnum || isOptional)) {
|
||||
return false;
|
||||
}
|
||||
} else if (type === "code") {
|
||||
const isCode = typeof value === "string" && value;
|
||||
const isOptional = (value === undefined || value === "") && arg.type === "code?";
|
||||
if (!(isCode || isOptional)) {
|
||||
return false;
|
||||
}
|
||||
} else if (type == "json") {
|
||||
const isJson = value !== undefined && value !== null && value !== "";
|
||||
const isOptional = arg.type === "json?";
|
||||
if (!(isJson || isOptional)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (arg.oneof !== undefined) {
|
||||
const idx = conf.input?.findIndex((v) => v.startsWith(arg.oneof!)) ?? -1;
|
||||
const inputValue = data.input?.[idx] ?? "";
|
||||
const argValue = data.args?.[arg.name] ?? "";
|
||||
if ((inputValue !== "" && argValue !== "") || (inputValue === "" && argValue === "")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user