fixes: tabs children are not rendered as the are not in their repsective parent container (#8036)

This commit is contained in:
Arpit 2023-10-26 21:47:35 +05:30 committed by GitHub
parent a2f80374b0
commit 601cb74f53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -126,7 +126,7 @@ export class PageService {
const clonedComponents = await Promise.all(
pageComponents.map(async (component) => {
const clonedComponent = { ...component, id: undefined, pageId: clonePageId };
const newComponent = await manager.save(Component, clonedComponent);
const newComponent = await manager.save(manager.create(Component, clonedComponent));
componentsIdMap[component.id] = newComponent.id;
const componentLayouts = await manager.find(Layout, { componentId: component.id });
@ -164,10 +164,37 @@ export class PageService {
})
);
const isChildOfTabsOrCalendar = (component, allComponents = [], componentParentId = undefined) => {
if (componentParentId) {
const parentId = component?.parent?.split('-').slice(0, -1).join('-');
const parentComponent = allComponents.find((comp) => comp.id === parentId);
if (parentComponent) {
return parentComponent.type === 'Tabs' || parentComponent.type === 'Calendar';
}
}
return false;
};
for (const component of clonedComponents) {
const componentId = componentsIdMap[component.parent];
if (componentId) {
await manager.update(Component, component.id, { parent: componentId });
let parentId = component.parent ? component.parent : null;
const isParentTabOrCalendar = isChildOfTabsOrCalendar(component, pageComponents, parentId);
if (isParentTabOrCalendar) {
const childTabId = component.parent.split('-')[component.parent.split('-').length - 1];
const _parentId = component?.parent?.split('-').slice(0, -1).join('-');
const mappedParentId = componentsIdMap[_parentId];
parentId = `${mappedParentId}-${childTabId}`;
} else {
parentId = componentsIdMap[parentId];
}
if (parentId) {
await manager.update(Component, component.id, { parent: parentId });
}
}
});