🐛 fix(reactflowUtils.ts): fix validation logic for nested dictionaries in validateNode function
✨ feat(reactflowUtils.ts): add hasEmptyKey function to check for empty keys in dictionaries in validateNode function
This commit is contained in:
parent
b30f9ddf7f
commit
52a8e6eeb5
1 changed files with 41 additions and 23 deletions
|
|
@ -204,9 +204,8 @@ export function validateNode(
|
||||||
node: { template },
|
node: { template },
|
||||||
} = node.data;
|
} = node.data;
|
||||||
|
|
||||||
return Object.keys(template).reduce(
|
return Object.keys(template).reduce((errors: Array<string>, t) => {
|
||||||
(errors: Array<string>, t) =>
|
if (
|
||||||
errors.concat(
|
|
||||||
template[t].required &&
|
template[t].required &&
|
||||||
template[t].show &&
|
template[t].show &&
|
||||||
(template[t].value === undefined ||
|
(template[t].value === undefined ||
|
||||||
|
|
@ -219,14 +218,22 @@ export function validateNode(
|
||||||
edge.targetHandle?.split("|")[1] === t &&
|
edge.targetHandle?.split("|")[1] === t &&
|
||||||
edge.targetHandle.split("|")[2] === node.id
|
edge.targetHandle.split("|")[2] === node.id
|
||||||
)
|
)
|
||||||
? [
|
) {
|
||||||
`${type} is missing ${template.display_name || toNormalCase(template[t].name)
|
errors.push(`${type} is missing ${template.display_name || toNormalCase(template[t].name)}.`);
|
||||||
}.`,
|
} else if (
|
||||||
]
|
(template[t].type === "dict" || template[t].type === "NestedDict") &&
|
||||||
: []
|
template[t].required &&
|
||||||
),
|
template[t].show &&
|
||||||
[] as string[]
|
(template[t].value !== undefined ||
|
||||||
);
|
template[t].value !== null ||
|
||||||
|
template[t].value !== "")
|
||||||
|
) {
|
||||||
|
if (hasDuplicateKeys(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) contains duplicate keys with the same values.`);
|
||||||
|
if (hasEmptyKey(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) contains keys with empty values.`);
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
}, [] as string[]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateNodes(reactFlowInstance: ReactFlowInstance) {
|
export function validateNodes(reactFlowInstance: ReactFlowInstance) {
|
||||||
|
|
@ -319,6 +326,17 @@ export function hasDuplicateKeys(array) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hasEmptyKey(objArray) {
|
||||||
|
for (const obj of objArray) {
|
||||||
|
for (const key in obj) {
|
||||||
|
if (obj.hasOwnProperty(key) && key === '') {
|
||||||
|
return true; // Found an empty key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false; // No empty keys found
|
||||||
|
}
|
||||||
|
|
||||||
export function convertValuesToNumbers(arr) {
|
export function convertValuesToNumbers(arr) {
|
||||||
return arr.map((obj) => {
|
return arr.map((obj) => {
|
||||||
const newObj = {};
|
const newObj = {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue