From 9c5768e1ab4034a71a15ff8e86fe4b9a5aa543d7 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 4 Feb 2025 12:18:35 +0100 Subject: [PATCH] Deprecate get unique param on UmbPickerInputContext and UmbRepositoryItemsManager (#18216) * Add a deprecation warning for the getUnique param * fix import * add specific version number * remove block usage * remove input rich media usage * explicit version * deprecate getUnique method in picker context * remove get unique method --- ...block-grid-area-type-permission.element.ts | 1 - .../block-type-card.element.ts | 1 - .../block-type-workspace-editor.element.ts | 6 +---- .../core/picker-input/picker-input.context.ts | 22 +++++++++++++++++-- .../repository/repository-items.manager.ts | 22 ++++++++++++++++--- .../input-document/input-document.context.ts | 2 +- .../workspace/document-workspace.context.ts | 10 ++++----- .../input-rich-media.element.ts | 6 +---- .../detail/webhook-detail.repository.ts | 2 +- 9 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-area-type-permission/block-grid-area-type-permission.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-area-type-permission/block-grid-area-type-permission.element.ts index ca852fa114..01a47859c0 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-area-type-permission/block-grid-area-type-permission.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-area-type-permission/block-grid-area-type-permission.element.ts @@ -40,7 +40,6 @@ export class UmbPropertyEditorUIBlockGridAreaTypePermissionElement #itemsManager = new UmbRepositoryItemsManager( this, UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, - (x) => x.unique, ); constructor() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts index 376e077785..a188483c94 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts @@ -18,7 +18,6 @@ export class UmbBlockTypeCardElement extends UmbLitElement { readonly #itemManager = new UmbRepositoryItemsManager( this, UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, - (x) => x.unique, ); @property({ type: String }) diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts index ac7c4f6a7d..05d2407e78 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts @@ -8,11 +8,7 @@ import { UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS } from '@umbraco-cms/backoffice @customElement('umb-block-type-workspace-editor') export class UmbBlockTypeWorkspaceEditorElement extends UmbLitElement { - #itemManager = new UmbRepositoryItemsManager( - this, - UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, - (x) => x.unique, - ); + #itemManager = new UmbRepositoryItemsManager(this, UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS); #workspaceContext?: typeof UMB_BLOCK_TYPE_WORKSPACE_CONTEXT.TYPE; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/picker-input/picker-input.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/picker-input/picker-input.context.ts index 97c39f77f5..1a597bf8af 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/picker-input/picker-input.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/picker-input/picker-input.context.ts @@ -5,6 +5,7 @@ import { UMB_MODAL_MANAGER_CONTEXT, umbConfirmModal } from '@umbraco-cms/backoff import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import type { UmbItemRepository } from '@umbraco-cms/backoffice/repository'; import type { UmbModalToken, UmbPickerModalData, UmbPickerModalValue } from '@umbraco-cms/backoffice/modal'; +import { UmbDeprecation } from '@umbraco-cms/backoffice/utils'; type PickerItemBaseType = { name: string; unique: string }; export class UmbPickerInputContext< @@ -44,8 +45,14 @@ export class UmbPickerInputContext< } private _min = 0; - /* TODO: find a better way to have a getUniqueMethod. If we want to support trees/items of different types, - then it need to be bound to the type and can't be a generic method we pass in. */ + /** + * Creates an instance of UmbPickerInputContext. + * @param {UmbControllerHost} host - The host for the controller. + * @param {string} repositoryAlias - The alias of the repository to use. + * @param {(string | UmbModalToken, PickerModalValueType>)} modalAlias - The alias of the modal to use. + * @param {((entry: PickedItemType) => string | undefined)} [getUniqueMethod] - DEPRECATED since 15.3. Will be removed in v. 17: A method to get the unique key from the item. + * @memberof UmbPickerInputContext + */ constructor( host: UmbControllerHost, repositoryAlias: string, @@ -56,6 +63,17 @@ export class UmbPickerInputContext< this.modalAlias = modalAlias; this.#getUnique = getUniqueMethod || ((entry) => entry.unique); + this.#getUnique = getUniqueMethod + ? (entry: PickedItemType) => { + new UmbDeprecation({ + deprecated: 'The getUniqueMethod parameter.', + removeInVersion: '17.0.0', + solution: 'The required unique property on the item will be used instead.', + }).warn(); + return getUniqueMethod(entry); + } + : (entry) => entry.unique; + this.#itemManager = new UmbRepositoryItemsManager(this, repositoryAlias, this.#getUnique); this.selection = this.#itemManager.uniques; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/repository/repository-items.manager.ts b/src/Umbraco.Web.UI.Client/src/packages/core/repository/repository-items.manager.ts index d54166a951..a17759bd2e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/repository/repository-items.manager.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/repository/repository-items.manager.ts @@ -1,3 +1,4 @@ +import { UmbDeprecation } from '@umbraco-cms/backoffice/utils'; import type { UmbItemRepository } from '@umbraco-cms/backoffice/repository'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api'; @@ -9,6 +10,7 @@ import { UmbEntityUpdatedEvent } from '@umbraco-cms/backoffice/entity-action'; const ObserveRepositoryAlias = Symbol(); +// TODO: v16 - add entityType to the type export class UmbRepositoryItemsManager extends UmbControllerBase { // repository?: UmbItemRepository; @@ -29,8 +31,13 @@ export class UmbRepositoryItemsManager exte #items = new UmbArrayState([], (x) => this.#getUnique(x)); items = this.#items.asObservable(); - /* TODO: find a better way to have a getUniqueMethod. If we want to support trees/items of different types, - then it need to be bound to the type and can't be a generic method we pass in. */ + /** + * Creates an instance of UmbRepositoryItemsManager. + * @param {UmbControllerHost} host - The host for the controller. + * @param {string} repositoryAlias - The alias of the repository to use. + * @param {((entry: ItemType) => string | undefined)} [getUniqueMethod] - DEPRECATED since 15.3. Will be removed in v. 17: A method to get the unique key from the item. + * @memberof UmbRepositoryItemsManager + */ constructor( host: UmbControllerHost, repositoryAlias: string, @@ -38,7 +45,16 @@ export class UmbRepositoryItemsManager exte ) { super(host); - this.#getUnique = getUniqueMethod || ((entry) => entry.unique); + this.#getUnique = getUniqueMethod + ? (entry: ItemType) => { + new UmbDeprecation({ + deprecated: 'The getUniqueMethod parameter.', + removeInVersion: '17.0.0', + solution: 'The required unique property on the item will be used instead.', + }).warn(); + return getUniqueMethod(entry); + } + : (entry) => entry.unique; this.#init = new UmbExtensionApiInitializer>>( this, diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/components/input-document/input-document.context.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/components/input-document/input-document.context.ts index 1fad7369cf..75b2b2c42a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/components/input-document/input-document.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/components/input-document/input-document.context.ts @@ -21,7 +21,7 @@ export class UmbDocumentPickerInputContext extends UmbPickerInputContext< UmbDocumentPickerModalValue > { constructor(host: UmbControllerHost) { - super(host, UMB_DOCUMENT_ITEM_REPOSITORY_ALIAS, UMB_DOCUMENT_PICKER_MODAL, (entry) => entry.unique); + super(host, UMB_DOCUMENT_ITEM_REPOSITORY_ALIAS, UMB_DOCUMENT_PICKER_MODAL); } override async openPicker( diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts index d709465d31..4f989c98ae 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts @@ -297,7 +297,7 @@ export class UmbDocumentWorkspaceContext public async publish() { new UmbDeprecation({ deprecated: 'The Publish method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.', - removeInVersion: '17', + removeInVersion: '17.0.0', solution: 'Use the Publish method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.', }).warn(); if (!this.#publishingContext) throw new Error('Publishing context is missing'); @@ -311,7 +311,7 @@ export class UmbDocumentWorkspaceContext public async saveAndPublish(): Promise { new UmbDeprecation({ deprecated: 'The SaveAndPublish method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.', - removeInVersion: '17', + removeInVersion: '17.0.0', solution: 'Use the SaveAndPublish method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.', }).warn(); if (!this.#publishingContext) throw new Error('Publishing context is missing'); @@ -325,7 +325,7 @@ export class UmbDocumentWorkspaceContext public async schedule() { new UmbDeprecation({ deprecated: 'The Schedule method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.', - removeInVersion: '17', + removeInVersion: '17.0.0', solution: 'Use the Schedule method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.', }).warn(); if (!this.#publishingContext) throw new Error('Publishing context is missing'); @@ -339,7 +339,7 @@ export class UmbDocumentWorkspaceContext public async unpublish() { new UmbDeprecation({ deprecated: 'The Unpublish method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.', - removeInVersion: '17', + removeInVersion: '17.0.0', solution: 'Use the Unpublish method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.', }).warn(); if (!this.#publishingContext) throw new Error('Publishing context is missing'); @@ -353,7 +353,7 @@ export class UmbDocumentWorkspaceContext public async publishWithDescendants() { new UmbDeprecation({ deprecated: 'The PublishWithDescendants method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.', - removeInVersion: '17', + removeInVersion: '17.0.0', solution: 'Use the PublishWithDescendants method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.', }).warn(); if (!this.#publishingContext) throw new Error('Publishing context is missing'); diff --git a/src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-rich-media/input-rich-media.element.ts b/src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-rich-media/input-rich-media.element.ts index cd4de1f9e8..ef9a467648 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-rich-media/input-rich-media.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-rich-media/input-rich-media.element.ts @@ -173,11 +173,7 @@ export class UmbInputRichMediaElement extends UmbFormControlMixin< @state() private _routeBuilder?: UmbModalRouteBuilder; - readonly #itemManager = new UmbRepositoryItemsManager( - this, - UMB_MEDIA_ITEM_REPOSITORY_ALIAS, - (x) => x.unique, - ); + readonly #itemManager = new UmbRepositoryItemsManager(this, UMB_MEDIA_ITEM_REPOSITORY_ALIAS); constructor() { super(); diff --git a/src/Umbraco.Web.UI.Client/src/packages/webhook/webhook/repository/detail/webhook-detail.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/webhook/webhook/repository/detail/webhook-detail.repository.ts index eb11fed0dd..cf0279f142 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/webhook/webhook/repository/detail/webhook-detail.repository.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/webhook/webhook/repository/detail/webhook-detail.repository.ts @@ -22,7 +22,7 @@ export class UmbWebhookDetailRepository extends UmbDetailRepositoryBase { new UmbDeprecation({ deprecated: 'The requestEvents method on the UmbWebhookDetailRepository is deprecated.', - removeInVersion: '17', + removeInVersion: '17.0.0', solution: 'Use the requestEvents method on UmbWebhookEventRepository instead.', }).warn();