117287: Fixed group form not working correctly anymore when switching between different groups

Also fixed edit ePerson not showing the group names
This commit is contained in:
Alexandre Vryghem
2024-10-29 17:02:42 +01:00
parent f03ed89687
commit 59e5f71a73
2 changed files with 32 additions and 18 deletions

View File

@@ -71,7 +71,9 @@
{{ dsoNameService.getName(group) }} {{ dsoNameService.getName(group) }}
</a> </a>
</td> </td>
<td class="align-middle">{{ dsoNameService.getName(undefined) }}</td> <td class="align-middle">
{{ dsoNameService.getName((group.object | async)?.payload) }}
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@@ -13,7 +13,7 @@ import {
Observable, Observable,
Subscription, combineLatest, Subscription, combineLatest,
} from 'rxjs'; } from 'rxjs';
import { map, switchMap, take, debounceTime, startWith, filter } from 'rxjs/operators'; import { map, switchMap, take, debounceTime } from 'rxjs/operators';
import { getCollectionEditRolesRoute } from '../../../collection-page/collection-page-routing-paths'; import { getCollectionEditRolesRoute } from '../../../collection-page/collection-page-routing-paths';
import { getCommunityEditRolesRoute } from '../../../community-page/community-page-routing-paths'; import { getCommunityEditRolesRoute } from '../../../community-page/community-page-routing-paths';
import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service'; import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service';
@@ -35,7 +35,7 @@ import {
} from '../../../core/shared/operators'; } from '../../../core/shared/operators';
import { AlertType } from '../../../shared/alert/aletr-type'; import { AlertType } from '../../../shared/alert/aletr-type';
import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component'; import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component';
import { hasValue, isNotEmpty, hasValueOperator, hasNoValue } from '../../../shared/empty.util'; import { hasValue, isNotEmpty, hasValueOperator } from '../../../shared/empty.util';
import { FormBuilderService } from '../../../shared/form/builder/form-builder.service'; import { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { followLink } from '../../../shared/utils/follow-link-config.model'; import { followLink } from '../../../shared/utils/follow-link-config.model';
@@ -164,11 +164,16 @@ export class GroupFormComponent implements OnInit, OnDestroy {
this.activeGroupLinkedDSO$ = this.getActiveGroupLinkedDSO(); this.activeGroupLinkedDSO$ = this.getActiveGroupLinkedDSO();
this.linkedEditRolesRoute$ = this.getLinkedEditRolesRoute(); this.linkedEditRolesRoute$ = this.getLinkedEditRolesRoute();
this.canEdit$ = this.activeGroupLinkedDSO$.pipe( this.canEdit$ = this.activeGroupLinkedDSO$.pipe(
filter((dso: DSpaceObject) => hasNoValue(dso)), switchMap((dso: DSpaceObject) => {
switchMap(() => this.activeGroup$), if (hasValue(dso)) {
return [false];
} else {
return this.activeGroup$.pipe(
hasValueOperator(), hasValueOperator(),
switchMap((group: Group) => this.authorizationService.isAuthorized(FeatureID.CanDelete, group.self)), switchMap((group: Group) => this.authorizationService.isAuthorized(FeatureID.CanDelete, group.self)),
startWith(false), );
}
}),
); );
this.initialisePage(); this.initialisePage();
} }
@@ -216,7 +221,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
combineLatest([ combineLatest([
this.activeGroup$, this.activeGroup$,
this.canEdit$, this.canEdit$,
this.activeGroupLinkedDSO$.pipe(take(1)), this.activeGroupLinkedDSO$,
]).subscribe(([activeGroup, canEdit, linkedObject]) => { ]).subscribe(([activeGroup, canEdit, linkedObject]) => {
if (activeGroup != null) { if (activeGroup != null) {
@@ -224,25 +229,31 @@ export class GroupFormComponent implements OnInit, OnDestroy {
// Disable group name exists validator // Disable group name exists validator
this.formGroup.controls.groupName.clearAsyncValidators(); this.formGroup.controls.groupName.clearAsyncValidators();
if (linkedObject?.name) { if (isNotEmpty(linkedObject?.name)) {
if (!this.formGroup.controls.groupCommunity) {
this.formBuilderService.insertFormGroupControl(1, this.formGroup, this.formModel, groupCommunityModel); this.formBuilderService.insertFormGroupControl(1, this.formGroup, this.formModel, groupCommunityModel);
this.groupDescription = this.formGroup.get('groupCommunity'); this.groupDescription = this.formGroup.get('groupCommunity');
}
this.formGroup.patchValue({ this.formGroup.patchValue({
groupName: activeGroup.name, groupName: activeGroup.name,
groupCommunity: linkedObject?.name ?? '', groupCommunity: linkedObject?.name ?? '',
groupDescription: activeGroup.firstMetadataValue('dc.description'), groupDescription: activeGroup.firstMetadataValue('dc.description'),
}); });
} else { } else {
this.formModel = [
groupNameModel,
groupDescriptionModel,
];
this.formGroup.patchValue({ this.formGroup.patchValue({
groupName: activeGroup.name, groupName: activeGroup.name,
groupDescription: activeGroup.firstMetadataValue('dc.description'), groupDescription: activeGroup.firstMetadataValue('dc.description'),
}); });
} }
setTimeout(() => {
if (!canEdit || activeGroup.permanent) { if (!canEdit || activeGroup.permanent) {
this.formGroup.disable(); this.formGroup.disable();
} else {
this.formGroup.enable();
} }
}, 200);
} }
}) })
); );
@@ -471,6 +482,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
*/ */
getLinkedEditRolesRoute(): Observable<string> { getLinkedEditRolesRoute(): Observable<string> {
return this.activeGroupLinkedDSO$.pipe( return this.activeGroupLinkedDSO$.pipe(
hasValueOperator(),
map((dso: DSpaceObject) => { map((dso: DSpaceObject) => {
switch ((dso as any).type) { switch ((dso as any).type) {
case Community.type.value: case Community.type.value:
@@ -478,7 +490,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
case Collection.type.value: case Collection.type.value:
return getCollectionEditRolesRoute(dso.id); return getCollectionEditRolesRoute(dso.id);
} }
}) }),
); );
} }
} }