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
+40 -35

No files matched your search

+14 -14
View File
@@ -445,7 +445,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
try {
const str = clipboard.readText();
if (!str || str == "") {
if (!str || str === "") {
return;
}
const curNodeData = findDataById(editor.selectedId);
@@ -477,7 +477,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
try {
const str = clipboard.readText();
if (!str || str == "") {
if (!str || str === "") {
return;
}
const curNodeData = findDataById(editor.selectedId);
@@ -547,7 +547,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
}
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);
selectNode(null);
updateGrahp();
@@ -652,7 +652,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
}
subpath = subpath.replaceAll(Path.sep, "/");
if (subpath.indexOf(workspace.workdir) == -1) {
if (subpath.indexOf(workspace.workdir) === -1) {
message.warning(t("node.subtreePathError"));
return;
}
@@ -741,7 +741,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
});
editor.graph.on("viewportchange", (data: any) => {
if (data.action == "translate" || data.action == "zoom") {
if (data.action === "translate" || data.action === "zoom") {
editor.graphMatrix = data.matrix;
}
});
@@ -877,7 +877,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
return;
}
if (srcNodeId == dstNode.getID()) {
if (srcNodeId === dstNode.getID()) {
console.log("drop same node");
return;
}
@@ -897,30 +897,30 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
}
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();
if (!dstData.children) {
dstData.children = [];
}
srcData.parent = dstData.id;
dstData.children.push(srcData);
} else if (dragDir == "dragUp") {
} else if (dragDir === "dragUp") {
if (!dstParent) {
return;
}
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;
dstParent.children!.splice(idx, 0, srcData);
} else if (dragDir == "dragDown") {
} else if (dragDir === "dragDown") {
if (!dstParent) {
return;
}
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;
dstParent.children!.splice(idx + 1, 0, srcData);
} else {
@@ -1248,7 +1248,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
type="text"
size="small"
style={{ width: "30px" }}
disabled={filterOption.results.length == 0}
disabled={filterOption.results.length === 0}
onClick={nextResult}
/>
)}
@@ -1258,7 +1258,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
type="text"
size="small"
style={{ width: "30px" }}
disabled={filterOption.results.length == 0}
disabled={filterOption.results.length === 0}
onClick={prevResult}
/>
)}
+14 -10
View File
@@ -109,9 +109,11 @@ const NodeInspector: FC = () => {
}
def.args?.forEach((v) => {
if (v.type === "json" || v.type === "json?") {
const value = data.args?.[v.name];
console.log("nameJson", v.name, value, data.args);
form.setFieldValue(
`args.${v.name}`,
JSON.stringify(data.args?.[v.name] ?? v.default, null, 2)
value === null ? "null" : JSON.stringify(value ?? v.default, null, 2)
);
} else {
form.setFieldValue(`args.${v.name}`, data.args?.[v.name] ?? v.default);
@@ -194,7 +196,7 @@ const NodeInspector: FC = () => {
if (v !== null && v !== undefined && v !== "") {
data.args ||= {};
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 {
data.args[arg.name] = v;
}
@@ -324,7 +326,7 @@ const NodeInspector: FC = () => {
<h4>{t("node.inputVariable")}</h4>
</Divider>
{def.input.map((v, i) => {
const required = v.indexOf("?") == -1;
const required = v.indexOf("?") === -1;
const desc = v.replace("?", "");
return (
<Form.Item
@@ -386,7 +388,7 @@ const NodeInspector: FC = () => {
<h4>{t("node.args")}</h4>
</Divider>
{def.args.map((v) => {
const required = v.type.indexOf("?") == -1;
const required = v.type.indexOf("?") === -1;
const type = v.type.replace("?", "") as NodeArgType;
return (
<Form.Item
@@ -399,9 +401,11 @@ const NodeInspector: FC = () => {
{ required, message: t("node.fileRequired", { field: v.desc }) },
({ getFieldValue, setFieldValue, isFieldValidating, validateFields }) => ({
validator(_, value) {
if (value && (v.type == "json" || v.type == "json?")) {
if (value && (v.type === "json" || v.type === "json?")) {
try {
JSON.parse(value);
if (value !== "null") {
JSON.parse(value);
}
} catch (e) {
return Promise.reject(new Error(t("node.invalidValue")));
}
@@ -474,7 +478,7 @@ const NodeInspector: FC = () => {
<h4>{t("node.outputVariable")}</h4>
</Divider>
{def.output.map((v, i) => {
const required = v.indexOf("?") == -1;
const required = v.indexOf("?") === -1;
const desc = v.replace("?", "");
return (
<Form.Item
@@ -580,7 +584,7 @@ const NodeDefInspector: FC = () => {
<h4>{t("node.inputVariable")}</h4>
</Divider>
{def.input.map((v, i) => {
const required = v.indexOf("?") == -1;
const required = v.indexOf("?") === -1;
return (
<Form.Item
label={`[${i}]`}
@@ -600,7 +604,7 @@ const NodeDefInspector: FC = () => {
<h4>{t("node.args")}</h4>
</Divider>
{def.args.map((v, i) => {
const required = v.type.indexOf("?") == -1;
const required = v.type.indexOf("?") === -1;
return (
<Form.Item
name={`args.${i}.type`}
@@ -628,7 +632,7 @@ const NodeDefInspector: FC = () => {
<h4>{t("node.outputVariable")}</h4>
</Divider>
{def.output.map((v, i) => {
const required = v.indexOf("?") == -1;
const required = v.indexOf("?") === -1;
return (
<Form.Item
label={`[${i}]`}
+1 -1
View File
@@ -65,7 +65,7 @@ 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";
+2 -2
View File
@@ -156,7 +156,7 @@ export const Workspace: FC = () => {
<div>
<FaExclamationTriangle style={{ fontSize: "60px", color: "#FADB14" }} />
</div>
{unsaves.length == 1 && (
{unsaves.length === 1 && (
<div>{t("workspace.saveOnClose", { name: Path.basename(unsaves[0].path) })}</div>
)}
{unsaves.length > 1 && (
@@ -331,7 +331,7 @@ export const Workspace: FC = () => {
</Flex>
</Flex>
)}
{workspace.editors.length == 0 && (
{workspace.editors.length === 0 && (
<Flex vertical align="center" justify="center" style={{ height: "100%" }}>
<Flex
vertical