[WIP] ReplaceBy in ContainerOperations.ts

This commit is contained in:
Carl Fuchs 2023-02-07 16:07:51 +01:00
parent e789300090
commit 1a9224b768

View file

@ -8,7 +8,7 @@ import Swal from 'sweetalert2';
import { PropertyType } from '../../../Enums/PropertyType'; import { PropertyType } from '../../../Enums/PropertyType';
import { TransformX, TransformY } from '../../../utils/svg'; import { TransformX, TransformY } from '../../../utils/svg';
import { Orientation } from '../../../Enums/Orientation'; import { Orientation } from '../../../Enums/Orientation';
import { AddContainerToSelectedContainer } from './AddContainer'; import { AddContainers } from './AddContainer';
import { IConfiguration } from '../../../Interfaces/IConfiguration'; import { IConfiguration } from '../../../Interfaces/IConfiguration';
/** /**
@ -130,28 +130,36 @@ export function ReplaceByContainer(
const history = GetCurrentHistory(fullHistory, historyCurrentStep); const history = GetCurrentHistory(fullHistory, historyCurrentStep);
const current = history[history.length - 1]; const current = history[history.length - 1];
const historyDelete = DeleteContainer(containerId, fullHistory, historyCurrentStep); const containerToReplace = FindContainerById(current.containers, containerId);
const currentDelete = historyDelete[historyDelete.length - 1]; if (containerToReplace === undefined) {
const selectedContainer = FindContainerById(currentDelete.containers, currentDelete.selectedContainerId); return history;
if (selectedContainer != null) { }
const historyAdd = AddContainerToSelectedContainer(newContainerId, selectedContainer, configuration, fullHistory, historyCurrentStep); const containerParent = FindContainerById(current.containers,containerToReplace.properties.parentId);
if (containerParent=== undefined) {
return history;
}
const historyAdd = AddContainers(containerParent.children.indexOf(containerId), [{ Type: newContainerId }], containerParent.properties.id, configuration, fullHistory, historyCurrentStep);
// Copy des possibles enfants
if (historyAdd.newContainers[0] === undefined) {
return history;
}
historyAdd.newContainers[0].children = containerToReplace.children;
const currentAdd = historyAdd[historyAdd.length - 1]; const historyDelete = DeleteContainer(containerId, historyAdd.history, historyCurrentStep + 1);
const currentDelete = historyDelete[historyDelete.length - 1];
fullHistory.push({ fullHistory.push({
lastAction: `Replace ${containerId} by ${newContainerId}`, lastAction: `Replace ${containerId} by ${newContainerId}`,
mainContainer: currentAdd.mainContainer, mainContainer: currentDelete.mainContainer,
containers: currentAdd.containers, containers: currentDelete.containers,
selectedContainerId: currentAdd.selectedContainerId, selectedContainerId: currentDelete.selectedContainerId,
typeCounters: Object.assign({}, currentAdd.typeCounters), typeCounters: Object.assign({}, currentDelete.typeCounters),
symbols: current.symbols, symbols: current.symbols,
selectedSymbolId: current.selectedSymbolId selectedSymbolId: current.selectedSymbolId
}); });
return fullHistory; return fullHistory;
} }
return history;
}
/** /**
* Returns the next container that will be selected * Returns the next container that will be selected