check input and output name
This commit is contained in:
1 parent
7cee076245
commit
77cb4a5411
4 files changed
+61
-1
No files matched your search
@@ -98,6 +98,7 @@
|
|||||||
"node.id": "Node id",
|
"node.id": "Node id",
|
||||||
"node.inputVariable": "Input variables",
|
"node.inputVariable": "Input variables",
|
||||||
"node.invalidValue": "Invalid value",
|
"node.invalidValue": "Invalid value",
|
||||||
|
"node.invalidVariableName": "Invalid variable name, should start with a letter or underscore",
|
||||||
"node.name": "Node name",
|
"node.name": "Node name",
|
||||||
"node.noNodeSelected": "No node selected",
|
"node.noNodeSelected": "No node selected",
|
||||||
"node.oneof.error": "Only one is allowed between input '{{input}}' and argument '{{arg}}({{desc}})'",
|
"node.oneof.error": "Only one is allowed between input '{{input}}' and argument '{{arg}}({{desc}})'",
|
||||||
|
|||||||
@@ -98,6 +98,7 @@
|
|||||||
"node.id": "节点标识",
|
"node.id": "节点标识",
|
||||||
"node.inputVariable": "输入变量",
|
"node.inputVariable": "输入变量",
|
||||||
"node.invalidValue": "无效的值",
|
"node.invalidValue": "无效的值",
|
||||||
|
"node.invalidVariableName": "变量名必须以字母或下划线开头",
|
||||||
"node.name": "节点名称",
|
"node.name": "节点名称",
|
||||||
"node.noNodeSelected": "未选择任务节点",
|
"node.noNodeSelected": "未选择任务节点",
|
||||||
"node.oneof.error": "输入项 “{{input}}” 和参数 “{{arg}}({{desc}})” 之中,只能选择设置其中之一",
|
"node.oneof.error": "输入项 “{{input}}” 和参数 “{{arg}}({{desc}})” 之中,只能选择设置其中之一",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
getNodeArgRawType,
|
getNodeArgRawType,
|
||||||
isNodeArgArray,
|
isNodeArgArray,
|
||||||
isNodeArgOptional,
|
isNodeArgOptional,
|
||||||
|
isValidVariableName,
|
||||||
} from "@/misc/b3util";
|
} from "@/misc/b3util";
|
||||||
import { Hotkey, isMacos } from "@/misc/keys";
|
import { Hotkey, isMacos } from "@/misc/keys";
|
||||||
import { mergeClassNames } from "@/misc/util";
|
import { mergeClassNames } from "@/misc/util";
|
||||||
@@ -436,6 +437,18 @@ const NodeInspector: FC = () => {
|
|||||||
name={field.name}
|
name={field.name}
|
||||||
validateTrigger={["onChange", "onBlur"]}
|
validateTrigger={["onChange", "onBlur"]}
|
||||||
style={{ width: "100%", marginBottom: 5 }}
|
style={{ width: "100%", marginBottom: 5 }}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
validator(_, value) {
|
||||||
|
if (value && !isValidVariableName(value)) {
|
||||||
|
return Promise.reject(
|
||||||
|
new Error(t("node.invalidVariableName"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<AutoComplete
|
<AutoComplete
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@@ -489,6 +502,9 @@ const NodeInspector: FC = () => {
|
|||||||
{ required, message: t("node.fileRequired", { field: desc }) },
|
{ required, message: t("node.fileRequired", { field: desc }) },
|
||||||
({ getFieldValue, setFieldValue, isFieldValidating, validateFields }) => ({
|
({ getFieldValue, setFieldValue, isFieldValidating, validateFields }) => ({
|
||||||
validator(_, value) {
|
validator(_, value) {
|
||||||
|
if (value && !isValidVariableName(value)) {
|
||||||
|
return Promise.reject(new Error(t("node.invalidVariableName")));
|
||||||
|
}
|
||||||
const arg = def.args?.find(
|
const arg = def.args?.find(
|
||||||
(a) => a.oneof && v.replace("?", "") === a.oneof
|
(a) => a.oneof && v.replace("?", "") === a.oneof
|
||||||
);
|
);
|
||||||
@@ -792,6 +808,18 @@ const NodeInspector: FC = () => {
|
|||||||
name={field.name}
|
name={field.name}
|
||||||
validateTrigger={["onChange", "onBlur"]}
|
validateTrigger={["onChange", "onBlur"]}
|
||||||
style={{ width: "100%", marginBottom: 5 }}
|
style={{ width: "100%", marginBottom: 5 }}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
validator(_, value) {
|
||||||
|
if (value && !isValidVariableName(value)) {
|
||||||
|
return Promise.reject(
|
||||||
|
new Error(t("node.invalidVariableName"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<AutoComplete
|
<AutoComplete
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@@ -841,7 +869,17 @@ const NodeInspector: FC = () => {
|
|||||||
label={desc}
|
label={desc}
|
||||||
name={`output.${i}`}
|
name={`output.${i}`}
|
||||||
key={`output.${i}`}
|
key={`output.${i}`}
|
||||||
rules={[{ required, message: t("node.fileRequired", { field: desc }) }]}
|
rules={[
|
||||||
|
{ required, message: t("node.fileRequired", { field: desc }) },
|
||||||
|
{
|
||||||
|
validator(_, value) {
|
||||||
|
if (value && !isValidVariableName(value)) {
|
||||||
|
return Promise.reject(new Error(t("node.invalidVariableName")));
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<AutoComplete
|
<AutoComplete
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ import { message } from "./hooks";
|
|||||||
import Path from "./path";
|
import Path from "./path";
|
||||||
import { zhNodeDef } from "./template";
|
import { zhNodeDef } from "./template";
|
||||||
|
|
||||||
|
export const isValidVariableName = (name: string) => {
|
||||||
|
return /^[a-zA-Z_]/.test(name);
|
||||||
|
};
|
||||||
|
|
||||||
export const isSubtreeRoot = (data: TreeGraphData) => {
|
export const isSubtreeRoot = (data: TreeGraphData) => {
|
||||||
return data.path && data.id.toString() !== "1";
|
return data.path && data.id.toString() !== "1";
|
||||||
};
|
};
|
||||||
@@ -229,6 +233,14 @@ export const checkNodeData = (data: NodeModel | null | undefined) => {
|
|||||||
if (!data.input[i]) {
|
if (!data.input[i]) {
|
||||||
data.input[i] = "";
|
data.input[i] = "";
|
||||||
}
|
}
|
||||||
|
if (data.input[i] && !isValidVariableName(data.input[i])) {
|
||||||
|
error(
|
||||||
|
data,
|
||||||
|
`input field '${data.input[i]}' is not a valid variable name,` +
|
||||||
|
`should start with a letter or underscore`
|
||||||
|
);
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
if (!isValidInputOrOutput(conf.input, data.input, i)) {
|
if (!isValidInputOrOutput(conf.input, data.input, i)) {
|
||||||
error(data, `intput field '${conf.input[i]}' is required`);
|
error(data, `intput field '${conf.input[i]}' is required`);
|
||||||
hasError = true;
|
hasError = true;
|
||||||
@@ -251,6 +263,14 @@ export const checkNodeData = (data: NodeModel | null | undefined) => {
|
|||||||
if (!data.output[i]) {
|
if (!data.output[i]) {
|
||||||
data.output[i] = "";
|
data.output[i] = "";
|
||||||
}
|
}
|
||||||
|
if (data.output[i] && !isValidVariableName(data.output[i])) {
|
||||||
|
error(
|
||||||
|
data,
|
||||||
|
`output field '${data.output[i]}' is not a valid variable name,` +
|
||||||
|
`should start with a letter or underscore`
|
||||||
|
);
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
if (!isValidInputOrOutput(conf.output, data.output, i)) {
|
if (!isValidInputOrOutput(conf.output, data.output, i)) {
|
||||||
error(data, `output field '${conf.output[i]}' is required`);
|
error(data, `output field '${conf.output[i]}' is required`);
|
||||||
hasError = true;
|
hasError = true;
|
||||||
|
|||||||
Reference in new issue
Block a user