Skip to content

Commit f8ec6b7

Browse files
authored
Merge pull request #2036 from umbraco/v14/bugfix/block-grid-allow-at-root-checked
Make allowAtRoot preset for Block Grid Types
2 parents 19bac46 + 4324363 commit f8ec6b7

File tree

13 files changed

+53
-31
lines changed

13 files changed

+53
-31
lines changed

src/packages/block/block-grid/components/block-grid-area-config-entry/workspace/block-grid-area-type-workspace.context.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { UmbBlockGridTypeAreaType } from '../../../types.js';
22
import type { UmbPropertyDatasetContext } from '@umbraco-cms/backoffice/property';
33
import { UMB_PROPERTY_CONTEXT } from '@umbraco-cms/backoffice/property';
4-
import {
5-
type UmbInvariantDatasetWorkspaceContext,
6-
type UmbRoutableWorkspaceContext,
7-
type UmbWorkspaceContext,
8-
UmbWorkspaceRouteManager,
4+
import type {
5+
UmbInvariantDatasetWorkspaceContext,
6+
UmbRoutableWorkspaceContext,
7+
UmbWorkspaceContext,
98
} from '@umbraco-cms/backoffice/workspace';
109
import {
1110
UmbSubmittableWorkspaceContextBase,

src/packages/block/block-grid/property-editors/block-grid-type-configuration/property-editor-ui-block-grid-type-configuration.element.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ import {
1717
} from '@umbraco-cms/backoffice/property-editor';
1818
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
1919
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
20-
import { UMB_BLOCK_GRID_TYPE, type UmbBlockGridTypeGroupType } from '@umbraco-cms/backoffice/block-grid';
20+
import { UMB_BLOCK_GRID_TYPE, UMB_BLOCK_GRID_TYPE_WORKSPACE_MODAL, type UmbBlockGridTypeGroupType } from '@umbraco-cms/backoffice/block-grid';
2121
import type { UUIInputEvent } from '@umbraco-cms/backoffice/external/uui';
2222
import {
2323
UMB_PROPERTY_CONTEXT,
2424
UMB_PROPERTY_DATASET_CONTEXT,
2525
type UmbPropertyDatasetContext,
2626
} from '@umbraco-cms/backoffice/property';
27-
import { UMB_WORKSPACE_MODAL } from '@umbraco-cms/backoffice/modal';
2827
import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
2928
import { UmbSorterController } from '@umbraco-cms/backoffice/sorter';
3029

@@ -61,8 +60,8 @@ export class UmbPropertyEditorUIBlockGridTypeConfigurationElement
6160

6261
#datasetContext?: UmbPropertyDatasetContext;
6362
#blockTypeWorkspaceModalRegistration?: UmbModalRouteRegistrationController<
64-
typeof UMB_WORKSPACE_MODAL.DATA,
65-
typeof UMB_WORKSPACE_MODAL.VALUE
63+
typeof UMB_BLOCK_GRID_TYPE_WORKSPACE_MODAL.DATA,
64+
typeof UMB_BLOCK_GRID_TYPE_WORKSPACE_MODAL.VALUE
6665
>;
6766

6867
#value: Array<UmbBlockTypeWithGroupKey> = [];
@@ -105,11 +104,8 @@ export class UmbPropertyEditorUIBlockGridTypeConfigurationElement
105104
this.#observeBlockGroups();
106105
});
107106

108-
this.#blockTypeWorkspaceModalRegistration = new UmbModalRouteRegistrationController(this, UMB_WORKSPACE_MODAL)
107+
this.#blockTypeWorkspaceModalRegistration = new UmbModalRouteRegistrationController(this, UMB_BLOCK_GRID_TYPE_WORKSPACE_MODAL)
109108
.addAdditionalPath(UMB_BLOCK_GRID_TYPE)
110-
.onSetup(() => {
111-
return { data: { entityType: UMB_BLOCK_GRID_TYPE, preset: {} }, modal: { size: 'large' } };
112-
})
113109
.observeRouteBuilder((routeBuilder) => {
114110
const newpath = routeBuilder({});
115111
this._workspacePath = newpath;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { UMB_BLOCK_GRID_TYPE, type UmbBlockGridTypeModel } from '../types.js';
2+
import type { UmbWorkspaceModalData, UmbWorkspaceModalValue } from '@umbraco-cms/backoffice/modal';
3+
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
4+
5+
export type UmbBlockGridTypeWorkspaceData = UmbWorkspaceModalData<UmbBlockGridTypeModel>;
6+
7+
export const UMB_BLOCK_GRID_TYPE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockGridTypeWorkspaceData, UmbWorkspaceModalValue>(
8+
'Umb.Modal.Workspace',
9+
{
10+
modal: {
11+
type: 'sidebar',
12+
size: 'large',
13+
},
14+
data: { entityType: UMB_BLOCK_GRID_TYPE, preset: {allowAtRoot: true} },
15+
},
16+
// Recast the type, so the entityType data prop is not required:
17+
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType' | 'preset'>, UmbWorkspaceModalValue>;

src/packages/block/block-grid/workspace/block-grid-workspace.modal-token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export const UMB_BLOCK_GRID_WORKSPACE_MODAL = new UmbModalToken<UmbBlockGridWork
1818
size: 'medium',
1919
},
2020
data: { entityType: 'block', preset: {}, originData: { index: -1, parentUnique: null } },
21-
// Recast the type, so the entityType data prop is not required:
2221
},
22+
// Recast the type, so the entityType data prop is not required:
2323
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbWorkspaceModalValue>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const UMB_BLOCK_GRID_TYPE_WORKSPACE_ALIAS = 'Umb.Workspace.BlockGridType';
22
export * from './block-grid-workspace.modal-token.js';
3+
export * from './block-grid-type-workspace.modal-token.js';

src/packages/block/block-list/workspace/block-list-workspace.modal-token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export const UMB_BLOCK_LIST_WORKSPACE_MODAL = new UmbModalToken<UmbBlockListWork
1616
size: 'medium',
1717
},
1818
data: { entityType: 'block', preset: {}, originData: { index: -1 } },
19-
// Recast the type, so the entityType data prop is not required:
2019
},
20+
// Recast the type, so the entityType data prop is not required:
2121
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbWorkspaceModalValue>;

src/packages/block/block-rte/workspace/block-rte-workspace.modal-token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorksp
1212
size: 'medium',
1313
},
1414
data: { entityType: 'block', preset: {}, originData: {} },
15-
// Recast the type, so the entityType data prop is not required:
1615
},
16+
// Recast the type, so the entityType data prop is not required:
1717
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbWorkspaceModalValue>;

src/packages/block/block-type/workspace/block-type-workspace.context.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
UmbSubmittableWorkspaceContextBase,
1111
UmbInvariantWorkspacePropertyDatasetContext,
1212
UmbWorkspaceIsNewRedirectController,
13-
UmbWorkspaceRouteManager,
1413
} from '@umbraco-cms/backoffice/workspace';
1514
import { UmbArrayState, UmbObjectState, appendToFrozenArray } from '@umbraco-cms/backoffice/observable-api';
1615
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
@@ -99,12 +98,22 @@ export class UmbBlockTypeWorkspaceContext<BlockTypeData extends UmbBlockTypeWith
9998

10099
async create(contentElementTypeId: string, groupKey?: string | null) {
101100
this.resetState();
102-
//Only set groupKey property if it exists
103-
const data: BlockTypeData = {
104-
contentElementTypeKey: contentElementTypeId,
105-
...(groupKey && { groupKey: groupKey }),
101+
102+
103+
let data: BlockTypeData = {
104+
contentElementTypeKey: contentElementTypeId
106105
} as BlockTypeData;
107106

107+
// If we have a modal context, we blend in the modal preset data: [NL]
108+
if (this.modalContext) {
109+
data = { ...data, ...this.modalContext.data.preset };
110+
}
111+
112+
// Only set groupKey property if it has been parsed to this method
113+
if (groupKey) {
114+
data.groupKey = groupKey;
115+
}
116+
108117
this.setIsNew(true);
109118
this.#data.setValue(data);
110119
return { data };

src/packages/block/block/workspace/block-workspace.modal-token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export const UMB_BLOCK_WORKSPACE_MODAL = new UmbModalToken<UmbBlockWorkspaceData
1313
size: 'large',
1414
},
1515
data: { entityType: 'block', preset: {}, originData: {} },
16-
// Recast the type, so the entityType data prop is not required:
1716
},
17+
// Recast the type, so the entityType data prop is not required:
1818
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbWorkspaceModalValue>;

src/packages/core/modal/context/modal.context.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type UmbModalContextClassArgs<
2626

2727
// TODO: consider splitting this into two separate handlers
2828
export class UmbModalContext<
29-
ModalPreset extends { [key: string]: any } = { [key: string]: any },
29+
ModalData extends { [key: string]: any } = { [key: string]: any },
3030
ModalValue = any,
3131
> extends UmbControllerBase {
3232
//
@@ -35,19 +35,19 @@ export class UmbModalContext<
3535
#submitRejecter?: (reason?: UmbModalRejectReason) => void;
3636

3737
public readonly key: string;
38-
public readonly data: ModalPreset;
38+
public readonly data: ModalData;
3939
public readonly type: UmbModalType = 'dialog';
4040
public readonly size: UUIModalSidebarSize = 'small';
4141
public readonly backdropBackground?: string;
4242
public readonly router: IRouterSlot | null = null;
43-
public readonly alias: string | UmbModalToken<ModalPreset, ModalValue>;
43+
public readonly alias: string | UmbModalToken<ModalData, ModalValue>;
4444

4545
#value;
4646
public readonly value;
4747

4848
constructor(
4949
host: UmbControllerHost,
50-
modalAlias: string | UmbModalToken<ModalPreset, ModalValue>,
50+
modalAlias: string | UmbModalToken<ModalData, ModalValue>,
5151
args: UmbModalContextClassArgs<UmbModalToken>,
5252
) {
5353
super(host);
@@ -69,9 +69,9 @@ export class UmbModalContext<
6969
this.data = Object.freeze(
7070
// If we have both data and defaultData perform a deep merge
7171
args.data && defaultData
72-
? (umbDeepMerge(args.data as UmbDeepPartialObject<ModalPreset>, defaultData) as ModalPreset)
72+
? (umbDeepMerge(args.data as UmbDeepPartialObject<ModalData>, defaultData) as ModalData)
7373
: // otherwise pick one of them:
74-
(args.data as ModalPreset) ?? defaultData,
74+
(args.data as ModalData) ?? defaultData,
7575
);
7676

7777
const initValue =

0 commit comments

Comments
 (0)