Skip to content

feat(es2): Load cedar template by ID instead of via the list endpoint#1022

Open
adlius wants to merge 2 commits into
CenterForOpenScience:hotfix/26.12.2from
adlius:fix-cedar-template-loading
Open

feat(es2): Load cedar template by ID instead of via the list endpoint#1022
adlius wants to merge 2 commits into
CenterForOpenScience:hotfix/26.12.2from
adlius:fix-cedar-template-loading

Conversation

@adlius

@adlius adlius commented Jun 27, 2026

Copy link
Copy Markdown
Contributor
  • Ticket: []
  • Feature flag: n/a

Purpose

Summary of Changes

Screenshot(s)

Side Effects

QA Notes

);
}

getMetadataCedarTemplate(id: string): Observable<{ data: CedarMetadataDataTemplateJsonApi }> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
getMetadataCedarTemplate(id: string): Observable<{ data: CedarMetadataDataTemplateJsonApi }> {
getMetadataCedarTemplate(id: string): Observable<ResponseDataJsonApi<CedarMetadataDataTemplateJsonApi>> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use this interface.

}

getMetadataCedarTemplate(id: string): Observable<{ data: CedarMetadataDataTemplateJsonApi }> {
return this.jsonApiService.get<{ data: CedarMetadataDataTemplateJsonApi }>(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return this.jsonApiService.get<{ data: CedarMetadataDataTemplateJsonApi }>(
return this.jsonApiService.get<ResponseDataJsonApi<CedarMetadataDataTemplateJsonApi>>(

Comment on lines +149 to +157
missingIds.forEach((id) => {
this.metadataService
.getMetadataCedarTemplate(id)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((response) => {
this.cedarTemplatesMap.update((map) => new Map(map).set(id, response.data));
});
});
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move cedar template loading into NGXS: dispatch GetCedarMetadataTemplatesByIds(templateIds) when records load, cache templates in store, and read them with a selector. The component should only dispatch and select — no local Map, no subscribe.
We can discuss it if needed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also why do we need to get each template by ID instead of via the list?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Also why do we need to get each template by ID instead of via the list?"

This is standard procedure when working with the v2 API. If we have an ID for something, then we use the detail endpoint with the ID to get the item. This prevents us from having to request more data than we need for the individual item, and it prevents us from having to iterate through items to find the thing we need.


const currentMap = this.cedarTemplatesMap();
const missingIds = [
...new Set(records.map((r) => r.relationships?.template?.data?.id).filter((id): id is string => !!id)),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need new Set here? Doesn't the back end already return unique IDs?

Comment on lines +574 to +579
this.metadataService
.getMetadataCedarTemplate(templateId)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((response) => {
this.selectedCedarTemplate.set(response.data);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use one shared action GetCedarMetadataTemplatesByIds here and in project-overview-metadata — same cache in store, different selectors for reading. Move template loading out of the component: dispatch ids, read from store, no subscribe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants