Fix back button behavior on roles page

This commit is contained in:
abhinav
2025-05-23 13:56:46 +02:00
parent ca92b4cf0e
commit 084cad6e46
2 changed files with 10 additions and 1 deletions

View File

@@ -38,6 +38,8 @@ import { NoContent } from '../../../core/shared/NoContent.model';
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock } from '../../../shared/mocks/dso-name.service.mock'; import { DSONameServiceMock } from '../../../shared/mocks/dso-name.service.mock';
import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub'; import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub';
import { routeServiceStub } from '../../../shared/testing/route-service.stub';
import { RouteService } from '../../../core/services/route.service';
describe('GroupFormComponent', () => { describe('GroupFormComponent', () => {
let component: GroupFormComponent; let component: GroupFormComponent;
@@ -230,6 +232,7 @@ describe('GroupFormComponent', () => {
{ provide: ActivatedRoute, useValue: route }, { provide: ActivatedRoute, useValue: route },
{ provide: Router, useValue: router }, { provide: Router, useValue: router },
{ provide: AuthorizationDataService, useValue: authorizationService }, { provide: AuthorizationDataService, useValue: authorizationService },
{ provide: RouteService, useValue: routeServiceStub },
], ],
schemas: [CUSTOM_ELEMENTS_SCHEMA], schemas: [CUSTOM_ELEMENTS_SCHEMA],
}).compileComponents(); }).compileComponents();

View File

@@ -46,6 +46,7 @@ import { ValidateGroupExists } from './validators/group-exists.validator';
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
import { environment } from '../../../../environments/environment'; import { environment } from '../../../../environments/environment';
import { getGroupEditRoute, getGroupsRoute } from '../../access-control-routing-paths'; import { getGroupEditRoute, getGroupsRoute } from '../../access-control-routing-paths';
import { RouteService } from '../../../core/services/route.service';
@Component({ @Component({
selector: 'ds-group-form', selector: 'ds-group-form',
@@ -155,6 +156,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
public requestService: RequestService, public requestService: RequestService,
protected changeDetectorRef: ChangeDetectorRef, protected changeDetectorRef: ChangeDetectorRef,
public dsoNameService: DSONameService, public dsoNameService: DSONameService,
protected routeService: RouteService,
) { ) {
} }
@@ -267,7 +269,11 @@ export class GroupFormComponent implements OnInit, OnDestroy {
onCancel() { onCancel() {
this.groupDataService.cancelEditGroup(); this.groupDataService.cancelEditGroup();
this.cancelForm.emit(); this.cancelForm.emit();
void this.router.navigate([getGroupsRoute()]); this.routeService.getPreviousUrl().pipe(
take(1),
).subscribe((previousURL) => {
void this.router.navigate([previousURL && previousURL.trim().length > 0 ? previousURL : getGroupsRoute()]);
});
} }
/** /**