Skip to content

Commit

Permalink
Editor: Deleting elements and groups at the same time throws error
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofmferrao committed Aug 27, 2024
1 parent 8be002a commit 0840c5b
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions ui/src/layout-editor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,11 +1530,11 @@ lD.deleteObject = function(
* @param {boolean=} showConfirmationModal
*/
lD.deleteMultipleObjects = function(showConfirmationModal = true) {
const deleteElementsOrGroupElements = function(
const deleteElements = function(
itemsArray,
type = 'elements',
) {
let auxWidget = null;
let auxWidgetId = null;
itemsArray.each((idx, item) => {
const itemId = $(item).attr('id');
const widgetId = $(item).data('widgetId');
Expand All @@ -1552,8 +1552,11 @@ lD.deleteMultipleObjects = function(showConfirmationModal = true) {
)
);

// Get parent widget if doesn't exist or we need to save
// Get parent widget if doesn't exist
// if widget is a new one
// or we need to save
if (
widgetFullId != auxWidgetId ||
!auxWidget ||
save
) {
Expand All @@ -1562,26 +1565,18 @@ lD.deleteMultipleObjects = function(showConfirmationModal = true) {
widgetFullId,
'canvas',
);
}

// Delete element from widget
if (type === 'elements') {
auxWidget.removeElement(
itemId,
{
save: save,
reload: false,
},
);
} else {
auxWidget.removeElementGroup(
itemId,
{
save: save,
reload: false,
},
);
auxWidgetId = widgetFullId;
}

// Delete elements from widget
auxWidget.removeElement(
itemId,
{
save: save,
reload: false,
},
);
});
};

Expand Down Expand Up @@ -1616,17 +1611,13 @@ lD.deleteMultipleObjects = function(showConfirmationModal = true) {
return;
}

// First delete elements if they exist
const $elementsToBeDeleted =
// Get elements to be deleted
let $elementsToBeDeleted =
lD.viewer.DOMObject.find('.selected.designer-element').sort((a, b) => {
return Number($(b).data('widgetId')) - Number($(a).data('widgetId'));
});

if ($elementsToBeDeleted.length > 0) {
deleteElementsOrGroupElements($elementsToBeDeleted);
}

// Then delete element groups
// Get groups to be deleted
const $elementGroupsToBeDeleted =
lD.viewer.DOMObject.find('.selected.designer-element-group')
.sort((a, b) => {
Expand All @@ -1636,13 +1627,22 @@ lD.deleteMultipleObjects = function(showConfirmationModal = true) {
);
});

// Grab elements from the groups
if ($elementGroupsToBeDeleted.length > 0) {
deleteElementsOrGroupElements(
$elementGroupsToBeDeleted,
'elementGroups',
// Add elements from the groups to all elements to be deleted
$elementsToBeDeleted = $elementsToBeDeleted.add(
$elementGroupsToBeDeleted.find('.designer-element').sort((a, b) => {
return Number($(b).data('widgetId')) - Number($(a).data('widgetId'));
}),
);
}

// Delete elements (groups will be automatically deleted
// if all elements from a group are also deleted)
if ($elementsToBeDeleted.length > 0) {
deleteElements($elementsToBeDeleted);
}

// Finally, delete regions one by one
const $regionsToBeDeleted =
lD.viewer.DOMObject.find('.selected.designer-region');
Expand Down

0 comments on commit 0840c5b

Please sign in to comment.