Fixes tabs copy pasting and component deletion inside container

This commit is contained in:
Nakul Nagargade 2024-10-24 13:10:18 +05:30
parent f51491df66
commit 026c7cfd12
3 changed files with 9 additions and 9 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,7 @@ const updateComponentLayout = (components, parentId, isCut = false) => {
const isChildOfTabsOrCalendar = (component, allComponents = [], componentParentId = undefined) => {
const parentId = componentParentId ?? component.component?.parent?.split('-').slice(0, -1).join('-');
const parentComponent = allComponents.find((comp) => comp.componentId === parentId);
const parentComponent = allComponents?.[parentId];
if (parentComponent) {
return parentComponent.component.component === 'Tabs' || parentComponent.component.component === 'Calendar';
}

View file

@ -19,13 +19,10 @@ const DesktopHeader = ({
isAppLoaded,
changeToDarkMode,
}) => {
const { editingVersion, showDarkModeToggle, isReleasedVersionId } = useStore(
const { showDarkModeToggle, isReleasedVersionId } = useStore(
(state) => ({
editingVersion: state?.editingVersion,
isReleasedVersionId: state?.releasedVersionId == state.editingVersion || state.isVersionReleased,
switchDarkMode: state.switchDarkMode,
isReleasedVersionId: state?.releasedVersionId == state.selectedVersion?.id || state.isVersionReleased,
showDarkModeToggle: state.globalSettings.appMode === 'auto' || !state.globalSettings.appMode,
appMode: state.globalSettings.appMode,
}),
shallow
);

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);