@@ -13,7 +13,7 @@ import {
1313 Observable ,
1414 Subscription , combineLatest ,
1515} from 'rxjs' ;
16- import { map , switchMap , take , debounceTime , startWith , filter } from 'rxjs/operators' ;
16+ import { map , switchMap , take , debounceTime } from 'rxjs/operators' ;
1717import { getCollectionEditRolesRoute } from '../../../collection-page/collection-page-routing-paths' ;
1818import { getCommunityEditRolesRoute } from '../../../community-page/community-page-routing-paths' ;
1919import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service' ;
@@ -35,7 +35,7 @@ import {
3535} from '../../../core/shared/operators' ;
3636import { AlertType } from '../../../shared/alert/aletr-type' ;
3737import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component' ;
38- import { hasValue , isNotEmpty , hasValueOperator , hasNoValue } from '../../../shared/empty.util' ;
38+ import { hasValue , isNotEmpty , hasValueOperator } from '../../../shared/empty.util' ;
3939import { FormBuilderService } from '../../../shared/form/builder/form-builder.service' ;
4040import { NotificationsService } from '../../../shared/notifications/notifications.service' ;
4141import { followLink } from '../../../shared/utils/follow-link-config.model' ;
@@ -164,11 +164,16 @@ export class GroupFormComponent implements OnInit, OnDestroy {
164164 this . activeGroupLinkedDSO$ = this . getActiveGroupLinkedDSO ( ) ;
165165 this . linkedEditRolesRoute$ = this . getLinkedEditRolesRoute ( ) ;
166166 this . canEdit$ = this . activeGroupLinkedDSO$ . pipe (
167- filter ( ( dso : DSpaceObject ) => hasNoValue ( dso ) ) ,
168- switchMap ( ( ) => this . activeGroup$ ) ,
169- hasValueOperator ( ) ,
170- switchMap ( ( group : Group ) => this . authorizationService . isAuthorized ( FeatureID . CanDelete , group . self ) ) ,
171- startWith ( false ) ,
167+ switchMap ( ( dso : DSpaceObject ) => {
168+ if ( hasValue ( dso ) ) {
169+ return [ false ] ;
170+ } else {
171+ return this . activeGroup$ . pipe (
172+ hasValueOperator ( ) ,
173+ switchMap ( ( group : Group ) => this . authorizationService . isAuthorized ( FeatureID . CanDelete , group . self ) ) ,
174+ ) ;
175+ }
176+ } ) ,
172177 ) ;
173178 this . initialisePage ( ) ;
174179 }
@@ -216,33 +221,39 @@ export class GroupFormComponent implements OnInit, OnDestroy {
216221 combineLatest ( [
217222 this . activeGroup$ ,
218223 this . canEdit$ ,
219- this . activeGroupLinkedDSO$ . pipe ( take ( 1 ) ) ,
224+ this . activeGroupLinkedDSO$ ,
220225 ] ) . subscribe ( ( [ activeGroup , canEdit , linkedObject ] ) => {
221226
222227 if ( activeGroup != null ) {
223228
224229 // Disable group name exists validator
225230 this . formGroup . controls . groupName . clearAsyncValidators ( ) ;
226231
227- if ( linkedObject ?. name ) {
228- this . formBuilderService . insertFormGroupControl ( 1 , this . formGroup , this . formModel , groupCommunityModel ) ;
229- this . groupDescription = this . formGroup . get ( 'groupCommunity' ) ;
232+ if ( isNotEmpty ( linkedObject ?. name ) ) {
233+ if ( ! this . formGroup . controls . groupCommunity ) {
234+ this . formBuilderService . insertFormGroupControl ( 1 , this . formGroup , this . formModel , groupCommunityModel ) ;
235+ this . groupDescription = this . formGroup . get ( 'groupCommunity' ) ;
236+ }
230237 this . formGroup . patchValue ( {
231238 groupName : activeGroup . name ,
232239 groupCommunity : linkedObject ?. name ?? '' ,
233240 groupDescription : activeGroup . firstMetadataValue ( 'dc.description' ) ,
234241 } ) ;
235242 } else {
243+ this . formModel = [
244+ groupNameModel ,
245+ groupDescriptionModel ,
246+ ] ;
236247 this . formGroup . patchValue ( {
237248 groupName : activeGroup . name ,
238249 groupDescription : activeGroup . firstMetadataValue ( 'dc.description' ) ,
239250 } ) ;
240251 }
241- setTimeout ( ( ) => {
242- if ( ! canEdit || activeGroup . permanent ) {
243- this . formGroup . disable ( ) ;
244- }
245- } , 200 ) ;
252+ if ( ! canEdit || activeGroup . permanent ) {
253+ this . formGroup . disable ( ) ;
254+ } else {
255+ this . formGroup . enable ( ) ;
256+ }
246257 }
247258 } )
248259 ) ;
@@ -471,14 +482,15 @@ export class GroupFormComponent implements OnInit, OnDestroy {
471482 */
472483 getLinkedEditRolesRoute ( ) : Observable < string > {
473484 return this . activeGroupLinkedDSO$ . pipe (
485+ hasValueOperator ( ) ,
474486 map ( ( dso : DSpaceObject ) => {
475487 switch ( ( dso as any ) . type ) {
476488 case Community . type . value :
477489 return getCommunityEditRolesRoute ( dso . id ) ;
478490 case Collection . type . value :
479491 return getCollectionEditRolesRoute ( dso . id ) ;
480492 }
481- } )
493+ } ) ,
482494 ) ;
483495 }
484496}
0 commit comments