move workspace modal registration

This commit is contained in:
Niels Lyngsø
2024-02-09 20:08:48 +01:00
parent e649aefea0
commit 6ea67225e9
4 changed files with 48 additions and 32 deletions

View File

@@ -1,12 +1,13 @@
import type { UmbBlockTypeBaseModel } from '../../block-type/types.js';
import type { UmbBlockDataType, UmbBlockLayoutBaseModel } from '../types.js';
import type { UmbBlockWorkspaceData } from '../index.js';
import { UMB_BLOCK_WORKSPACE_MODAL } from '../workspace/block-workspace.modal-token.js';
import type { UmbBlockDataObjectModel, UmbBlockManagerContext } from './block-manager.context.js';
import { UMB_BLOCK_ENTRIES_CONTEXT } from './block-entries.context-token.js';
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 { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
import { UmbArrayState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/modal';
export abstract class UmbBlockEntriesContext<
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType, BlockManagerContextType>,
@@ -20,6 +21,11 @@ export abstract class UmbBlockEntriesContext<
_manager?: BlockManagerContextType;
_retrieveManager;
#workspaceModal: UmbModalRouteRegistrationController;
#workspacePath = new UmbStringState(undefined);
workspacePath = this.#workspacePath.asObservable();
protected _layoutEntries = new UmbArrayState<BlockLayoutType>([], (x) => x.contentUdi);
readonly layoutEntries = this._layoutEntries.asObservable();
readonly layoutEntriesLength = this._layoutEntries.asObservablePart((x) => x.length);
@@ -31,7 +37,34 @@ 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);
});
}
protected abstract _gotBlockManager(): void;
@@ -52,14 +85,14 @@ export abstract class UmbBlockEntriesContext<
public abstract create(
contentElementTypeKey: string,
layoutEntry?: Omit<BlockLayoutType, 'contentUdi'>,
modalData?: UmbBlockWorkspaceData,
modalData?: typeof UMB_BLOCK_WORKSPACE_MODAL.DATA,
): Promise<UmbBlockDataObjectModel<BlockLayoutType> | undefined>;
abstract insert(
layoutEntry: BlockLayoutType,
content: UmbBlockDataType,
settings: UmbBlockDataType | undefined,
modalData: UmbBlockWorkspaceData,
modalData: typeof UMB_BLOCK_WORKSPACE_MODAL.DATA,
): Promise<boolean>;
//edit?
//editSettings

View File

@@ -130,9 +130,16 @@ export abstract class UmbBlockEntryContext<
}
#gotManager() {
if (this._manager) {
this.#observeBlockType();
this.#observeData();
}
abstract _gotManager(): void;
#gotEntries() {
if (this._entries) {
this.observe(
this._manager.workspacePath,
this._entries.workspacePath,
(workspacePath) => {
this.#workspacePath.setValue(workspacePath);
},
@@ -141,14 +148,8 @@ export abstract class UmbBlockEntryContext<
} else {
this.removeControllerByAlias('observeWorkspacePath');
}
this.#observeBlockType();
this.#observeData();
}
abstract _gotManager(): void;
#gotEntries() {}
abstract _gotEntries(): void;
#observeData() {

View File

@@ -5,8 +5,7 @@ import { UmbArrayState, UmbClassState, UmbStringState } from '@umbraco-cms/backo
import { UmbDocumentTypeDetailRepository } from '@umbraco-cms/backoffice/document-type';
import { buildUdi, getKeyFromUdi } from '@umbraco-cms/backoffice/utils';
import type { UmbBlockTypeBaseModel, UmbBlockWorkspaceData } from '@umbraco-cms/backoffice/block';
import { UMB_BLOCK_MANAGER_CONTEXT, UMB_BLOCK_WORKSPACE_MODAL } from '@umbraco-cms/backoffice/block';
import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/modal';
import { UMB_BLOCK_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/block';
import type { UmbContentTypeModel } from '@umbraco-cms/backoffice/content-type';
import { UmbId } from '@umbraco-cms/backoffice/id';
import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor';
@@ -24,10 +23,6 @@ export abstract class UmbBlockManagerContext<
> extends UmbContextBase<UmbBlockManagerContext> {
//
#contentTypeRepository = new UmbDocumentTypeDetailRepository(this);
#workspaceModal: UmbModalRouteRegistrationController;
#workspacePath = new UmbStringState(undefined);
workspacePath = this.#workspacePath.asObservable();
#propertyAlias = new UmbStringState(undefined);
propertyAlias = this.#propertyAlias.asObservable();
@@ -92,7 +87,6 @@ export abstract class UmbBlockManagerContext<
propertyContext?.alias,
(alias) => {
this.#propertyAlias.setValue(alias);
this.#workspaceModal.setUniquePathValue('propertyAlias', alias);
},
'observePropertyAlias',
);
@@ -100,23 +94,10 @@ export abstract class UmbBlockManagerContext<
propertyContext?.variantId,
(variantId) => {
this.#variantId.setValue(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',
);
});
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 ensureContentType(unique?: string) {

View File

@@ -77,6 +77,7 @@ export class UmbBlockWorkspaceContext<
}).asPromise();
this.#retrieveBlockEntries = this.consumeContext(UMB_BLOCK_ENTRIES_CONTEXT, (context) => {
console.log('UMB_BLOCK_ENTRIES_CONTEXT', context);
this.#blockEntries = context;
}).asPromise();
}