From dad97929628bde1d9b47caa183242f9f2deb0384 Mon Sep 17 00:00:00 2001 From: Roman Nastyuk Date: Thu, 2 Oct 2025 14:35:34 +0300 Subject: [PATCH 1/2] fix(ang-905): fixed create component affiliations issue --- .../add-component-dialog.component.html | 9 +++++---- .../add-component-dialog.component.ts | 5 +++++ .../affiliated-institution-select.component.html | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.html b/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.html index ee2298811..6fbc974cc 100644 --- a/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.html +++ b/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.html @@ -6,15 +6,16 @@ - @if (currentProject()?.affiliatedInstitutions?.length) { + @if (areUserInstitutionsLoading() || userInstitutions().length) {
-

+

{{ 'myProjects.createProject.affiliation.title' | translate }}

diff --git a/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts b/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts index 3c3c2b049..8165c6e51 100644 --- a/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts +++ b/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts @@ -20,6 +20,7 @@ import { CustomValidators } from '@osf/shared/helpers'; import { ComponentForm, Institution } from '@osf/shared/models'; import { ToastService } from '@osf/shared/services'; import { FetchRegions, RegionsSelectors } from '@osf/shared/stores'; +import { FetchUserInstitutions, InstitutionsSelectors } from '@osf/shared/stores/institutions'; import { CreateComponent, GetComponents, ProjectOverviewSelectors } from '../../store'; @@ -51,11 +52,14 @@ export class AddComponentDialogComponent implements OnInit { currentProject = select(ProjectOverviewSelectors.getProject); areRegionsLoading = select(RegionsSelectors.areRegionsLoading); isSubmitting = select(ProjectOverviewSelectors.getComponentsSubmitting); + userInstitutions = select(InstitutionsSelectors.getUserInstitutions); + areUserInstitutionsLoading = select(InstitutionsSelectors.areUserInstitutionsLoading); actions = createDispatchMap({ createComponent: CreateComponent, getComponents: GetComponents, getRegions: FetchRegions, + fetchUserInstitutions: FetchUserInstitutions, }); componentForm = new FormGroup({ @@ -96,6 +100,7 @@ export class AddComponentDialogComponent implements OnInit { ngOnInit(): void { this.actions.getRegions(); + this.actions.fetchUserInstitutions(); } setSelectedInstitutions(institutions: Institution[]) { diff --git a/src/app/shared/components/affiliated-institution-select/affiliated-institution-select.component.html b/src/app/shared/components/affiliated-institution-select/affiliated-institution-select.component.html index e7b55e90b..f40a6da50 100644 --- a/src/app/shared/components/affiliated-institution-select/affiliated-institution-select.component.html +++ b/src/app/shared/components/affiliated-institution-select/affiliated-institution-select.component.html @@ -1,5 +1,5 @@ @if (isLoading()) { - + } @else {
From 6244cd19b4a0e90e8f1fdf9133bf8f824668fec5 Mon Sep 17 00:00:00 2001 From: Roman Nastyuk Date: Mon, 6 Oct 2025 17:39:01 +0300 Subject: [PATCH 2/2] fix(ang-905): fixed component creation institutions absence --- .../add-component-dialog.component.ts | 3 ++ .../services/project-overview.service.ts | 32 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts b/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts index b592bf39b..2e603a2d5 100644 --- a/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts +++ b/src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts @@ -157,6 +157,9 @@ export class AddComponentDialogComponent implements OnInit { .filter((inst) => inst !== undefined); this.selectedInstitutions.set(matchedInstitutions); + + const institutionIds = matchedInstitutions.map((inst) => inst.id); + this.componentForm.get(ComponentFormControls.Affiliations)?.setValue(institutionIds); } }); } diff --git a/src/app/features/project/overview/services/project-overview.service.ts b/src/app/features/project/overview/services/project-overview.service.ts index 9fbe5357f..7e7931527 100644 --- a/src/app/features/project/overview/services/project-overview.service.ts +++ b/src/app/features/project/overview/services/project-overview.service.ts @@ -1,5 +1,5 @@ -import { Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; +import { Observable, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { inject, Injectable } from '@angular/core'; @@ -122,11 +122,29 @@ export class ProjectOverviewService { params['region'] = region; } - if (affiliatedInstitutions.length) { - params['affiliated_institutions'] = affiliatedInstitutions; - } - - return this.jsonApiService.post(`${this.apiUrl}/nodes/${projectId}/children/`, payload, params); + return this.jsonApiService + .post>(`${this.apiUrl}/nodes/${projectId}/children/`, payload, params) + .pipe( + switchMap((response) => { + const componentId = response.data.id; + + if (affiliatedInstitutions.length) { + const affiliationsPayload = { + data: affiliatedInstitutions.map((id) => ({ + type: 'institutions', + id, + })), + }; + + return this.jsonApiService.patch( + `${this.apiUrl}/nodes/${componentId}/relationships/institutions/`, + affiliationsPayload + ); + } + + return of(undefined); + }) + ); } deleteComponent(componentId: string): Observable {