Skip to content

Commit

Permalink
chore: fix the navigation
Browse files Browse the repository at this point in the history
When a resource is added or modified, it is not always returned
to the correct page. The editor now uses the previous url to redirect.

* Closes rero/rero-ils#3628.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Apr 30, 2024
1 parent 71e6a2e commit 15442de
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions projects/rero/ng-core/src/lib/record/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { Location } from '@angular/common';
import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core';
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
import { TranslateService } from '@ngx-translate/core';
Expand Down Expand Up @@ -138,6 +138,9 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
// Observable of hidden fields
private _hiddenFieldsSubject: BehaviorSubject<FormlyFieldConfig[]> = new BehaviorSubject([]);

// Previous Url for navigation
private previousUrl?: string = undefined;

// current list of hidden fields
public get hiddenFields$(): Observable<any[]> {
return this._hiddenFieldsSubject.asObservable();
Expand Down Expand Up @@ -176,6 +179,7 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
* @param modalService BsModalService.
* @param routeCollectionService RouteCollectionService
* @param loggerService LoggerService
* @param router Router
*/
constructor(
protected formlyJsonschema: FormlyJsonschema,
Expand All @@ -188,10 +192,12 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
protected location: Location,
protected modalService: BsModalService,
protected routeCollectionService: RouteCollectionService,
protected loggerService: LoggerService
protected loggerService: LoggerService,
protected router: Router
) {
super();
this.form = new UntypedFormGroup({});
this.previousUrl = this.router.getCurrentNavigation().previousNavigation?.extractedUrl?.toString();
}

/**
Expand Down Expand Up @@ -576,13 +582,17 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
this.translateService.instant(result.message),
this.translateService.instant(this.recordType)
);
this.recordUiService.redirectAfterSave(
result.record.id,
result.record,
this.recordType,
result.action,
this.route
);
if (this.previousUrl) {
this.router.navigateByUrl(this.previousUrl);
} else {
this.recordUiService.redirectAfterSave(
result.record.id,
result.record,
this.recordType,
result.action,
this.route
);
}
this.loadingChange.emit(true);
});
}
Expand Down

0 comments on commit 15442de

Please sign in to comment.