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(
|
||||
index: number,
|
||||
types: string[],
|
||||
availableContainers: IAvailableContainer[],
|
||||
parentId: string,
|
||||
configuration: IConfiguration,
|
||||
fullHistory: IHistoryState[],
|
||||
|
@ -218,15 +218,19 @@ export function AddContainers(
|
|||
const containerIds: string[] = [];
|
||||
|
||||
// Iterate over the containers
|
||||
types.forEach((type, typeIndex) => {
|
||||
availableContainers.forEach((availableContainer, typeIndex) => {
|
||||
// Get the preset properties from the API
|
||||
const containerConfig = configuration.AvailableContainers
|
||||
const type = availableContainer.Type;
|
||||
|
||||
const defaultConfig = configuration.AvailableContainers
|
||||
.find(option => option.Type === type);
|
||||
|
||||
if (containerConfig === undefined) {
|
||||
throw new Error(`[AddContainer] Object type not found. Found: ${type}`);
|
||||
if (defaultConfig === undefined) {
|
||||
throw new Error(`[AddContainer] Object type not found among default config. Found: ${type}`);
|
||||
}
|
||||
|
||||
const containerConfig = Object.assign(defaultConfig, availableContainer);
|
||||
|
||||
// Default margin
|
||||
const left: number = containerConfig.Margin?.left ?? 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
|
||||
return AddContainers(
|
||||
index,
|
||||
[type],
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
[{ Type: type }],
|
||||
parentId,
|
||||
configuration,
|
||||
fullHistory,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue