fix oneof compare

This commit is contained in:
codetypes committed 2024-08-07 22:05:47 +08:00
1 parent dab1d8ee8a
commit 7a40a36ca5
1 file changed
+7 -3
+7 -3
View File
@@ -337,7 +337,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) {
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) { if (arg) {
const argName = `args.${arg.name}`; const argName = `args.${arg.name}`;
if (!isFieldValidating(argName)) { if (!isFieldValidating(argName)) {
@@ -407,10 +409,12 @@ const NodeInspector: FC = () => {
return Promise.reject(new Error(t("node.invalidValue"))); return Promise.reject(new Error(t("node.invalidValue")));
} }
} }
if (v.oneof === undefined) { if (!v.oneof) {
return Promise.resolve(); 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) { if (idx === undefined || idx < 0) {
return Promise.reject( return Promise.reject(
new Error(t("node.oneof.inputNotfound", { input: v.oneof })) new Error(t("node.oneof.inputNotfound", { input: v.oneof }))