-
Notifications
You must be signed in to change notification settings - Fork 8
fix: Update buildSchemaTree to handle old parent UID and improve fiel… #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… duplicate fields and improve UID checks
| } | ||
|
|
||
| export function buildSchemaTree(fields: any[], parentUid = '', parentType = ''): any[] { | ||
| export function buildSchemaTree(fields: any[], parentUid = '', parentType = '', oldPrentUid = ''): any[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oldPrentUid correct the spelling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|
|
||
| // Fallback: check if field is a direct child of oldPrentUid (if provided and different) | ||
| if (oldPrentUid && oldPrentUid !== parentUid && fieldUid.startsWith(oldPrentUid + '.')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct the spelling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| const remainder = fieldUid.substring(oldPrentUid.length + 1); | ||
| // Verify it's exactly one level deeper (no more dots in remainder) | ||
| return remainder && !remainder.includes('.'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add null checks in above function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| if (oldFieldtUid && fUid.startsWith(oldFieldtUid + '.')) { | ||
| const remainder = fUid.substring(oldFieldtUid.length + 1); | ||
| return remainder && !remainder.includes('.'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add null checks in above block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| uid: childUid, | ||
| display_name: childDisplay, | ||
| schema: buildSchemaTree(fields, child.contentstackFieldUid, 'modular_blocks_child') | ||
| schema: buildSchemaTree(fields, child.contentstackFieldUid, 'modular_blocks_child', child?.backupFieldUid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
child?.contentstackFieldUid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want the backFieldUId to get the nested child of it if it is mapped to another field
| (fieldType === 'modular_blocks_child' && hasChildren)) { | ||
| // Recursively build schema for groups and modular block children with nested content | ||
| result.schema = buildSchemaTree(fields, fieldUid, fieldType); | ||
| result.schema = buildSchemaTree(fields, fieldUid, fieldType, oldFieldtUid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be oldFieldUid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…dle optional chaining for field properties
…ng for field UIDs
…d UID checks