move workspace modal registration to each implementation

This commit is contained in:
Niels Lyngsø
2024-05-28 20:48:58 +02:00
committed by Jacob Overgaard
parent 344b3cf50e
commit 153f1be001
6 changed files with 81 additions and 65 deletions

View File

@@ -1,6 +1,10 @@
import type { UmbBlockDataType } from '../../block/index.js';
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
import { UMB_BLOCK_GRID_ENTRY_CONTEXT, type UmbBlockGridWorkspaceData } from '../index.js';
import {
UMB_BLOCK_GRID_ENTRY_CONTEXT,
UMB_BLOCK_GRID_WORKSPACE_MODAL,
type UmbBlockGridWorkspaceData,
} from '../index.js';
import type { UmbBlockGridLayoutModel, UmbBlockGridTypeAreaType, UmbBlockGridTypeModel } from '../types.js';
import { UMB_BLOCK_GRID_MANAGER_CONTEXT } from './block-grid-manager.context-token.js';
import type { UmbBlockGridScalableContainerContext } from './block-grid-scale-manager/block-grid-scale-manager.controller.js';
@@ -21,6 +25,7 @@ export class UmbBlockGridEntriesContext
{
//
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
#workspaceModal: UmbModalRouteRegistrationController;
#parentEntry?: typeof UMB_BLOCK_GRID_ENTRY_CONTEXT.TYPE;
@@ -66,13 +71,13 @@ export class UmbBlockGridEntriesContext
setParentUnique(contentUdi: string | null) {
this.#parentUnique = contentUdi;
// Notice pathFolderName can be removed when we have switched to use a proper GUID/ID/KEY. [NL]
this._workspaceModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
this.#workspaceModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
this.#catalogueModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
}
setAreaKey(areaKey: string | null) {
this.#areaKey = areaKey;
this._workspaceModal.setUniquePathValue('areaKey', areaKey ?? 'null');
this.#workspaceModal.setUniquePathValue('areaKey', areaKey ?? 'null');
this.#catalogueModal.setUniquePathValue('areaKey', areaKey ?? 'null');
this.#gotAreaKey();
}
@@ -93,8 +98,6 @@ export class UmbBlockGridEntriesContext
constructor(host: UmbControllerHost) {
super(host, UMB_BLOCK_GRID_MANAGER_CONTEXT);
this._workspaceModal.addUniquePaths(['parentUnique', 'areaKey']);
this.consumeContext(UMB_BLOCK_GRID_ENTRY_CONTEXT, (blockGridEntry) => {
this.#parentEntry = blockGridEntry;
this.#gotBlockParentEntry(); // is not used at this point. [NL]
@@ -119,6 +122,24 @@ export class UmbBlockGridEntriesContext
// TODO: Does it make any sense that this is a state? Check usage and confirm. [NL]
this._catalogueRouteBuilderState.setValue(routeBuilder);
});
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_GRID_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId', 'parentUnique', 'areaKey'])
.addAdditionalPath('block')
.onSetup(() => {
return {
data: {
entityType: 'block',
preset: {},
originData: { areaKey: this.#areaKey, parentUnique: this.#parentUnique },
},
modal: { size: 'medium' },
};
})
.observeRouteBuilder((routeBuilder) => {
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
}
protected _gotBlockManager() {
@@ -131,6 +152,7 @@ export class UmbBlockGridEntriesContext
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);
@@ -138,9 +160,9 @@ export class UmbBlockGridEntriesContext
this.observe(
this._manager.variantId,
(variantId) => {
if (variantId) {
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
}
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
},
'observePropertyAlias',
);

View File

@@ -1,6 +1,6 @@
import type { UmbBlockDataType } from '../../block/index.js';
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
import type { UmbBlockListWorkspaceData } from '../index.js';
import { UMB_BLOCK_LIST_WORKSPACE_MODAL, type UmbBlockListWorkspaceData } from '../index.js';
import type { UmbBlockListLayoutModel, UmbBlockListTypeModel } from '../types.js';
import { UMB_BLOCK_LIST_MANAGER_CONTEXT } from './block-list-manager.context-token.js';
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
@@ -15,6 +15,7 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
> {
//
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
#workspaceModal: UmbModalRouteRegistrationController;
// We will just say its always allowed for list for now: [NL]
public readonly canCreate = new UmbBooleanState(true).asObservable();
@@ -40,6 +41,17 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
.observeRouteBuilder((routeBuilder) => {
this._catalogueRouteBuilderState.setValue(routeBuilder);
});
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_LIST_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
.addAdditionalPath('block')
.onSetup(() => {
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
})
.observeRouteBuilder((routeBuilder) => {
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
}
protected _gotBlockManager() {
@@ -64,6 +76,7 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);
@@ -71,9 +84,9 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
this.observe(
this._manager.variantId,
(variantId) => {
if (variantId) {
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
}
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
},
'observePropertyAlias',
);

View File

@@ -1,7 +1,10 @@
import type { UmbBlockDataType } from '../../block/index.js';
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
import type { UmbBlockRteWorkspaceData } from '../index.js';
import type { UmbBlockRteLayoutModel, UmbBlockRteTypeModel } from '../types.js';
import {
UMB_BLOCK_RTE_WORKSPACE_MODAL,
type UmbBlockRteWorkspaceData,
} from '../workspace/block-rte-workspace.modal-token.js';
import { UMB_BLOCK_RTE_MANAGER_CONTEXT } from './block-rte-manager.context-token.js';
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
@@ -15,6 +18,7 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
> {
//
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
#workspaceModal: UmbModalRouteRegistrationController;
// We will just say its always allowed for RTE for now: [NL]
public readonly canCreate = new UmbBooleanState(true).asObservable();
@@ -38,6 +42,17 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
.observeRouteBuilder((routeBuilder) => {
this._catalogueRouteBuilderState.setValue(routeBuilder);
});
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_RTE_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
.addAdditionalPath('block')
.onSetup(() => {
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
})
.observeRouteBuilder((routeBuilder) => {
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
}
protected _gotBlockManager() {
@@ -62,6 +77,7 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);
@@ -69,9 +85,9 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
this.observe(
this._manager.variantId,
(variantId) => {
if (variantId) {
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
}
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
},
'observePropertyAlias',
);

View File

@@ -1,16 +1,10 @@
import type {
UmbBlockLayoutBaseModel,
UmbBlockViewPropsType,
UmbBlockWorkspaceData,
} from '@umbraco-cms/backoffice/block';
import type { UmbWorkspaceModalData } from '@umbraco-cms/backoffice/modal';
import type { UmbBlockWorkspaceData } from '@umbraco-cms/backoffice/block';
import type { UmbWorkspaceModalData, UmbWorkspaceModalValue } from '@umbraco-cms/backoffice/modal';
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
export interface UmbBlockRteWorkspaceData extends UmbBlockWorkspaceData<object> {}
export type UmbBlockRteWorkspaceValue = Array<UmbBlockViewPropsType<UmbBlockLayoutBaseModel>>;
export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorkspaceData, UmbBlockRteWorkspaceValue>(
export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorkspaceData, UmbWorkspaceModalValue>(
'Umb.Modal.Workspace',
{
modal: {
@@ -20,4 +14,4 @@ export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorksp
data: { entityType: 'block', preset: {}, originData: {} },
// Recast the type, so the entityType data prop is not required:
},
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbBlockRteWorkspaceValue>;
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbWorkspaceModalValue>;

View File

@@ -1,13 +1,13 @@
import type { UmbBlockDataType, UmbBlockLayoutBaseModel } from '../types.js';
import { UMB_BLOCK_WORKSPACE_MODAL } from '../workspace/block-workspace.modal-token.js';
import type { UmbBlockDataObjectModel, UmbBlockManagerContext } from './block-manager.context.js';
import type { UmbBlockWorkspaceData } from '../workspace/block-workspace.modal-token.js';
import { UMB_BLOCK_ENTRIES_CONTEXT } from './block-entries.context-token.js';
import type { UmbBlockDataObjectModel, UmbBlockManagerContext } from './block-manager.context.js';
import { type Observable, UmbArrayState, UmbBasicState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbBlockTypeBaseModel } from '@umbraco-cms/backoffice/block-type';
import type { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { type Observable, UmbArrayState, UmbBasicState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
import { type UmbModalRouteBuilder, UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';
export abstract class UmbBlockEntriesContext<
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType, BlockManagerContextType>,
@@ -21,13 +21,11 @@ export abstract class UmbBlockEntriesContext<
_manager?: BlockManagerContextType;
_retrieveManager;
_workspaceModal: UmbModalRouteRegistrationController;
protected _catalogueRouteBuilderState = new UmbBasicState<UmbModalRouteBuilder | undefined>(undefined);
readonly catalogueRouteBuilder = this._catalogueRouteBuilderState.asObservable();
#workspacePath = new UmbStringState(undefined);
workspacePath = this.#workspacePath.asObservable();
protected _workspacePath = new UmbStringState(undefined);
workspacePath = this._workspacePath.asObservable();
public abstract readonly canCreate: Observable<boolean>;
@@ -42,34 +40,7 @@ export abstract class UmbBlockEntriesContext<
this._retrieveManager = this.consumeContext(blockManagerContextToken, (blockGridManager) => {
this._manager = blockGridManager;
this._gotBlockManager();
this.observe(
this._manager.propertyAlias,
(alias) => {
this._workspaceModal.setUniquePathValue('propertyAlias', alias);
},
'observePropertyAlias',
);
this.observe(
this._manager.variantId,
(variantId) => {
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
this._workspaceModal.setUniquePathValue('variantId', variantId?.toString());
},
'observePropertyVariantId',
);
}).asPromise();
this._workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
.addAdditionalPath('block')
.onSetup(() => {
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
})
.observeRouteBuilder((routeBuilder) => {
const newPath = routeBuilder({});
this.#workspacePath.setValue(newPath);
});
}
async getManager() {
@@ -100,14 +71,14 @@ export abstract class UmbBlockEntriesContext<
public abstract create(
contentElementTypeKey: string,
layoutEntry?: Omit<BlockLayoutType, 'contentUdi'>,
modalData?: typeof UMB_BLOCK_WORKSPACE_MODAL.DATA,
modalData?: UmbBlockWorkspaceData,
): Promise<UmbBlockDataObjectModel<BlockLayoutType> | undefined>;
abstract insert(
layoutEntry: BlockLayoutType,
content: UmbBlockDataType,
settings: UmbBlockDataType | undefined,
modalData: typeof UMB_BLOCK_WORKSPACE_MODAL.DATA,
modalData: UmbBlockWorkspaceData,
): Promise<boolean>;
//edit?
//editSettings

View File

@@ -324,7 +324,7 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
} else {
// Update data:
this.#blockManager.setOneLayout(layoutData, this.#modalContext?.data as UmbBlockWorkspaceData);
this.#blockManager.setOneLayout(layoutData, this.#modalContext.data as UmbBlockWorkspaceData);
if (contentData) {
this.#blockManager.setOneContent(contentData);
}