Skip to content

Commit 657c7c1

Browse files
nielslyngsoeiOvergaard
authored andcommitted
move workspace modal registration to each implementation
1 parent 726aeef commit 657c7c1

File tree

6 files changed

+81
-65
lines changed

6 files changed

+81
-65
lines changed

src/packages/block/block-grid/context/block-grid-entries.context.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { UmbBlockDataType } from '../../block/index.js';
22
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
3-
import { UMB_BLOCK_GRID_ENTRY_CONTEXT, type UmbBlockGridWorkspaceData } from '../index.js';
3+
import {
4+
UMB_BLOCK_GRID_ENTRY_CONTEXT,
5+
UMB_BLOCK_GRID_WORKSPACE_MODAL,
6+
type UmbBlockGridWorkspaceData,
7+
} from '../index.js';
48
import type { UmbBlockGridLayoutModel, UmbBlockGridTypeAreaType, UmbBlockGridTypeModel } from '../types.js';
59
import { UMB_BLOCK_GRID_MANAGER_CONTEXT } from './block-grid-manager.context-token.js';
610
import type { UmbBlockGridScalableContainerContext } from './block-grid-scale-manager/block-grid-scale-manager.controller.js';
@@ -21,6 +25,7 @@ export class UmbBlockGridEntriesContext
2125
{
2226
//
2327
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
28+
#workspaceModal: UmbModalRouteRegistrationController;
2429

2530
#parentEntry?: typeof UMB_BLOCK_GRID_ENTRY_CONTEXT.TYPE;
2631

@@ -66,13 +71,13 @@ export class UmbBlockGridEntriesContext
6671
setParentUnique(contentUdi: string | null) {
6772
this.#parentUnique = contentUdi;
6873
// Notice pathFolderName can be removed when we have switched to use a proper GUID/ID/KEY. [NL]
69-
this._workspaceModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
74+
this.#workspaceModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
7075
this.#catalogueModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
7176
}
7277

7378
setAreaKey(areaKey: string | null) {
7479
this.#areaKey = areaKey;
75-
this._workspaceModal.setUniquePathValue('areaKey', areaKey ?? 'null');
80+
this.#workspaceModal.setUniquePathValue('areaKey', areaKey ?? 'null');
7681
this.#catalogueModal.setUniquePathValue('areaKey', areaKey ?? 'null');
7782
this.#gotAreaKey();
7883
}
@@ -93,8 +98,6 @@ export class UmbBlockGridEntriesContext
9398
constructor(host: UmbControllerHost) {
9499
super(host, UMB_BLOCK_GRID_MANAGER_CONTEXT);
95100

96-
this._workspaceModal.addUniquePaths(['parentUnique', 'areaKey']);
97-
98101
this.consumeContext(UMB_BLOCK_GRID_ENTRY_CONTEXT, (blockGridEntry) => {
99102
this.#parentEntry = blockGridEntry;
100103
this.#gotBlockParentEntry(); // is not used at this point. [NL]
@@ -119,6 +122,24 @@ export class UmbBlockGridEntriesContext
119122
// TODO: Does it make any sense that this is a state? Check usage and confirm. [NL]
120123
this._catalogueRouteBuilderState.setValue(routeBuilder);
121124
});
125+
126+
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_GRID_WORKSPACE_MODAL)
127+
.addUniquePaths(['propertyAlias', 'variantId', 'parentUnique', 'areaKey'])
128+
.addAdditionalPath('block')
129+
.onSetup(() => {
130+
return {
131+
data: {
132+
entityType: 'block',
133+
preset: {},
134+
originData: { areaKey: this.#areaKey, parentUnique: this.#parentUnique },
135+
},
136+
modal: { size: 'medium' },
137+
};
138+
})
139+
.observeRouteBuilder((routeBuilder) => {
140+
const newPath = routeBuilder({});
141+
this._workspacePath.setValue(newPath);
142+
});
122143
}
123144

124145
protected _gotBlockManager() {
@@ -131,16 +152,17 @@ export class UmbBlockGridEntriesContext
131152
this._manager.propertyAlias,
132153
(alias) => {
133154
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
155+
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
134156
},
135157
'observePropertyAlias',
136158
);
137159

138160
this.observe(
139161
this._manager.variantId,
140162
(variantId) => {
141-
if (variantId) {
142-
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
143-
}
163+
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
164+
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
165+
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
144166
},
145167
'observePropertyAlias',
146168
);

src/packages/block/block-list/context/block-list-entries.context.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { UmbBlockDataType } from '../../block/index.js';
22
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
3-
import type { UmbBlockListWorkspaceData } from '../index.js';
3+
import { UMB_BLOCK_LIST_WORKSPACE_MODAL, type UmbBlockListWorkspaceData } from '../index.js';
44
import type { UmbBlockListLayoutModel, UmbBlockListTypeModel } from '../types.js';
55
import { UMB_BLOCK_LIST_MANAGER_CONTEXT } from './block-list-manager.context-token.js';
66
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
@@ -15,6 +15,7 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
1515
> {
1616
//
1717
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
18+
#workspaceModal: UmbModalRouteRegistrationController;
1819

1920
// We will just say its always allowed for list for now: [NL]
2021
public readonly canCreate = new UmbBooleanState(true).asObservable();
@@ -40,6 +41,17 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
4041
.observeRouteBuilder((routeBuilder) => {
4142
this._catalogueRouteBuilderState.setValue(routeBuilder);
4243
});
44+
45+
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_LIST_WORKSPACE_MODAL)
46+
.addUniquePaths(['propertyAlias', 'variantId'])
47+
.addAdditionalPath('block')
48+
.onSetup(() => {
49+
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
50+
})
51+
.observeRouteBuilder((routeBuilder) => {
52+
const newPath = routeBuilder({});
53+
this._workspacePath.setValue(newPath);
54+
});
4355
}
4456

4557
protected _gotBlockManager() {
@@ -64,16 +76,17 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
6476
this._manager.propertyAlias,
6577
(alias) => {
6678
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
79+
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
6780
},
6881
'observePropertyAlias',
6982
);
7083

7184
this.observe(
7285
this._manager.variantId,
7386
(variantId) => {
74-
if (variantId) {
75-
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
76-
}
87+
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
88+
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
89+
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
7790
},
7891
'observePropertyAlias',
7992
);

src/packages/block/block-rte/context/block-rte-entries.context.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { UmbBlockDataType } from '../../block/index.js';
22
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
3-
import type { UmbBlockRteWorkspaceData } from '../index.js';
43
import type { UmbBlockRteLayoutModel, UmbBlockRteTypeModel } from '../types.js';
4+
import {
5+
UMB_BLOCK_RTE_WORKSPACE_MODAL,
6+
type UmbBlockRteWorkspaceData,
7+
} from '../workspace/block-rte-workspace.modal-token.js';
58
import { UMB_BLOCK_RTE_MANAGER_CONTEXT } from './block-rte-manager.context-token.js';
69
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
710
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
@@ -15,6 +18,7 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
1518
> {
1619
//
1720
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
21+
#workspaceModal: UmbModalRouteRegistrationController;
1822

1923
// We will just say its always allowed for RTE for now: [NL]
2024
public readonly canCreate = new UmbBooleanState(true).asObservable();
@@ -38,6 +42,17 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
3842
.observeRouteBuilder((routeBuilder) => {
3943
this._catalogueRouteBuilderState.setValue(routeBuilder);
4044
});
45+
46+
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_RTE_WORKSPACE_MODAL)
47+
.addUniquePaths(['propertyAlias', 'variantId'])
48+
.addAdditionalPath('block')
49+
.onSetup(() => {
50+
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
51+
})
52+
.observeRouteBuilder((routeBuilder) => {
53+
const newPath = routeBuilder({});
54+
this._workspacePath.setValue(newPath);
55+
});
4156
}
4257

4358
protected _gotBlockManager() {
@@ -62,16 +77,17 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
6277
this._manager.propertyAlias,
6378
(alias) => {
6479
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
80+
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
6581
},
6682
'observePropertyAlias',
6783
);
6884

6985
this.observe(
7086
this._manager.variantId,
7187
(variantId) => {
72-
if (variantId) {
73-
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
74-
}
88+
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
89+
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
90+
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
7591
},
7692
'observePropertyAlias',
7793
);
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import type {
2-
UmbBlockLayoutBaseModel,
3-
UmbBlockViewPropsType,
4-
UmbBlockWorkspaceData,
5-
} from '@umbraco-cms/backoffice/block';
6-
import type { UmbWorkspaceModalData } from '@umbraco-cms/backoffice/modal';
1+
import type { UmbBlockWorkspaceData } from '@umbraco-cms/backoffice/block';
2+
import type { UmbWorkspaceModalData, UmbWorkspaceModalValue } from '@umbraco-cms/backoffice/modal';
73
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
84

95
export interface UmbBlockRteWorkspaceData extends UmbBlockWorkspaceData<object> {}
106

11-
export type UmbBlockRteWorkspaceValue = Array<UmbBlockViewPropsType<UmbBlockLayoutBaseModel>>;
12-
13-
export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorkspaceData, UmbBlockRteWorkspaceValue>(
7+
export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorkspaceData, UmbWorkspaceModalValue>(
148
'Umb.Modal.Workspace',
159
{
1610
modal: {
@@ -20,4 +14,4 @@ export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorksp
2014
data: { entityType: 'block', preset: {}, originData: {} },
2115
// Recast the type, so the entityType data prop is not required:
2216
},
23-
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbBlockRteWorkspaceValue>;
17+
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbWorkspaceModalValue>;

src/packages/block/block/context/block-entries.context.ts

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { UmbBlockDataType, UmbBlockLayoutBaseModel } from '../types.js';
2-
import { UMB_BLOCK_WORKSPACE_MODAL } from '../workspace/block-workspace.modal-token.js';
3-
import type { UmbBlockDataObjectModel, UmbBlockManagerContext } from './block-manager.context.js';
2+
import type { UmbBlockWorkspaceData } from '../workspace/block-workspace.modal-token.js';
43
import { UMB_BLOCK_ENTRIES_CONTEXT } from './block-entries.context-token.js';
4+
import type { UmbBlockDataObjectModel, UmbBlockManagerContext } from './block-manager.context.js';
5+
import { type Observable, UmbArrayState, UmbBasicState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
6+
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
57
import type { UmbBlockTypeBaseModel } from '@umbraco-cms/backoffice/block-type';
68
import type { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
7-
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
89
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
9-
import { type Observable, UmbArrayState, UmbBasicState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
10-
import { type UmbModalRouteBuilder, UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
10+
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';
1111

1212
export abstract class UmbBlockEntriesContext<
1313
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType, BlockManagerContextType>,
@@ -21,13 +21,11 @@ export abstract class UmbBlockEntriesContext<
2121
_manager?: BlockManagerContextType;
2222
_retrieveManager;
2323

24-
_workspaceModal: UmbModalRouteRegistrationController;
25-
2624
protected _catalogueRouteBuilderState = new UmbBasicState<UmbModalRouteBuilder | undefined>(undefined);
2725
readonly catalogueRouteBuilder = this._catalogueRouteBuilderState.asObservable();
2826

29-
#workspacePath = new UmbStringState(undefined);
30-
workspacePath = this.#workspacePath.asObservable();
27+
protected _workspacePath = new UmbStringState(undefined);
28+
workspacePath = this._workspacePath.asObservable();
3129

3230
public abstract readonly canCreate: Observable<boolean>;
3331

@@ -42,34 +40,7 @@ export abstract class UmbBlockEntriesContext<
4240
this._retrieveManager = this.consumeContext(blockManagerContextToken, (blockGridManager) => {
4341
this._manager = blockGridManager;
4442
this._gotBlockManager();
45-
46-
this.observe(
47-
this._manager.propertyAlias,
48-
(alias) => {
49-
this._workspaceModal.setUniquePathValue('propertyAlias', alias);
50-
},
51-
'observePropertyAlias',
52-
);
53-
this.observe(
54-
this._manager.variantId,
55-
(variantId) => {
56-
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
57-
this._workspaceModal.setUniquePathValue('variantId', variantId?.toString());
58-
},
59-
'observePropertyVariantId',
60-
);
6143
}).asPromise();
62-
63-
this._workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_WORKSPACE_MODAL)
64-
.addUniquePaths(['propertyAlias', 'variantId'])
65-
.addAdditionalPath('block')
66-
.onSetup(() => {
67-
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
68-
})
69-
.observeRouteBuilder((routeBuilder) => {
70-
const newPath = routeBuilder({});
71-
this.#workspacePath.setValue(newPath);
72-
});
7344
}
7445

7546
async getManager() {
@@ -100,14 +71,14 @@ export abstract class UmbBlockEntriesContext<
10071
public abstract create(
10172
contentElementTypeKey: string,
10273
layoutEntry?: Omit<BlockLayoutType, 'contentUdi'>,
103-
modalData?: typeof UMB_BLOCK_WORKSPACE_MODAL.DATA,
74+
modalData?: UmbBlockWorkspaceData,
10475
): Promise<UmbBlockDataObjectModel<BlockLayoutType> | undefined>;
10576

10677
abstract insert(
10778
layoutEntry: BlockLayoutType,
10879
content: UmbBlockDataType,
10980
settings: UmbBlockDataType | undefined,
110-
modalData: typeof UMB_BLOCK_WORKSPACE_MODAL.DATA,
81+
modalData: UmbBlockWorkspaceData,
11182
): Promise<boolean>;
11283
//edit?
11384
//editSettings

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
324324
} else {
325325
// Update data:
326326

327-
this.#blockManager.setOneLayout(layoutData, this.#modalContext?.data as UmbBlockWorkspaceData);
327+
this.#blockManager.setOneLayout(layoutData, this.#modalContext.data as UmbBlockWorkspaceData);
328328
if (contentData) {
329329
this.#blockManager.setOneContent(contentData);
330330
}

0 commit comments

Comments
 (0)