implement/replace existing unique router paths

This commit is contained in:
Niels Lyngsø
2025-01-09 22:08:07 +01:00
parent 2c8117c8a5
commit 3ccb10d7c0
6 changed files with 33 additions and 100 deletions

View File

@@ -16,10 +16,8 @@ import {
UmbStringState,
} from '@umbraco-cms/backoffice/observable-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
import { pathFolderName } from '@umbraco-cms/backoffice/utils';
import { UmbModalRouteRegistrationController, UmbRoutePathAddendumContext } from '@umbraco-cms/backoffice/router';
import type { UmbNumberRangeValueType } from '@umbraco-cms/backoffice/models';
import { UMB_CONTENT_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/content';
interface UmbBlockGridAreaTypeInvalidRuleType {
groupKey?: string;
@@ -40,11 +38,7 @@ export class UmbBlockGridEntriesContext
implements UmbBlockGridScalableContainerContext
{
//
#catalogueModal: UmbModalRouteRegistrationController<
typeof UMB_BLOCK_CATALOGUE_MODAL.DATA,
typeof UMB_BLOCK_CATALOGUE_MODAL.VALUE
>;
#workspaceModal;
#pathAddendum = new UmbRoutePathAddendumContext(this);
#parentEntry?: typeof UMB_BLOCK_GRID_ENTRY_CONTEXT.TYPE;
@@ -94,9 +88,6 @@ export class UmbBlockGridEntriesContext
setParentUnique(contentKey: string | null) {
this.#parentUnique = contentKey;
// Notice pathFolderName can be removed when we have switched to use a proper GUID/ID/KEY. [NL]
this.#workspaceModal.setUniquePathValue('parentUnique', pathFolderName(contentKey ?? 'null'));
this.#catalogueModal.setUniquePathValue('parentUnique', pathFolderName(contentKey ?? 'null'));
}
getParentUnique(): string | null | undefined {
@@ -105,8 +96,7 @@ export class UmbBlockGridEntriesContext
setAreaKey(areaKey: string | null) {
this.#areaKey = areaKey;
this.#workspaceModal.setUniquePathValue('areaKey', areaKey ?? 'null');
this.#catalogueModal.setUniquePathValue('areaKey', areaKey ?? 'null');
this.#pathAddendum.setAddendum(areaKey ?? '');
this.#gotAreaKey();
// Idea: If we need to parse down a validation data path to target the specific layout object: [NL]
@@ -153,9 +143,8 @@ export class UmbBlockGridEntriesContext
this.#gotBlockParentEntry(); // is not used at this point. [NL]
});
this.#catalogueModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_CATALOGUE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId', 'parentUnique', 'areaKey'])
.addAdditionalPath(':view/:index')
new UmbModalRouteRegistrationController(this, UMB_BLOCK_CATALOGUE_MODAL)
.addAdditionalPath('_catalogue/:view/:index')
.onSetup((routingInfo) => {
if (!this._manager) return false;
// Idea: Maybe on setup should be async, so it can retrieve the values when needed? [NL]
@@ -199,8 +188,7 @@ export class UmbBlockGridEntriesContext
this._catalogueRouteBuilderState.setValue(routeBuilder);
});
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_GRID_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId', 'parentUnique', 'areaKey'])
new UmbModalRouteRegistrationController(this, UMB_BLOCK_GRID_WORKSPACE_MODAL)
.addAdditionalPath('block')
.onSetup(() => {
return {
@@ -221,12 +209,6 @@ export class UmbBlockGridEntriesContext
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
this.consumeContext(UMB_CONTENT_PROPERTY_DATASET_CONTEXT, (dataset) => {
const variantId = dataset.getVariantId();
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
});
}
protected _gotBlockManager() {
@@ -234,15 +216,6 @@ export class UmbBlockGridEntriesContext
this.#setupAllowedBlockTypes();
this.#setupRangeLimits();
this.observe(
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);
}
#gotAreaKey() {

View File

@@ -7,7 +7,6 @@ import { UMB_BLOCK_LIST_MANAGER_CONTEXT } from './block-list-manager.context-tok
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
import { UMB_CONTENT_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/content';
export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
typeof UMB_BLOCK_LIST_MANAGER_CONTEXT,
@@ -17,11 +16,6 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
UmbBlockListWorkspaceOriginData
> {
//
#catalogueModal: UmbModalRouteRegistrationController<
typeof UMB_BLOCK_CATALOGUE_MODAL.DATA,
typeof UMB_BLOCK_CATALOGUE_MODAL.VALUE
>;
#workspaceModal;
// We will just say its always allowed for list for now: [NL]
public readonly canCreate = new UmbBooleanState(true).asObservable();
@@ -29,9 +23,8 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
constructor(host: UmbControllerHost) {
super(host, UMB_BLOCK_LIST_MANAGER_CONTEXT);
this.#catalogueModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_CATALOGUE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
.addAdditionalPath(':view/:index')
new UmbModalRouteRegistrationController(this, UMB_BLOCK_CATALOGUE_MODAL)
.addAdditionalPath('_catalogue/:view/:index')
.onSetup(async (routingInfo) => {
await this._retrieveManager;
if (!this._manager) return false;
@@ -69,8 +62,7 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
this._catalogueRouteBuilderState.setValue(routeBuilder);
});
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_LIST_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
new UmbModalRouteRegistrationController(this, UMB_BLOCK_LIST_WORKSPACE_MODAL)
.addAdditionalPath('block')
.onSetup(() => {
return {
@@ -82,13 +74,6 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
// TODO: This must later be switched out with a smarter Modal Registration System, cause here is a issue with Block Editors in inline mode in Block Editors, cause the hosting Block is also of type Content. [NL]
this.consumeContext(UMB_CONTENT_PROPERTY_DATASET_CONTEXT, (dataset) => {
const variantId = dataset.getVariantId();
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
});
}
protected _gotBlockManager() {
@@ -108,15 +93,6 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
},
'observeThisLayouts',
);
this.observe(
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);
}
getPathForCreateBlock(index: number) {

View File

@@ -9,7 +9,6 @@ import { UMB_BLOCK_RTE_MANAGER_CONTEXT } from './block-rte-manager.context-token
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
import { UMB_CONTENT_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/content';
export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
typeof UMB_BLOCK_RTE_MANAGER_CONTEXT,
@@ -19,11 +18,6 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
UmbBlockRteWorkspaceOriginData
> {
//
readonly #catalogueModal: UmbModalRouteRegistrationController<
typeof UMB_BLOCK_CATALOGUE_MODAL.DATA,
typeof UMB_BLOCK_CATALOGUE_MODAL.VALUE
>;
readonly #workspaceModal;
// We will just say its always allowed for RTE for now: [NL]
public readonly canCreate = new UmbBooleanState(true).asObservable();
@@ -31,9 +25,8 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
constructor(host: UmbControllerHost) {
super(host, UMB_BLOCK_RTE_MANAGER_CONTEXT);
this.#catalogueModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_CATALOGUE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
.addAdditionalPath(':view')
new UmbModalRouteRegistrationController(this, UMB_BLOCK_CATALOGUE_MODAL)
.addAdditionalPath('_catalogue/:view')
.onSetup((routingInfo) => {
return {
data: {
@@ -68,8 +61,7 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
this._catalogueRouteBuilderState.setValue(routeBuilder);
});
this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_RTE_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
new UmbModalRouteRegistrationController(this, UMB_BLOCK_RTE_WORKSPACE_MODAL)
.addAdditionalPath('block')
.onSetup(() => {
return { data: { entityType: 'block', preset: {}, baseDataPath: this._dataPath }, modal: { size: 'medium' } };
@@ -78,12 +70,6 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
this.consumeContext(UMB_CONTENT_PROPERTY_DATASET_CONTEXT, (dataset) => {
const variantId = dataset.getVariantId();
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
});
}
protected _gotBlockManager() {
@@ -103,15 +89,6 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
},
'observeThisLayouts',
);
this.observe(
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);
}
getPathForCreateBlock() {

View File

@@ -39,7 +39,6 @@ export class UmbInputBlockTypeElement<
this.dispatchEvent(new CustomEvent('change', { detail: { moveComplete: true } }));
},
});
#elementPickerModal;
@property({ type: Array, attribute: false })
public set value(items) {
@@ -50,9 +49,10 @@ export class UmbInputBlockTypeElement<
return this._items;
}
/** @deprecated will be removed in v17 */
@property({ type: String })
public set propertyAlias(value: string | undefined) {
this.#elementPickerModal.setUniquePathValue('propertyAlias', value);
//this.#elementPickerModal.setUniquePathValue('propertyAlias', value);
}
public get propertyAlias(): string | undefined {
return undefined;
@@ -75,13 +75,16 @@ export class UmbInputBlockTypeElement<
super();
this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, async (instance) => {
this.#datasetContext = instance;
this.observe(await this.#datasetContext?.propertyValueByAlias('blocks'), (value) => {
this.#filter = value as Array<UmbBlockTypeBaseModel>;
});
this.observe(
await this.#datasetContext?.propertyValueByAlias('blocks'),
(value) => {
this.#filter = value as Array<UmbBlockTypeBaseModel>;
},
'observeBlocks',
);
});
this.#elementPickerModal = new UmbModalRouteRegistrationController(this, UMB_DOCUMENT_TYPE_PICKER_MODAL)
.addUniquePaths(['propertyAlias'])
new UmbModalRouteRegistrationController(this, UMB_DOCUMENT_TYPE_PICKER_MODAL)
.onSetup(() => {
return {
data: {

View File

@@ -24,6 +24,7 @@ import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
import type { UmbBlockTypeBaseModel } from '@umbraco-cms/backoffice/block-type';
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
import { UmbUfmVirtualRenderController } from '@umbraco-cms/backoffice/ufm';
import { UmbRoutePathAddendumContext } from '@umbraco-cms/backoffice/router';
export abstract class UmbBlockEntryContext<
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType>,
@@ -45,6 +46,8 @@ export abstract class UmbBlockEntryContext<
_entries?: BlockEntriesContextType;
#contentKey?: string;
#pathAddendum = new UmbRoutePathAddendumContext(this);
#variantId = new UmbClassState<UmbVariantId | undefined>(undefined);
protected readonly _variantId = this.#variantId.asObservable();
@@ -275,6 +278,7 @@ export abstract class UmbBlockEntryContext<
this.observe(
this.unique,
(contentKey) => {
this.#pathAddendum.setAddendum(contentKey);
if (!contentKey) return;
this.#observeContentData();
},

View File

@@ -133,19 +133,21 @@ export class UmbInputRichMediaElement extends UUIFormControlMixin(UmbLitElement,
#focalPointEnabled: boolean = false;
@property()
/** @deprecated will be removed in v17 */
public set alias(value: string | undefined) {
this.#modalRouter.setUniquePathValue('propertyAlias', value);
//this.#modalRouter.setUniquePathValue('propertyAlias', value);
}
public get alias(): string | undefined {
return this.#modalRouter.getUniquePathValue('propertyAlias');
return undefined; //this.#modalRouter.getUniquePathValue('propertyAlias');
}
@property()
/** @deprecated will be removed in v17 */
public set variantId(value: string | UmbVariantId | undefined) {
this.#modalRouter.setUniquePathValue('variantId', value?.toString());
//this.#modalRouter.setUniquePathValue('variantId', value?.toString());
}
public get variantId(): string | undefined {
return this.#modalRouter.getUniquePathValue('variantId');
return undefined; //this.#modalRouter.getUniquePathValue('variantId');
}
/**
@@ -177,7 +179,6 @@ export class UmbInputRichMediaElement extends UUIFormControlMixin(UmbLitElement,
#itemRepository = new UmbMediaItemRepository(this);
#modalRouter;
#modalManager?: UmbModalManagerContext;
constructor() {
@@ -187,9 +188,8 @@ export class UmbInputRichMediaElement extends UUIFormControlMixin(UmbLitElement,
this.#modalManager = instance;
});
this.#modalRouter = new UmbModalRouteRegistrationController(this, UMB_IMAGE_CROPPER_EDITOR_MODAL)
new UmbModalRouteRegistrationController(this, UMB_IMAGE_CROPPER_EDITOR_MODAL)
.addAdditionalPath(':key')
.addUniquePaths(['propertyAlias', 'variantId'])
.onSetup((params) => {
const key = params.key;
if (!key) return false;