fix null value error

This commit is contained in:
codetypes committed 2024-07-23 17:44:18 +08:00
1 parent 54c0ff7356
commit d32c0a54b0
6 files changed
+39 -34

No files matched your search

+1
View File
@@ -9,6 +9,7 @@ module.exports = {
plugins: ["@typescript-eslint", "@stylistic/js", "react-refresh"], plugins: ["@typescript-eslint", "@stylistic/js", "react-refresh"],
parser: "@typescript-eslint/parser", parser: "@typescript-eslint/parser",
rules: { rules: {
eqeqeq: "error",
"@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-shadow": "error", "@typescript-eslint/no-shadow": "error",
"react-refresh/only-export-components": "warn", "react-refresh/only-export-components": "warn",
+14 -14
View File
@@ -445,7 +445,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
try { try {
const str = clipboard.readText(); const str = clipboard.readText();
if (!str || str == "") { if (!str || str === "") {
return; return;
} }
const curNodeData = findDataById(editor.selectedId); const curNodeData = findDataById(editor.selectedId);
@@ -477,7 +477,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
try { try {
const str = clipboard.readText(); const str = clipboard.readText();
if (!str || str == "") { if (!str || str === "") {
return; return;
} }
const curNodeData = findDataById(editor.selectedId); const curNodeData = findDataById(editor.selectedId);
@@ -547,7 +547,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
} }
const parentData = findParent(data)!; const parentData = findParent(data)!;
parentData.children = parentData.children!.filter((e) => e.id != editor.selectedId); parentData.children = parentData.children!.filter((e) => e.id !== editor.selectedId);
refreshItem(parentData); refreshItem(parentData);
selectNode(null); selectNode(null);
updateGrahp(); updateGrahp();
@@ -652,7 +652,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
} }
subpath = subpath.replaceAll(Path.sep, "/"); subpath = subpath.replaceAll(Path.sep, "/");
if (subpath.indexOf(workspace.workdir) == -1) { if (subpath.indexOf(workspace.workdir) === -1) {
message.warning(t("node.subtreePathError")); message.warning(t("node.subtreePathError"));
return; return;
} }
@@ -741,7 +741,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
}); });
editor.graph.on("viewportchange", (data: any) => { editor.graph.on("viewportchange", (data: any) => {
if (data.action == "translate" || data.action == "zoom") { if (data.action === "translate" || data.action === "zoom") {
editor.graphMatrix = data.matrix; editor.graphMatrix = data.matrix;
} }
}); });
@@ -877,7 +877,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
return; return;
} }
if (srcNodeId == dstNode.getID()) { if (srcNodeId === dstNode.getID()) {
console.log("drop same node"); console.log("drop same node");
return; return;
} }
@@ -897,30 +897,30 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
} }
const removeSrc = () => { const removeSrc = () => {
srcParent.children = srcParent.children!.filter((value) => value.id != srcData.id); srcParent.children = srcParent.children!.filter((value) => value.id !== srcData.id);
}; };
if (dragDir == "dragRight") { if (dragDir === "dragRight") {
removeSrc(); removeSrc();
if (!dstData.children) { if (!dstData.children) {
dstData.children = []; dstData.children = [];
} }
srcData.parent = dstData.id; srcData.parent = dstData.id;
dstData.children.push(srcData); dstData.children.push(srcData);
} else if (dragDir == "dragUp") { } else if (dragDir === "dragUp") {
if (!dstParent) { if (!dstParent) {
return; return;
} }
removeSrc(); removeSrc();
const idx = dstParent.children!.findIndex((value) => value.id == dstData.id); const idx = dstParent.children!.findIndex((value) => value.id === dstData.id);
srcData.parent = dstParent.id; srcData.parent = dstParent.id;
dstParent.children!.splice(idx, 0, srcData); dstParent.children!.splice(idx, 0, srcData);
} else if (dragDir == "dragDown") { } else if (dragDir === "dragDown") {
if (!dstParent) { if (!dstParent) {
return; return;
} }
removeSrc(); removeSrc();
const idx = dstParent.children!.findIndex((value) => value.id == dstData.id); const idx = dstParent.children!.findIndex((value) => value.id === dstData.id);
srcData.parent = dstParent.id; srcData.parent = dstParent.id;
dstParent.children!.splice(idx + 1, 0, srcData); dstParent.children!.splice(idx + 1, 0, srcData);
} else { } else {
@@ -1248,7 +1248,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
type="text" type="text"
size="small" size="small"
style={{ width: "30px" }} style={{ width: "30px" }}
disabled={filterOption.results.length == 0} disabled={filterOption.results.length === 0}
onClick={nextResult} onClick={nextResult}
/> />
)} )}
@@ -1258,7 +1258,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
type="text" type="text"
size="small" size="small"
style={{ width: "30px" }} style={{ width: "30px" }}
disabled={filterOption.results.length == 0} disabled={filterOption.results.length === 0}
onClick={prevResult} onClick={prevResult}
/> />
)} )}
+13 -9
View File
@@ -109,9 +109,11 @@ const NodeInspector: FC = () => {
} }
def.args?.forEach((v) => { def.args?.forEach((v) => {
if (v.type === "json" || v.type === "json?") { if (v.type === "json" || v.type === "json?") {
const value = data.args?.[v.name];
console.log("nameJson", v.name, value, data.args);
form.setFieldValue( form.setFieldValue(
`args.${v.name}`, `args.${v.name}`,
JSON.stringify(data.args?.[v.name] ?? v.default, null, 2) value === null ? "null" : JSON.stringify(value ?? v.default, null, 2)
); );
} else { } else {
form.setFieldValue(`args.${v.name}`, data.args?.[v.name] ?? v.default); form.setFieldValue(`args.${v.name}`, data.args?.[v.name] ?? v.default);
@@ -194,7 +196,7 @@ const NodeInspector: FC = () => {
if (v !== null && v !== undefined && v !== "") { if (v !== null && v !== undefined && v !== "") {
data.args ||= {}; data.args ||= {};
if (arg.type === "json" || arg.type === "json?") { if (arg.type === "json" || arg.type === "json?") {
data.args[arg.name] = JSON.parse(v); data.args[arg.name] = v === "null" ? null : JSON.parse(v);
} else { } else {
data.args[arg.name] = v; data.args[arg.name] = v;
} }
@@ -324,7 +326,7 @@ const NodeInspector: FC = () => {
<h4>{t("node.inputVariable")}</h4> <h4>{t("node.inputVariable")}</h4>
</Divider> </Divider>
{def.input.map((v, i) => { {def.input.map((v, i) => {
const required = v.indexOf("?") == -1; const required = v.indexOf("?") === -1;
const desc = v.replace("?", ""); const desc = v.replace("?", "");
return ( return (
<Form.Item <Form.Item
@@ -386,7 +388,7 @@ const NodeInspector: FC = () => {
<h4>{t("node.args")}</h4> <h4>{t("node.args")}</h4>
</Divider> </Divider>
{def.args.map((v) => { {def.args.map((v) => {
const required = v.type.indexOf("?") == -1; const required = v.type.indexOf("?") === -1;
const type = v.type.replace("?", "") as NodeArgType; const type = v.type.replace("?", "") as NodeArgType;
return ( return (
<Form.Item <Form.Item
@@ -399,9 +401,11 @@ const NodeInspector: FC = () => {
{ required, message: t("node.fileRequired", { field: v.desc }) }, { required, message: t("node.fileRequired", { field: v.desc }) },
({ getFieldValue, setFieldValue, isFieldValidating, validateFields }) => ({ ({ getFieldValue, setFieldValue, isFieldValidating, validateFields }) => ({
validator(_, value) { validator(_, value) {
if (value && (v.type == "json" || v.type == "json?")) { if (value && (v.type === "json" || v.type === "json?")) {
try { try {
if (value !== "null") {
JSON.parse(value); JSON.parse(value);
}
} catch (e) { } catch (e) {
return Promise.reject(new Error(t("node.invalidValue"))); return Promise.reject(new Error(t("node.invalidValue")));
} }
@@ -474,7 +478,7 @@ const NodeInspector: FC = () => {
<h4>{t("node.outputVariable")}</h4> <h4>{t("node.outputVariable")}</h4>
</Divider> </Divider>
{def.output.map((v, i) => { {def.output.map((v, i) => {
const required = v.indexOf("?") == -1; const required = v.indexOf("?") === -1;
const desc = v.replace("?", ""); const desc = v.replace("?", "");
return ( return (
<Form.Item <Form.Item
@@ -580,7 +584,7 @@ const NodeDefInspector: FC = () => {
<h4>{t("node.inputVariable")}</h4> <h4>{t("node.inputVariable")}</h4>
</Divider> </Divider>
{def.input.map((v, i) => { {def.input.map((v, i) => {
const required = v.indexOf("?") == -1; const required = v.indexOf("?") === -1;
return ( return (
<Form.Item <Form.Item
label={`[${i}]`} label={`[${i}]`}
@@ -600,7 +604,7 @@ const NodeDefInspector: FC = () => {
<h4>{t("node.args")}</h4> <h4>{t("node.args")}</h4>
</Divider> </Divider>
{def.args.map((v, i) => { {def.args.map((v, i) => {
const required = v.type.indexOf("?") == -1; const required = v.type.indexOf("?") === -1;
return ( return (
<Form.Item <Form.Item
name={`args.${i}.type`} name={`args.${i}.type`}
@@ -628,7 +632,7 @@ const NodeDefInspector: FC = () => {
<h4>{t("node.outputVariable")}</h4> <h4>{t("node.outputVariable")}</h4>
</Divider> </Divider>
{def.output.map((v, i) => { {def.output.map((v, i) => {
const required = v.indexOf("?") == -1; const required = v.indexOf("?") === -1;
return ( return (
<Form.Item <Form.Item
label={`[${i}]`} label={`[${i}]`}
+1 -1
View File
@@ -65,7 +65,7 @@ G6.registerNode(
let color = nodeDef.color || NODE_COLORS[classify] || NODE_COLORS["Other"]; let color = nodeDef.color || NODE_COLORS[classify] || NODE_COLORS["Other"];
if ( if (
!workspace.hasNodeDef(cfg.name as string) || !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) !checkTreeData(cfg as TreeGraphData)
) { ) {
classify = "Error"; classify = "Error";
+2 -2
View File
@@ -156,7 +156,7 @@ export const Workspace: FC = () => {
<div> <div>
<FaExclamationTriangle style={{ fontSize: "60px", color: "#FADB14" }} /> <FaExclamationTriangle style={{ fontSize: "60px", color: "#FADB14" }} />
</div> </div>
{unsaves.length == 1 && ( {unsaves.length === 1 && (
<div>{t("workspace.saveOnClose", { name: Path.basename(unsaves[0].path) })}</div> <div>{t("workspace.saveOnClose", { name: Path.basename(unsaves[0].path) })}</div>
)} )}
{unsaves.length > 1 && ( {unsaves.length > 1 && (
@@ -331,7 +331,7 @@ export const Workspace: FC = () => {
</Flex> </Flex>
</Flex> </Flex>
)} )}
{workspace.editors.length == 0 && ( {workspace.editors.length === 0 && (
<Flex vertical align="center" justify="center" style={{ height: "100%" }}> <Flex vertical align="center" justify="center" style={{ height: "100%" }}>
<Flex <Flex
vertical vertical
+8 -8
View File
@@ -126,8 +126,8 @@ const checkNodeArg = (
} }
hasError = true; hasError = true;
} }
} else if (type == "json") { } else if (type === "json") {
const isJson = value !== undefined && value !== null && value !== ""; const isJson = value !== undefined && value !== "";
const isOptional = arg.type === "json?"; const isOptional = arg.type === "json?";
if (!(isJson || isOptional)) { if (!(isJson || isOptional)) {
if (verbose) { if (verbose) {
@@ -153,7 +153,7 @@ const checkNodeArg = (
}; };
export const checkOneof = (argValue: unknown, inputValue: unknown) => { export const checkOneof = (argValue: unknown, inputValue: unknown) => {
argValue = argValue ?? ""; argValue = argValue === undefined ? "" : argValue;
inputValue = inputValue ?? ""; inputValue = inputValue ?? "";
return (argValue !== "" && inputValue === "") || (argValue === "" && inputValue !== ""); return (argValue !== "" && inputValue === "") || (argValue === "" && inputValue !== "");
}; };
@@ -164,7 +164,7 @@ 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 && conf.children != -1) { if (conf.children !== undefined && conf.children !== -1) {
const count = data.children?.length || 0; const count = data.children?.length || 0;
if (conf.children !== count) { if (conf.children !== count) {
hasError = true; hasError = true;
@@ -264,7 +264,7 @@ export const createNode = (data: TreeGraphData, includeChildren: boolean = true)
node.args = {}; node.args = {};
for (const k in data.args) { for (const k in data.args) {
const v = data.args[k]; const v = data.args[k];
if (v !== null && v !== undefined) { if (v !== undefined) {
node.args[k] = v; node.args[k] = v;
} }
} }
@@ -307,10 +307,10 @@ const toStatusFlag = (data: TreeGraphData) => {
const appendStatusFlag = (status: number, childStatus: number) => { const appendStatusFlag = (status: number, childStatus: number) => {
const childSuccess = (childStatus >> StatusFlag.SUCCESS) & 1; const childSuccess = (childStatus >> StatusFlag.SUCCESS) & 1;
const childFailure = (childStatus >> StatusFlag.FAILURE) & 1; const childFailure = (childStatus >> StatusFlag.FAILURE) & 1;
if (childSuccess == 0) { if (childSuccess === 0) {
status |= 1 << StatusFlag.SUCCESS_ZERO; status |= 1 << StatusFlag.SUCCESS_ZERO;
} }
if (childFailure == 0) { if (childFailure === 0) {
status |= 1 << StatusFlag.FAILURE_ZERO; status |= 1 << StatusFlag.FAILURE_ZERO;
} }
status |= childStatus; status |= childStatus;
@@ -404,7 +404,7 @@ 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 && conf.children != -1) { if (conf.children !== undefined && conf.children !== -1) {
return (data.children?.length || 0) === conf.children; return (data.children?.length || 0) === conf.children;
} }
return true; return true;