Merged PR 216: Deprecate parent from IContainerModel for FindContainerById

This commit is contained in:
Eric Nguyen 2022-10-17 16:01:06 +00:00
parent d40cd8cf8e
commit b4eba6bb9b
19 changed files with 97 additions and 109 deletions

View file

@ -57,9 +57,10 @@ export function DeleteContainer(
throw new Error(`[DeleteContainer] Tried to delete a container that is not present in the main container: ${containerId}`);
}
const parent = FindContainerById(containers, container.properties.parentId);
if (container === mainContainerClone ||
container.parent === undefined ||
container.parent === null) {
parent === undefined ||
parent === null) {
Swal.fire({
title: 'Oops...',
text: 'Deleting the main container is not allowed!',
@ -75,10 +76,10 @@ export function DeleteContainer(
const newSymbols = structuredClone(current.symbols);
UnlinkContainerFromSymbols(containers, newSymbols, container);
const index = container.parent.children.indexOf(container.properties.id);
const index = parent.children.indexOf(container.properties.id);
const success = containers.delete(container.properties.id);
if (index > -1 && success) {
container.parent.children.splice(index, 1);
parent.children.splice(index, 1);
} else {
throw new Error('[DeleteContainer] Could not find container among parent\'s children');
}
@ -90,7 +91,7 @@ export function DeleteContainer(
const selectedContainerId = GetSelectedContainerOnDelete(
containers,
current.selectedContainerId,
container.parent,
parent,
index
);
@ -202,12 +203,8 @@ export function OnPropertyChange(
*/
export function SortChildren(
containers: Map<string, IContainerModel>,
parent: IContainerModel | null | undefined
parent: IContainerModel
): void {
if (parent === null || parent === undefined) {
return;
}
const isHorizontal = parent.properties.orientation === Orientation.Horizontal;
const children = parent.children;
@ -293,7 +290,10 @@ function SetContainer(
);
// sort the children list by their position
SortChildren(containers, container.parent);
const parent = FindContainerById(containers, container.properties.parentId);
if (parent !== null && parent !== undefined) {
SortChildren(containers, parent);
}
// Apply special behaviors: rigid, flex, symbol, anchor
ApplyBehaviors(containers, container, symbols);