Skip to content
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

Feature: Data mapping extension + aligning reference lists #18318

Open
wants to merge 111 commits into
base: v15/dev
Choose a base branch
from

Conversation

madsrasmussen
Copy link
Contributor

@madsrasmussen madsrasmussen commented Feb 13, 2025

Build on top of #18311 - Review this first

This PR implements a fully dynamic approach to listing references in a document/media workspace supporting the polymorphic response from the server.

Until now, the reference lists have had a hardcoded solution with support for document, media, and member entities. With this PR, we use the entityRefItem extension to render a reference based on the entity type in the data.

The reference endpoint returns a "mixed" response, which can consist of multiple entity types. The endpoint doesn't specify the entity type of an entry but only the type of the response model. To prevent a hardcoded solution, the PR introduces a dataMapping extension that can map any data based on an identifier in the data.

Manifest:

 {
  type: 'dataMapping',
  alias: 'Umb.DataMapping.ManagementApi.DocumentReferenceResponse',
  name: 'Document Reference Response Management Api Data Mapping',
  api: () => import('./document-reference-response-model.mapper.js'),
  dataSourceIdentifier: 'Umb.ManagementApi',
  dataModelIdentifier: 'DocumentReferenceResponseModel',
 },

Example:

export class UmbDocumentReferenceResponseManagementApiDataMapping
  extends UmbControllerBase
  implements UmbDataMapping<DocumentReferenceResponseModel, UmbDocumentReferenceModel> {

  async map(data: DocumentReferenceResponseModel): Promise<UmbDocumentReferenceModel> {
    return {
      // map data here
    };
  }
}

export { UmbDocumentReferenceResponseManagementApiDataMapping as api };

@madsrasmussen madsrasmussen marked this pull request as ready for review February 17, 2025 14:10
@madsrasmussen madsrasmussen added release/15.3.0 category/ux User experience category/dx Developer experience labels Feb 17, 2025
@madsrasmussen madsrasmussen changed the title Feature: Data mapper extension + aligning reference lists Feature: Data mapping extension + aligning reference lists Feb 17, 2025
Base automatically changed from v15/feature/display-current-variant-item-name to v15/dev February 18, 2025 18:52
# Conflicts:
#	src/Umbraco.Web.UI.Client/src/packages/documents/documents/item/document-item-ref.element.ts
export interface ManifestDataMapping<MetaType extends MetaDataMapping = MetaDataMapping>
extends ManifestApi<UmbDataMapping> {
type: 'dataMapping';
dataSourceIdentifier: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the dataSourceIdentifier and dataModelIdentifier be defined in the meta to be consistent with other manifest types? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been back and forth with these. We only use them for filtering so I saw them in the same category as the forEntitypes field. Maybe they should have been named forDataSource and forDataModel? 🤔

I have no problem moving them if they fit better in meta?

Copy link
Member

@nielslyngsoe nielslyngsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madsrasmussen I just have one thing that I like you to consider and then I'm happy, I have read all the code and tested the various cases.

@nielslyngsoe nielslyngsoe enabled auto-merge (squash) February 18, 2025 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants