Skip to content

Commit a9bf900

Browse files
authoredJan 21, 2025··
enable areas to be undefined (#18057)
1 parent 800873c commit a9bf900

File tree

5 files changed

+54
-45
lines changed

5 files changed

+54
-45
lines changed
 

‎src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ function resolvePlacementAsBlockGrid(
3131
args: UmbSorterResolvePlacementArgs<UmbBlockGridLayoutModel, UmbBlockGridEntryElement>,
3232
) {
3333
// If this has areas, we do not want to move, unless we are at the edge
34-
if (args.relatedModel.areas?.length > 0 && isWithinRect(args.pointerX, args.pointerY, args.relatedRect, -10)) {
34+
if (
35+
args.relatedModel.areas &&
36+
args.relatedModel.areas.length > 0 &&
37+
isWithinRect(args.pointerX, args.pointerY, args.relatedRect, -10)
38+
) {
3539
return null;
3640
}
3741

‎src/Umbraco.Web.UI.Client/src/packages/block/block-grid/context/block-grid-manager.context.ts

+35-32
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,15 @@ export class UmbBlockGridManagerContext<
132132
// Lets check if we found the right parent layout entry:
133133
if (currentEntry.contentKey === parentId) {
134134
// Append the layout entry to be inserted and unfreeze the rest of the data:
135-
const areas = currentEntry.areas.map((x) =>
136-
x.key === areaKey
137-
? {
138-
...x,
139-
items: pushAtToUniqueArray([...x.items], insert, (x) => x.contentKey === insert.contentKey, index),
140-
}
141-
: x,
142-
);
135+
const areas =
136+
currentEntry.areas?.map((x) =>
137+
x.key === areaKey
138+
? {
139+
...x,
140+
items: pushAtToUniqueArray([...x.items], insert, (x) => x.contentKey === insert.contentKey, index),
141+
}
142+
: x,
143+
) ?? [];
143144
return appendToFrozenArray(
144145
entries,
145146
{
@@ -150,31 +151,33 @@ export class UmbBlockGridManagerContext<
150151
);
151152
}
152153
// Otherwise check if any items of the areas are the parent layout entry we are looking for. We do so based on parentId, recursively:
153-
let y: number = currentEntry.areas?.length;
154-
while (y--) {
155-
// Recursively ask the items of this area to insert the layout entry, if something returns there was a match in this branch. [NL]
156-
const correctedAreaItems = this.#appendLayoutEntryToArea(
157-
insert,
158-
currentEntry.areas[y].items,
159-
parentId,
160-
areaKey,
161-
index,
162-
);
163-
if (correctedAreaItems) {
164-
// This area got a corrected set of items, lets append those to the area and unfreeze the surrounding data:
165-
const area = currentEntry.areas[y];
166-
return appendToFrozenArray(
167-
entries,
168-
{
169-
...currentEntry,
170-
areas: appendToFrozenArray(
171-
currentEntry.areas,
172-
{ ...area, items: correctedAreaItems },
173-
(z) => z.key === area.key,
174-
),
175-
},
176-
(x) => x.contentKey === currentEntry.contentKey,
154+
if (currentEntry.areas) {
155+
let y: number = currentEntry.areas.length;
156+
while (y--) {
157+
// Recursively ask the items of this area to insert the layout entry, if something returns there was a match in this branch. [NL]
158+
const correctedAreaItems = this.#appendLayoutEntryToArea(
159+
insert,
160+
currentEntry.areas[y].items,
161+
parentId,
162+
areaKey,
163+
index,
177164
);
165+
if (correctedAreaItems) {
166+
// This area got a corrected set of items, lets append those to the area and unfreeze the surrounding data:
167+
const area = currentEntry.areas[y];
168+
return appendToFrozenArray(
169+
entries,
170+
{
171+
...currentEntry,
172+
areas: appendToFrozenArray(
173+
currentEntry.areas,
174+
{ ...area, items: correctedAreaItems },
175+
(z) => z.key === area.key,
176+
),
177+
},
178+
(x) => x.contentKey === currentEntry.contentKey,
179+
);
180+
}
178181
}
179182
}
180183
}

‎src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-value-cloner/property-value-cloner-block-grid.cloner.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe('UmbBlockGridPropertyValueCloner', () => {
162162

163163
testLayoutEntryNewKeyIsReflected(
164164
'fictive-content-type-2',
165-
result.value?.layout[UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS]?.[0].areas[0]?.items[0],
165+
result.value?.layout[UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS]?.[0].areas?.[0]?.items[0],
166166
result.value?.contentData,
167167
result.value?.settingsData,
168168
result.value?.expose,
@@ -175,7 +175,7 @@ describe('UmbBlockGridPropertyValueCloner', () => {
175175

176176
testLayoutEntryNewKeyIsReflected(
177177
'fictive-content-type-3',
178-
result.value?.layout[UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS]?.[0].areas[0]?.items[0].areas[0]?.items[0],
178+
result.value?.layout[UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS]?.[0].areas?.[0]?.items[0].areas[0]?.items[0],
179179
result.value?.contentData,
180180
result.value?.settingsData,
181181
result.value?.expose,

‎src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-value-cloner/property-value-cloner-block-grid.cloner.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ export class UmbBlockGridPropertyValueCloner extends UmbBlockPropertyValueCloner
1919
#cloneLayoutEntry = async (layout: UmbBlockGridLayoutModel): Promise<UmbBlockGridLayoutModel> => {
2020
// Clone the specific layout entry:
2121
const entryClone = await this._cloneBlock(layout);
22-
// And then clone the items of its areas:
23-
entryClone.areas = await Promise.all(
24-
entryClone.areas.map(async (area) => {
25-
return {
26-
...area,
27-
items: await Promise.all(area.items.map(this.#cloneLayoutEntry)),
28-
};
29-
}),
30-
);
22+
if (entryClone.areas) {
23+
// And then clone the items of its areas:
24+
entryClone.areas = await Promise.all(
25+
entryClone.areas.map(async (area) => {
26+
return {
27+
...area,
28+
items: await Promise.all(area.items.map(this.#cloneLayoutEntry)),
29+
};
30+
}),
31+
);
32+
}
3133
return entryClone;
3234
};
3335
}

‎src/Umbraco.Web.UI.Client/src/packages/block/block-grid/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface UmbBlockGridValueModel extends UmbBlockValueType<UmbBlockGridLa
5151
export interface UmbBlockGridLayoutModel extends UmbBlockLayoutBaseModel {
5252
columnSpan: number;
5353
rowSpan: number;
54-
areas: Array<UmbBlockGridLayoutAreaItemModel>;
54+
areas?: Array<UmbBlockGridLayoutAreaItemModel>;
5555
}
5656

5757
export interface UmbBlockGridLayoutAreaItemModel {

0 commit comments

Comments
 (0)
Please sign in to comment.