@@ -9,11 +9,13 @@ import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
99import { ChangeDetectionStrategy , Component , effect , inject , OnInit , signal } from '@angular/core' ;
1010import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
1111
12- import { GetComponents , ProjectOverviewSelectors } from '@osf/features/project/overview/store' ;
1312import { LoadingSpinnerComponent , TextInputComponent } from '@osf/shared/components' ;
1413import { InputLimits } from '@osf/shared/constants' ;
1514import { CustomValidators } from '@osf/shared/helpers' ;
16- import { ViewOnlyLinkComponent } from '@shared/models' ;
15+ import { CurrentResourceSelectors , GetResourceChildren } from '@osf/shared/stores' ;
16+ import { ViewOnlyLinkChildren } from '@shared/models' ;
17+
18+ import { ResourceInfoModel } from '../../models' ;
1719
1820@Component ( {
1921 selector : 'osf-create-view-link-dialog' ,
@@ -31,44 +33,42 @@ import { ViewOnlyLinkComponent } from '@shared/models';
3133 changeDetection : ChangeDetectionStrategy . OnPush ,
3234} )
3335export class CreateViewLinkDialogComponent implements OnInit {
34- linkName = new FormControl ( '' , { nonNullable : true , validators : [ CustomValidators . requiredTrimmed ( ) ] } ) ;
35-
3636 readonly dialogRef = inject ( DynamicDialogRef ) ;
37- protected readonly config = inject ( DynamicDialogConfig ) ;
38- inputLimits = InputLimits ;
37+ readonly config = inject ( DynamicDialogConfig ) ;
38+ readonly inputLimits = InputLimits ;
39+
40+ linkName = new FormControl ( '' , { nonNullable : true , validators : [ CustomValidators . requiredTrimmed ( ) ] } ) ;
3941
4042 anonymous = signal ( true ) ;
41- protected selectedComponents = signal < Record < string , boolean > > ( { } ) ;
42- protected components = select ( ProjectOverviewSelectors . getComponents ) ;
43- protected isLoading = select ( ProjectOverviewSelectors . getComponentsLoading ) ;
43+ selectedComponents = signal < Record < string , boolean > > ( { } ) ;
44+ components = select ( CurrentResourceSelectors . getResourceChildren ) ;
45+ isLoading = select ( CurrentResourceSelectors . isResourceChildrenLoading ) ;
4446
45- protected actions = createDispatchMap ( {
46- getComponents : GetComponents ,
47- } ) ;
47+ actions = createDispatchMap ( { getComponents : GetResourceChildren } ) ;
4848
49- get currentProjectId ( ) : string {
50- return this . config . data ?. [ 'projectId' ] || '' ;
49+ get currentResource ( ) {
50+ return this . config . data as ResourceInfoModel ;
5151 }
5252
53- get allComponents ( ) : ViewOnlyLinkComponent [ ] {
54- const currentProjectData = this . config . data ?. [ 'currentProject' ] ;
53+ get allComponents ( ) : ViewOnlyLinkChildren [ ] {
54+ const currentResourceData = this . currentResource ;
5555 const components = this . components ( ) ;
5656
57- const result : ViewOnlyLinkComponent [ ] = [ ] ;
57+ const result : ViewOnlyLinkChildren [ ] = [ ] ;
5858
59- if ( currentProjectData ) {
59+ if ( currentResourceData ) {
6060 result . push ( {
61- id : currentProjectData . id ,
62- title : currentProjectData . title ,
63- isCurrentProject : true ,
61+ id : currentResourceData . id ,
62+ title : currentResourceData . title ,
63+ isCurrentResource : true ,
6464 } ) ;
6565 }
6666
6767 components . forEach ( ( comp ) => {
6868 result . push ( {
6969 id : comp . id ,
7070 title : comp . title ,
71- isCurrentProject : false ,
71+ isCurrentResource : false ,
7272 } ) ;
7373 } ) ;
7474
@@ -85,10 +85,10 @@ export class CreateViewLinkDialogComponent implements OnInit {
8585 }
8686
8787 ngOnInit ( ) : void {
88- const projectId = this . currentProjectId ;
88+ const projectId = this . currentResource . id ;
8989
9090 if ( projectId ) {
91- this . actions . getComponents ( projectId ) ;
91+ this . actions . getComponents ( projectId , this . currentResource . type ) ;
9292 } else {
9393 this . initializeSelection ( ) ;
9494 }
@@ -98,28 +98,20 @@ export class CreateViewLinkDialogComponent implements OnInit {
9898 const initialState : Record < string , boolean > = { } ;
9999
100100 this . allComponents . forEach ( ( component ) => {
101- initialState [ component . id ] = component . isCurrentProject ;
101+ initialState [ component . id ] = component . isCurrentResource ;
102102 } ) ;
103103
104104 this . selectedComponents . set ( initialState ) ;
105105 }
106106
107- isCurrentProject ( item : ViewOnlyLinkComponent ) : boolean {
108- return item . isCurrentProject ;
109- }
110-
111- get isFormValid ( ) : boolean {
112- return this . linkName . valid && ! ! this . linkName . value . trim ( ) . length ;
113- }
114-
115107 addLink ( ) : void {
116- if ( ! this . isFormValid ) return ;
108+ if ( this . linkName . invalid ) return ;
117109
118110 const selectedIds = Object . entries ( this . selectedComponents ( ) )
119111 . filter ( ( [ , checked ] ) => checked )
120112 . map ( ( [ id ] ) => id ) ;
121113
122- const rootProjectId = this . currentProjectId ;
114+ const rootProjectId = this . currentResource . id ;
123115 const rootProject = selectedIds . includes ( rootProjectId ) ? [ { id : rootProjectId , type : 'nodes' } ] : [ ] ;
124116
125117 const relationshipComponents = selectedIds
@@ -160,7 +152,7 @@ export class CreateViewLinkDialogComponent implements OnInit {
160152 deselectAllComponents ( ) : void {
161153 const allIds : Record < string , boolean > = { } ;
162154 this . allComponents . forEach ( ( component ) => {
163- allIds [ component . id ] = component . isCurrentProject ;
155+ allIds [ component . id ] = component . isCurrentResource ;
164156 } ) ;
165157 this . selectedComponents . set ( allIds ) ;
166158 }
0 commit comments