-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Entity Data Picker: Fix "Not Found" in remove dialog for entities without a top-level name #22915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
leekelleher
merged 7 commits into
release/17.5.0
from
v17/hotfix/entity-data-picker-resolve-item-name
May 21, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e8d514e
Add item data resolver support to picker data sources
madsrasmussen dbfeb6a
add js docs
madsrasmussen 845bf62
remove duplicated fallback logic
madsrasmussen 8edf80a
wip unit tests of requestItemName method
madsrasmussen 9c8e2c3
Use DocumentVariantStateModel in mock documents to fix compiler
madsrasmussen 0145b91
Update input-entity-data.context.ts
madsrasmussen 0e22a5a
Update input-entity-data.context.test.ts
madsrasmussen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
src/Umbraco.Web.UI.Client/src/packages/core/picker-data-source/data-source/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,20 @@ | ||
| import type { UmbItemModel } from '@umbraco-cms/backoffice/entity-item'; | ||
| import type { UmbItemDataResolver, UmbItemModel } from '@umbraco-cms/backoffice/entity-item'; | ||
| import type { UmbApi } from '@umbraco-cms/backoffice/extension-api'; | ||
| import type { UmbItemRepository } from '@umbraco-cms/backoffice/repository'; | ||
| import type { UmbConfigCollectionModel } from '@umbraco-cms/backoffice/utils'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
|
|
||
| export interface UmbPickerDataSource<PickedItemType extends UmbItemModel = UmbItemModel> | ||
| extends UmbItemRepository<PickedItemType>, | ||
| UmbApi { | ||
| setConfig?(config: UmbConfigCollectionModel | undefined): void; | ||
| getConfig?(): UmbConfigCollectionModel | undefined; | ||
|
|
||
| /** | ||
| * Creates an item data resolver for this data source, bound to the given host. | ||
| * Pass the consuming element or context as host so the resolver can reach local DOM contexts (e.g. `UMB_VARIANT_CONTEXT`). | ||
| * @param {UmbControllerHost} host The controller host of the picker consumer. | ||
| * @returns {UmbItemDataResolver} A resolver that can provide the display name, icon, and other metadata for an item. | ||
| */ | ||
| createItemDataResolver?(host: UmbControllerHost): UmbItemDataResolver; | ||
| } | ||
145 changes: 145 additions & 0 deletions
145
.../src/packages/property-editors/entity-data-picker/input/input-entity-data.context.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| import { expect } from '@open-wc/testing'; | ||
| import { customElement } from '@umbraco-cms/backoffice/external/lit'; | ||
| import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; | ||
| import { UmbControllerHostElementMixin } from '@umbraco-cms/backoffice/controller-api'; | ||
| import { UmbObjectState, UmbStringState } from '@umbraco-cms/backoffice/observable-api'; | ||
| import { UmbEntityDataPickerInputContext } from './input-entity-data.context.js'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
| import type { UmbItemDataResolver, UmbItemModel } from '@umbraco-cms/backoffice/entity-item'; | ||
| import type { UmbPickerDataSource } from '@umbraco-cms/backoffice/picker-data-source'; | ||
| import type { Observable } from '@umbraco-cms/backoffice/observable-api'; | ||
|
|
||
| // A test entity model that has a label instead of name, simulating entities like Document | ||
| // where names are variant-dependent and not stored as a top-level property. | ||
| interface UmbTestItemModel extends UmbItemModel { | ||
| label: string; | ||
| } | ||
|
|
||
| // A resolver that derives its display name from item.label, not from any constructor argument. | ||
| // This guarantees the resolver path is genuinely exercised — item.name is undefined for | ||
| // UmbTestItemModel, so any name returned must come through setData/label. | ||
| class UmbTestItemDataResolver extends UmbControllerBase implements UmbItemDataResolver<UmbTestItemModel> { | ||
| #data = new UmbObjectState<UmbTestItemModel | undefined>(undefined); | ||
|
|
||
| public readonly entityType = this.#data.asObservablePart((x) => x?.entityType); | ||
| public readonly unique = this.#data.asObservablePart((x) => x?.unique); | ||
| public readonly icon = this.#data.asObservablePart((x) => x?.icon ?? undefined); | ||
|
|
||
| #name = new UmbStringState(undefined); | ||
| public readonly name: Observable<string | undefined> = this.#name.asObservable(); | ||
|
|
||
| setData(data: UmbTestItemModel | undefined) { | ||
| this.#data.setValue(data); | ||
| this.#name.setValue(data?.label); | ||
| } | ||
|
|
||
| getData(): UmbTestItemModel | undefined { | ||
| return this.#data.getValue(); | ||
| } | ||
|
|
||
| async getEntityType(): Promise<string | undefined> { | ||
| return this.observe(this.entityType).asPromise(); | ||
| } | ||
|
|
||
| async getUnique(): Promise<string | undefined> { | ||
| return this.observe(this.unique).asPromise(); | ||
| } | ||
|
|
||
| async getName(): Promise<string | undefined> { | ||
| return this.#name.getValue(); | ||
| } | ||
|
|
||
| async getIcon(): Promise<string | undefined> { | ||
| return this.observe(this.icon).asPromise(); | ||
| } | ||
| } | ||
|
|
||
| class UmbTestPickerDataSource extends UmbControllerBase implements UmbPickerDataSource<UmbItemModel> { | ||
| requestItems(): ReturnType<UmbPickerDataSource['requestItems']> { | ||
| return Promise.resolve({ data: [] }); | ||
| } | ||
|
|
||
| // requestCollection is required so isPickerCollectionDataSource returns true, | ||
| // allowing #setModalToken to resolve without throwing. | ||
| requestCollection() { | ||
| return Promise.resolve({ data: { items: [], total: 0 } }); | ||
| } | ||
| } | ||
|
|
||
| class UmbTestPickerDataSourceWithResolver extends UmbTestPickerDataSource { | ||
| createItemDataResolver(host: UmbControllerHost): UmbItemDataResolver { | ||
| return new UmbTestItemDataResolver(host); | ||
| } | ||
| } | ||
|
|
||
| @customElement('test-entity-data-picker-context-host') | ||
| class UmbTestControllerHostElement extends UmbControllerHostElementMixin(HTMLElement) {} | ||
|
|
||
| // Exposes the protected _requestItemName method and bypasses the item manager so | ||
| // tests do not need the repository extension to be registered. | ||
| class UmbTestEntityDataPickerInputContext extends UmbEntityDataPickerInputContext { | ||
| #testItems = new Map<string, UmbItemModel>(); | ||
|
|
||
| setTestItem(item: UmbItemModel) { | ||
| this.#testItems.set(item.unique, item); | ||
| } | ||
|
|
||
| override getSelectedItemByUnique(unique: string): UmbItemModel | undefined { | ||
| return this.#testItems.get(unique); | ||
| } | ||
|
|
||
| async requestItemName(unique: string): Promise<string> { | ||
| return this._requestItemName(unique); | ||
| } | ||
| } | ||
|
|
||
| describe('UmbEntityDataPickerInputContext._requestItemName', () => { | ||
| let hostElement: UmbTestControllerHostElement; | ||
| let context: UmbTestEntityDataPickerInputContext; | ||
|
|
||
| beforeEach(() => { | ||
| hostElement = new UmbTestControllerHostElement(); | ||
| document.body.appendChild(hostElement); | ||
| context = new UmbTestEntityDataPickerInputContext(hostElement); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| context.destroy(); | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('should return the name resolved from item data by the data source resolver', async () => { | ||
| const item: UmbTestItemModel = { unique: 'test-1', entityType: 'test', label: 'Resolved Label' }; | ||
| context.setTestItem(item); | ||
| context.setDataSourceApi(new UmbTestPickerDataSourceWithResolver(hostElement)); | ||
|
|
||
| const name = await context.requestItemName('test-1'); | ||
| expect(name).to.equal('Resolved Label'); | ||
| }); | ||
|
|
||
| it('should fall back to item.name when the data source provides no resolver', async () => { | ||
| const item: UmbItemModel = { unique: 'test-2', entityType: 'test', name: 'Item Name' }; | ||
| context.setTestItem(item); | ||
| context.setDataSourceApi(new UmbTestPickerDataSource(hostElement)); | ||
|
|
||
| const name = await context.requestItemName('test-2'); | ||
| expect(name).to.equal('Item Name'); | ||
| }); | ||
|
|
||
| it('should fall back to item.name when the resolver returns undefined', async () => { | ||
| // UmbItemModel has name but no label. UmbTestItemDataResolver reads .label, which is | ||
| // undefined here, so getName() returns undefined — exercising the if(name) guard in | ||
| // _requestItemName and ensuring it falls through to super._requestItemName. | ||
| const item: UmbItemModel = { unique: 'test-3', entityType: 'test', name: 'Fallback Name' }; | ||
| context.setTestItem(item); | ||
| context.setDataSourceApi(new UmbTestPickerDataSourceWithResolver(hostElement)); | ||
|
|
||
| const name = await context.requestItemName('test-3'); | ||
| expect(name).to.equal('Fallback Name'); | ||
| }); | ||
|
|
||
| it('should return #general_notFound when no item is found for the given unique', async () => { | ||
| const name = await context.requestItemName('non-existent'); | ||
| expect(name).to.equal('#general_notFound'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.