Allow AddContainers to extends the default config
This commit is contained in:
parent
569d21ee9b
commit
6a3ddea763
3 changed files with 16 additions and 12 deletions
|
@ -190,7 +190,7 @@ export function AddContainerToSelectedContainer(
|
||||||
*/
|
*/
|
||||||
export function AddContainers(
|
export function AddContainers(
|
||||||
index: number,
|
index: number,
|
||||||
types: string[],
|
availableContainers: IAvailableContainer[],
|
||||||
parentId: string,
|
parentId: string,
|
||||||
configuration: IConfiguration,
|
configuration: IConfiguration,
|
||||||
fullHistory: IHistoryState[],
|
fullHistory: IHistoryState[],
|
||||||
|
@ -218,15 +218,19 @@ export function AddContainers(
|
||||||
const containerIds: string[] = [];
|
const containerIds: string[] = [];
|
||||||
|
|
||||||
// Iterate over the containers
|
// Iterate over the containers
|
||||||
types.forEach((type, typeIndex) => {
|
availableContainers.forEach((availableContainer, typeIndex) => {
|
||||||
// Get the preset properties from the API
|
// Get the preset properties from the API
|
||||||
const containerConfig = configuration.AvailableContainers
|
const type = availableContainer.Type;
|
||||||
|
|
||||||
|
const defaultConfig = configuration.AvailableContainers
|
||||||
.find(option => option.Type === type);
|
.find(option => option.Type === type);
|
||||||
|
|
||||||
if (containerConfig === undefined) {
|
if (defaultConfig === undefined) {
|
||||||
throw new Error(`[AddContainer] Object type not found. Found: ${type}`);
|
throw new Error(`[AddContainer] Object type not found among default config. Found: ${type}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const containerConfig = Object.assign(defaultConfig, availableContainer);
|
||||||
|
|
||||||
// Default margin
|
// Default margin
|
||||||
const left: number = containerConfig.Margin?.left ?? 0;
|
const left: number = containerConfig.Margin?.left ?? 0;
|
||||||
const bottom: number = containerConfig.Margin?.bottom ?? 0;
|
const bottom: number = containerConfig.Margin?.bottom ?? 0;
|
||||||
|
@ -330,7 +334,8 @@ export function AddContainer(
|
||||||
// just call AddContainers with an array on a single element
|
// just call AddContainers with an array on a single element
|
||||||
return AddContainers(
|
return AddContainers(
|
||||||
index,
|
index,
|
||||||
[type],
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
[{ Type: type }],
|
||||||
parentId,
|
parentId,
|
||||||
configuration,
|
configuration,
|
||||||
fullHistory,
|
fullHistory,
|
||||||
|
|
|
@ -85,7 +85,7 @@ function HandleSetContainerList(
|
||||||
setNewHistory(
|
setNewHistory(
|
||||||
AddContainers(
|
AddContainers(
|
||||||
selectedContainer.children.length,
|
selectedContainer.children.length,
|
||||||
response.Containers.map(container => container.Type),
|
response.Containers,
|
||||||
selectedContainer.properties.id,
|
selectedContainer.properties.id,
|
||||||
configuration,
|
configuration,
|
||||||
history,
|
history,
|
||||||
|
@ -121,8 +121,6 @@ function HandleReplace(
|
||||||
|
|
||||||
const index = selectedContainer.parent.children.indexOf(selectedContainer);
|
const index = selectedContainer.parent.children.indexOf(selectedContainer);
|
||||||
|
|
||||||
const types = response.Containers.map(container => container.Type);
|
|
||||||
|
|
||||||
const newHistoryAfterDelete = DeleteContainer(
|
const newHistoryAfterDelete = DeleteContainer(
|
||||||
selectedContainer.properties.id,
|
selectedContainer.properties.id,
|
||||||
history,
|
history,
|
||||||
|
@ -131,7 +129,7 @@ function HandleReplace(
|
||||||
|
|
||||||
const newHistoryBeforeDelete = AddContainers(
|
const newHistoryBeforeDelete = AddContainers(
|
||||||
index,
|
index,
|
||||||
types,
|
response.Containers,
|
||||||
selectedContainer.properties.parentId,
|
selectedContainer.properties.parentId,
|
||||||
configuration,
|
configuration,
|
||||||
newHistoryAfterDelete,
|
newHistoryAfterDelete,
|
||||||
|
@ -144,6 +142,7 @@ function HandleReplace(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename the last action by Replace
|
// Rename the last action by Replace
|
||||||
|
const types = response.Containers.map(container => container.Type);
|
||||||
newHistoryBeforeDelete[newHistoryBeforeDelete.length - 1].lastAction =
|
newHistoryBeforeDelete[newHistoryBeforeDelete.length - 1].lastAction =
|
||||||
`Replace ${selectedContainer.properties.id} by [${types.join(', ')}]`;
|
`Replace ${selectedContainer.properties.id} by [${types.join(', ')}]`;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { IAvailableSymbol } from './IAvailableSymbol';
|
||||||
|
|
||||||
/** Model of configuration for the application to configure it */
|
/** Model of configuration for the application to configure it */
|
||||||
export interface IConfiguration {
|
export interface IConfiguration {
|
||||||
AvailableContainers: IAvailableContainer[]
|
AvailableContainers: IAvailableContainer[] // TODO: Use a Map<string, IAvailableContainer>
|
||||||
AvailableSymbols: IAvailableSymbol[]
|
AvailableSymbols: IAvailableSymbol[] // TODO: Use a Map<string, IAvailableContainer>
|
||||||
MainContainer: IAvailableContainer
|
MainContainer: IAvailableContainer
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue