From 2d95fd745814c8865dacbff33f8e09b4d2f4bc3d Mon Sep 17 00:00:00 2001 From: arpitnath Date: Fri, 15 Sep 2023 14:33:51 +0530 Subject: [PATCH] fixes: components with default children --- frontend/src/Editor/EditorFunc.jsx | 9 --------- frontend/src/Editor/SubContainer.jsx | 7 +++++-- frontend/src/_stores/utils.js | 12 ++++++++++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/frontend/src/Editor/EditorFunc.jsx b/frontend/src/Editor/EditorFunc.jsx index 53be7f2ef7..ce0853c6d9 100644 --- a/frontend/src/Editor/EditorFunc.jsx +++ b/frontend/src/Editor/EditorFunc.jsx @@ -956,15 +956,6 @@ const EditorComponent = (props) => { appDefinitionChanged(updatedAppDefinition, { skipAutoSave: true, componentDefinitionChanged: true, ...props }); } } - - // Other actions can be performed here if needed, like autoSave, ymap, etc. - // computeComponentState(updatedAppDefinition.pages[currentPageId]?.components); - // autoSave(); - // props.ymap?.set('appDef', { - // newDefinition: updatedAppDefinition, - // editingVersionId: props.editingVersion?.id, - // }); - // } }; const removeComponent = (componentId) => { diff --git a/frontend/src/Editor/SubContainer.jsx b/frontend/src/Editor/SubContainer.jsx index 374e48face..ef126f0561 100644 --- a/frontend/src/Editor/SubContainer.jsx +++ b/frontend/src/Editor/SubContainer.jsx @@ -186,8 +186,11 @@ export const SubContainer = ({ ); _.set(childrenBoxes, newComponent.id, { - component: newComponent.component, - parent: parentComponent.component === 'Tabs' ? parentId + '-' + tab : parentId, + component: { + ...newComponent.component, + parent: parentComponent.component === 'Tabs' ? parentId + '-' + tab : parentId, + }, + layouts: { [currentLayout]: { ...layout, diff --git a/frontend/src/_stores/utils.js b/frontend/src/_stores/utils.js index ea2932a5a0..14ffcbac15 100644 --- a/frontend/src/_stores/utils.js +++ b/frontend/src/_stores/utils.js @@ -205,12 +205,24 @@ const computeComponentDiff = (appDiff, currentPageId, opts) => { const currentPageComponents = appDiff?.pages[currentPageId]?.components; updateDiff = _.toPairs(currentPageComponents ?? []).reduce((result, [id, component]) => { + if (_.keys(component).length === 1 && component.withDefaultChildren !== undefined) { + return result; + } + const componentMeta = componentTypes.find((comp) => comp.component === component.component.component); const metaDiff = diff(componentMeta, component.component); result[id] = _.defaultsDeep(metaDiff, defaultComponent); + if (metaDiff.definition && !_.isEmpty(metaDiff.definition)) { + const metaAttributes = _.keys(metaDiff.definition); + + metaAttributes.forEach((attribute) => { + result[id][attribute] = metaDiff.definition[attribute]; + }); + } + result[id].type = componentMeta.component; result[id].parent = component.component.parent ?? null; result[id].layouts = appDiff.pages[currentPageId].components[id].layouts;