Skip to content

Commit 9c5768e

Browse files
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
1 parent 52aa18c commit 9c5768e

File tree

9 files changed

+48
-24
lines changed

9 files changed

+48
-24
lines changed

src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-area-type-permission/block-grid-area-type-permission.element.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export class UmbPropertyEditorUIBlockGridAreaTypePermissionElement
4040
#itemsManager = new UmbRepositoryItemsManager<UmbDocumentTypeItemModel>(
4141
this,
4242
UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
43-
(x) => x.unique,
4443
);
4544

4645
constructor() {

src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class UmbBlockTypeCardElement extends UmbLitElement {
1818
readonly #itemManager = new UmbRepositoryItemsManager<UmbDocumentTypeItemModel>(
1919
this,
2020
UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
21-
(x) => x.unique,
2221
);
2322

2423
@property({ type: String })

src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import { UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS } from '@umbraco-cms/backoffice
88

99
@customElement('umb-block-type-workspace-editor')
1010
export class UmbBlockTypeWorkspaceEditorElement extends UmbLitElement {
11-
#itemManager = new UmbRepositoryItemsManager<UmbDocumentTypeItemModel>(
12-
this,
13-
UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
14-
(x) => x.unique,
15-
);
11+
#itemManager = new UmbRepositoryItemsManager<UmbDocumentTypeItemModel>(this, UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS);
1612

1713
#workspaceContext?: typeof UMB_BLOCK_TYPE_WORKSPACE_CONTEXT.TYPE;
1814

src/Umbraco.Web.UI.Client/src/packages/core/picker-input/picker-input.context.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { UMB_MODAL_MANAGER_CONTEXT, umbConfirmModal } from '@umbraco-cms/backoff
55
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
66
import type { UmbItemRepository } from '@umbraco-cms/backoffice/repository';
77
import type { UmbModalToken, UmbPickerModalData, UmbPickerModalValue } from '@umbraco-cms/backoffice/modal';
8+
import { UmbDeprecation } from '@umbraco-cms/backoffice/utils';
89

910
type PickerItemBaseType = { name: string; unique: string };
1011
export class UmbPickerInputContext<
@@ -44,8 +45,14 @@ export class UmbPickerInputContext<
4445
}
4546
private _min = 0;
4647

47-
/* TODO: find a better way to have a getUniqueMethod. If we want to support trees/items of different types,
48-
then it need to be bound to the type and can't be a generic method we pass in. */
48+
/**
49+
* Creates an instance of UmbPickerInputContext.
50+
* @param {UmbControllerHost} host - The host for the controller.
51+
* @param {string} repositoryAlias - The alias of the repository to use.
52+
* @param {(string | UmbModalToken<UmbPickerModalData<PickerItemType>, PickerModalValueType>)} modalAlias - The alias of the modal to use.
53+
* @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.
54+
* @memberof UmbPickerInputContext
55+
*/
4956
constructor(
5057
host: UmbControllerHost,
5158
repositoryAlias: string,
@@ -56,6 +63,17 @@ export class UmbPickerInputContext<
5663
this.modalAlias = modalAlias;
5764
this.#getUnique = getUniqueMethod || ((entry) => entry.unique);
5865

66+
this.#getUnique = getUniqueMethod
67+
? (entry: PickedItemType) => {
68+
new UmbDeprecation({
69+
deprecated: 'The getUniqueMethod parameter.',
70+
removeInVersion: '17.0.0',
71+
solution: 'The required unique property on the item will be used instead.',
72+
}).warn();
73+
return getUniqueMethod(entry);
74+
}
75+
: (entry) => entry.unique;
76+
5977
this.#itemManager = new UmbRepositoryItemsManager<PickedItemType>(this, repositoryAlias, this.#getUnique);
6078

6179
this.selection = this.#itemManager.uniques;

src/Umbraco.Web.UI.Client/src/packages/core/repository/repository-items.manager.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UmbDeprecation } from '@umbraco-cms/backoffice/utils';
12
import type { UmbItemRepository } from '@umbraco-cms/backoffice/repository';
23
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
34
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
@@ -9,6 +10,7 @@ import { UmbEntityUpdatedEvent } from '@umbraco-cms/backoffice/entity-action';
910

1011
const ObserveRepositoryAlias = Symbol();
1112

13+
// TODO: v16 - add entityType to the type
1214
export class UmbRepositoryItemsManager<ItemType extends { unique: string }> extends UmbControllerBase {
1315
//
1416
repository?: UmbItemRepository<ItemType>;
@@ -29,16 +31,30 @@ export class UmbRepositoryItemsManager<ItemType extends { unique: string }> exte
2931
#items = new UmbArrayState<ItemType>([], (x) => this.#getUnique(x));
3032
items = this.#items.asObservable();
3133

32-
/* TODO: find a better way to have a getUniqueMethod. If we want to support trees/items of different types,
33-
then it need to be bound to the type and can't be a generic method we pass in. */
34+
/**
35+
* Creates an instance of UmbRepositoryItemsManager.
36+
* @param {UmbControllerHost} host - The host for the controller.
37+
* @param {string} repositoryAlias - The alias of the repository to use.
38+
* @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.
39+
* @memberof UmbRepositoryItemsManager
40+
*/
3441
constructor(
3542
host: UmbControllerHost,
3643
repositoryAlias: string,
3744
getUniqueMethod?: (entry: ItemType) => string | undefined,
3845
) {
3946
super(host);
4047

41-
this.#getUnique = getUniqueMethod || ((entry) => entry.unique);
48+
this.#getUnique = getUniqueMethod
49+
? (entry: ItemType) => {
50+
new UmbDeprecation({
51+
deprecated: 'The getUniqueMethod parameter.',
52+
removeInVersion: '17.0.0',
53+
solution: 'The required unique property on the item will be used instead.',
54+
}).warn();
55+
return getUniqueMethod(entry);
56+
}
57+
: (entry) => entry.unique;
4258

4359
this.#init = new UmbExtensionApiInitializer<ManifestRepository<UmbItemRepository<ItemType>>>(
4460
this,

src/Umbraco.Web.UI.Client/src/packages/documents/documents/components/input-document/input-document.context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class UmbDocumentPickerInputContext extends UmbPickerInputContext<
2121
UmbDocumentPickerModalValue
2222
> {
2323
constructor(host: UmbControllerHost) {
24-
super(host, UMB_DOCUMENT_ITEM_REPOSITORY_ALIAS, UMB_DOCUMENT_PICKER_MODAL, (entry) => entry.unique);
24+
super(host, UMB_DOCUMENT_ITEM_REPOSITORY_ALIAS, UMB_DOCUMENT_PICKER_MODAL);
2525
}
2626

2727
override async openPicker(

src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class UmbDocumentWorkspaceContext
297297
public async publish() {
298298
new UmbDeprecation({
299299
deprecated: 'The Publish method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.',
300-
removeInVersion: '17',
300+
removeInVersion: '17.0.0',
301301
solution: 'Use the Publish method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.',
302302
}).warn();
303303
if (!this.#publishingContext) throw new Error('Publishing context is missing');
@@ -311,7 +311,7 @@ export class UmbDocumentWorkspaceContext
311311
public async saveAndPublish(): Promise<void> {
312312
new UmbDeprecation({
313313
deprecated: 'The SaveAndPublish method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.',
314-
removeInVersion: '17',
314+
removeInVersion: '17.0.0',
315315
solution: 'Use the SaveAndPublish method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.',
316316
}).warn();
317317
if (!this.#publishingContext) throw new Error('Publishing context is missing');
@@ -325,7 +325,7 @@ export class UmbDocumentWorkspaceContext
325325
public async schedule() {
326326
new UmbDeprecation({
327327
deprecated: 'The Schedule method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.',
328-
removeInVersion: '17',
328+
removeInVersion: '17.0.0',
329329
solution: 'Use the Schedule method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.',
330330
}).warn();
331331
if (!this.#publishingContext) throw new Error('Publishing context is missing');
@@ -339,7 +339,7 @@ export class UmbDocumentWorkspaceContext
339339
public async unpublish() {
340340
new UmbDeprecation({
341341
deprecated: 'The Unpublish method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.',
342-
removeInVersion: '17',
342+
removeInVersion: '17.0.0',
343343
solution: 'Use the Unpublish method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.',
344344
}).warn();
345345
if (!this.#publishingContext) throw new Error('Publishing context is missing');
@@ -353,7 +353,7 @@ export class UmbDocumentWorkspaceContext
353353
public async publishWithDescendants() {
354354
new UmbDeprecation({
355355
deprecated: 'The PublishWithDescendants method on the UMB_DOCUMENT_WORKSPACE_CONTEXT is deprecated.',
356-
removeInVersion: '17',
356+
removeInVersion: '17.0.0',
357357
solution: 'Use the PublishWithDescendants method on the UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT instead.',
358358
}).warn();
359359
if (!this.#publishingContext) throw new Error('Publishing context is missing');

src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-rich-media/input-rich-media.element.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ export class UmbInputRichMediaElement extends UmbFormControlMixin<
173173
@state()
174174
private _routeBuilder?: UmbModalRouteBuilder;
175175

176-
readonly #itemManager = new UmbRepositoryItemsManager<UmbMediaItemModel>(
177-
this,
178-
UMB_MEDIA_ITEM_REPOSITORY_ALIAS,
179-
(x) => x.unique,
180-
);
176+
readonly #itemManager = new UmbRepositoryItemsManager<UmbMediaItemModel>(this, UMB_MEDIA_ITEM_REPOSITORY_ALIAS);
181177

182178
constructor() {
183179
super();

src/Umbraco.Web.UI.Client/src/packages/webhook/webhook/repository/detail/webhook-detail.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class UmbWebhookDetailRepository extends UmbDetailRepositoryBase<UmbWebho
2222
async requestEvents(): Promise<{ data: { items: string[]; total: number }; error: any }> {
2323
new UmbDeprecation({
2424
deprecated: 'The requestEvents method on the UmbWebhookDetailRepository is deprecated.',
25-
removeInVersion: '17',
25+
removeInVersion: '17.0.0',
2626
solution: 'Use the requestEvents method on UmbWebhookEventRepository instead.',
2727
}).warn();
2828

0 commit comments

Comments
 (0)