Merge pull request #11101 from ToolJet/fix-refactor-copy-pasting-tab

Fixes tabs copy pasting and component deletion inside container
This commit is contained in:
Johnson Cherian 2024-10-24 13:30:10 +05:30 committed by GitHub
commit e71843a494
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -211,6 +211,7 @@ export const getAllChildComponents = (allComponents, parentId) => {
if (componentParentId === parentId) {
let childComponent = deepClone(allComponents[componentId]);
childComponent.componentId = componentId;
childComponents.push(childComponent);
// Recursively find children of the current child component
@ -240,7 +241,10 @@ export const copyComponents = ({ isCut = false, isCloning = false }) => {
const currentPageId = useStore.getState().getCurrentPageId();
// if parent is selected, then remove the parent from the selected components
const filteredSelectedComponents = selectedComponents.filter((selectedComponent) => {
const parentComponentId = selectedComponent?.component?.parent;
const parentComponentId = isChildOfTabsOrCalendar(selectedComponent, allComponents)
? selectedComponent.component.parent.split('-').slice(0, -1).join('-')
: selectedComponent?.component?.parent;
if (parentComponentId) {
// Check if the parent component is also selected
const isParentSelected = selectedComponents.some((comp) => comp.id === parentComponentId);
@ -327,8 +331,8 @@ const updateComponentLayout = (components, parentId, isCut = false) => {
const isChildOfTabsOrCalendar = (component, allComponents = [], componentParentId = undefined) => {
const parentId = componentParentId ?? component.component?.parent?.match(/([a-fA-F0-9-]{36})-(.+)/)?.[1];
const parentComponent = allComponents?.[parentId];
const parentComponent = allComponents.find((comp) => comp.componentId === parentId);
if (parentComponent) {
return parentComponent.component.component === 'Tabs' || parentComponent.component.component === 'Calendar';
}

View file

@ -1377,7 +1377,7 @@ export const createComponentsSlice = (set, get) => ({
const component = {
component: allComponents?.[componentId]?.component,
layouts: allComponents?.[componentId]?.layouts,
parent: allComponents?.[componentId]?.parent,
parent: allComponents?.[componentId]?.component?.parent,
id: componentId,
};
_selected.push(component);