Implement Insert in SetContainerList
This commit is contained in:
parent
0d761e6a41
commit
e63b2779e1
3 changed files with 94 additions and 35 deletions
|
@ -201,9 +201,12 @@ function HandleSetContainerList(
|
|||
const addingBehavior = response.AddingBehavior ?? action.AddingBehavior;
|
||||
const current = GetCurrentHistoryState(history, historyCurrentStep);
|
||||
const containers = current.containers;
|
||||
const parent = FindContainerById(containers, selectedContainer.properties.parentId);
|
||||
switch (addingBehavior) {
|
||||
case AddMethod.Insert:
|
||||
case AddMethod.Append:
|
||||
response.Containers.forEach(config => {
|
||||
config.AddMethod = config.AddMethod ?? addingBehavior;
|
||||
});
|
||||
setNewHistory(
|
||||
AddContainers(
|
||||
selectedContainer.children.length,
|
||||
|
@ -214,8 +217,6 @@ function HandleSetContainerList(
|
|||
historyCurrentStep
|
||||
));
|
||||
break;
|
||||
case AddMethod.Insert:
|
||||
throw new Error('Not yet supported');
|
||||
case AddMethod.Replace:
|
||||
setNewHistory(
|
||||
HandleReplace(
|
||||
|
@ -228,7 +229,8 @@ function HandleSetContainerList(
|
|||
)
|
||||
);
|
||||
break;
|
||||
case AddMethod.ReplaceParent:
|
||||
case AddMethod.ReplaceParent: {
|
||||
const parent = FindContainerById(containers, selectedContainer.properties.parentId);
|
||||
if (parent === undefined || parent === null) {
|
||||
Swal.fire({
|
||||
title: 'Error',
|
||||
|
@ -248,6 +250,7 @@ function HandleSetContainerList(
|
|||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,3 +296,46 @@ function HandleReplace(
|
|||
|
||||
return newHistoryBeforeDelete;
|
||||
}
|
||||
|
||||
function HandleInsert(
|
||||
containers: Map<string, IContainerModel>,
|
||||
selectedContainer: IContainerModel,
|
||||
response: ISetContainerListResponse,
|
||||
configuration: IConfiguration,
|
||||
history: IHistoryState[],
|
||||
historyCurrentStep: number
|
||||
): IHistoryState[] {
|
||||
const parent = FindContainerById(containers, selectedContainer.properties.id);
|
||||
if (parent === undefined || parent === null) {
|
||||
throw new Error('[InsertContainer] Cannot insert in a container that does not exists');
|
||||
}
|
||||
|
||||
const index = parent.children.indexOf(selectedContainer.properties.id);
|
||||
|
||||
const newHistoryAfterDelete = DeleteContainer(
|
||||
selectedContainer.properties.id,
|
||||
history,
|
||||
historyCurrentStep
|
||||
);
|
||||
|
||||
const newHistoryBeforeDelete = AddContainers(
|
||||
index,
|
||||
response.Containers,
|
||||
selectedContainer.properties.parentId,
|
||||
configuration,
|
||||
newHistoryAfterDelete,
|
||||
newHistoryAfterDelete.length - 1
|
||||
);
|
||||
|
||||
// Remove AddContainers from history
|
||||
if (import.meta.env.PROD) {
|
||||
newHistoryBeforeDelete.splice(newHistoryBeforeDelete.length - 2, 1);
|
||||
}
|
||||
|
||||
// Rename the last action by Replace
|
||||
const types = response.Containers.map(container => container.Type);
|
||||
newHistoryBeforeDelete[newHistoryBeforeDelete.length - 1].lastAction =
|
||||
`Replace ${selectedContainer.properties.id} by [${types.join(', ')}]`;
|
||||
|
||||
return newHistoryBeforeDelete;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue