From 7a40a36ca5b864ad958c934b047ba5fc68ce5812 Mon Sep 17 00:00:00 2001 From: codetypes Date: Wed, 7 Aug 2024 22:05:47 +0800 Subject: [PATCH] fix oneof compare --- src/components/inspector.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/inspector.tsx b/src/components/inspector.tsx index 2135d3d..021b57d 100644 --- a/src/components/inspector.tsx +++ b/src/components/inspector.tsx @@ -337,7 +337,9 @@ const NodeInspector: FC = () => { { required, message: t("node.fileRequired", { field: desc }) }, ({ getFieldValue, setFieldValue, isFieldValidating, validateFields }) => ({ validator(_, value) { - const arg = def.args?.find((a) => a.oneof && v.startsWith(a.oneof)); + const arg = def.args?.find( + (a) => a.oneof && v.replace("?", "") === a.oneof + ); if (arg) { const argName = `args.${arg.name}`; if (!isFieldValidating(argName)) { @@ -407,10 +409,12 @@ const NodeInspector: FC = () => { return Promise.reject(new Error(t("node.invalidValue"))); } } - if (v.oneof === undefined) { + if (!v.oneof) { return Promise.resolve(); } - const idx = def.input?.findIndex((input) => input.startsWith(v.oneof!)); + const idx = def.input?.findIndex( + (input) => input.replace("?", "") === v.oneof + ); if (idx === undefined || idx < 0) { return Promise.reject( new Error(t("node.oneof.inputNotfound", { input: v.oneof }))