From da599e135b9e5ab2ecde4df70568ea2fe33192f9 Mon Sep 17 00:00:00 2001 From: Arpit Date: Mon, 16 Oct 2023 12:53:42 +0530 Subject: [PATCH] [appdef] fixes: on importing a exported app child components are not present in the parent component (#7864) * fixes: on importing a exported app child components are not present in the parent component * handles parent component mapping for tabs and calendar component * handles parent component mapping for tabs and calendar component for new versions --- .../src/services/app_import_export.service.ts | 30 ++++++++++++++++++- server/src/services/apps.service.ts | 30 ++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/server/src/services/app_import_export.service.ts b/server/src/services/app_import_export.service.ts index d9decca543..9a84c2f1e3 100644 --- a/server/src/services/app_import_export.service.ts +++ b/server/src/services/app_import_export.service.ts @@ -576,6 +576,20 @@ export class AppImportExportService { appResourceMappings.dataQueryMapping = dataQueryMapping; } + 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 page of importingPages) { const newPage = manager.create(Page, { name: page.name, @@ -599,12 +613,26 @@ export class AppImportExportService { for (const component of pageComponents) { const newComponent = new Component(); + 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 = appResourceMappings.componentsMapping[_parentId]; + + parentId = `${mappedParentId}-${childTabId}`; + } else { + parentId = appResourceMappings.componentsMapping[parentId]; + } + newComponent.name = component.name; newComponent.type = component.type; newComponent.properties = component.properties; newComponent.styles = component.styles; newComponent.validation = component.validation; - newComponent.parent = component.parent || null; + newComponent.parent = component.parent ? parentId : null; newComponent.page = pageCreated; diff --git a/server/src/services/apps.service.ts b/server/src/services/apps.service.ts index bca36716e4..a784127a96 100644 --- a/server/src/services/apps.service.ts +++ b/server/src/services/apps.service.ts @@ -459,6 +459,20 @@ export class AppsService { const oldComponentToNewComponentMapping = {}; const oldPageToNewPageMapping = {}; + 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 page of pages) { const savedPage = await manager.save( manager.create(Page, { @@ -497,13 +511,27 @@ export class AppsService { oldComponentToNewComponentMapping[component.id] = newComponent.id; + let parentId = component.parent ? component.parent : null; + + const isParentTabOrCalendar = isChildOfTabsOrCalendar(component, page.components, parentId); + + if (isParentTabOrCalendar) { + const childTabId = component.parent.split('-')[component.parent.split('-').length - 1]; + const _parentId = component?.parent?.split('-').slice(0, -1).join('-'); + const mappedParentId = oldComponentToNewComponentMapping[_parentId]; + + parentId = `${mappedParentId}-${childTabId}`; + } else { + parentId = oldComponentToNewComponentMapping[parentId]; + } + newComponent.name = component.name; newComponent.type = component.type; newComponent.pageId = savedPage.id; newComponent.properties = component.properties; newComponent.styles = component.styles; newComponent.validation = component.validation; - newComponent.parent = component.parent ? oldComponentToNewComponentMapping[component.parent] : null; + newComponent.parent = component.parent ? parentId : null; newComponent.page = savedPage; newComponents.push(newComponent);