Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
RuleCategoryAction,
RuleSearchCriteriaDto,
} from '../../../models/ruleAction.interface';
import { Location } from '@angular/common';

const ARCHIVE_UNIT_HOLDING_UNIT = 'ARCHIVE_UNIT_HOLDING_UNIT';

Expand Down Expand Up @@ -167,6 +168,7 @@ export class ManagementRulesComponent implements OnInit, OnChanges, OnDestroy {
public dialog: MatDialog,
private route: ActivatedRoute,
private router: Router,
private location: Location,
private translate: TranslateService,
private logger: Logger,
private ruleService: RuleService,
Expand Down Expand Up @@ -662,7 +664,7 @@ export class ManagementRulesComponent implements OnInit, OnChanges, OnDestroy {
.pipe(filter((result) => !!result))
.subscribe(() => {
this.initializeParameters();
this.router.navigate(['/archive-search/tenant/', this.tenantIdentifier]);
this.location.back();
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import { Location } from '@angular/common';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
Expand Down Expand Up @@ -129,7 +130,13 @@ describe('ArchiveSearchComponent', () => {
};

const setupTest = async (queryParams: Params) => {
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'createUrlTree', 'serializeUrl', 'parseUrl']);
routerSpy.createUrlTree.and.returnValue({});
routerSpy.serializeUrl.and.returnValue('/test-url');
routerSpy.parseUrl.and.returnValue({ queryParams: {} });

const locationSpy = jasmine.createSpyObj('Location', ['replaceState', 'path']);
locationSpy.path.and.returnValue('/test-url');

spyOn(archiveServiceStub, 'searchArchiveUnitsByCriteria').and.callThrough();

Expand Down Expand Up @@ -157,6 +164,7 @@ describe('ArchiveSearchComponent', () => {
{ provide: ArchiveUnitEliminationService, useValue: archiveUnitEliminationServiceMock },
{ provide: BASE_URL, useValue: '/fake-api' },
{ provide: ComputeInheritedRulesService, useValue: computeInheritedRulesServiceMock },
{ provide: Location, useValue: locationSpy },
{ provide: MatDialog, useValue: matDialogSpy },
{ provide: Router, useValue: routerSpy },
{ provide: SchemaService, useValue: { getDescriptiveSchemaTree: () => of(), getSchema: () => of([]) } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ export class ArchiveSearchComponent implements OnInit, OnChanges, OnDestroy, Aft
this.searchCriteriaKeys = [];
this.included = false;
}
this.applySearchCriteriaHistory(event);
this.clearCriteria();
setTimeout(() => this.applySearchCriteriaHistory(event));
}

emitOrderChange() {
Expand Down Expand Up @@ -767,6 +768,9 @@ export class ArchiveSearchComponent implements OnInit, OnChanges, OnDestroy, Aft
this.subscribeResetNodesOnFilingHoldingNodesChanges();
this.recursiveCheck(this.nodeArray, false);

// Collect all criteria to update URL at once
const criteriaToAddToUrl: any[] = [];

storedSearchCriteriaHistory.searchCriteriaList.forEach((criteria: SearchCriteriaEltements) => {
this.fillTreeNodeAsSearchCriteriaHistory(criteria);

Expand All @@ -789,10 +793,29 @@ export class ArchiveSearchComponent implements OnInit, OnChanges, OnDestroy, Aft
category,
criteria.valueTranslated,
criteria.dataType,
true,
false,
);

// Collect criteria for URL update (only FIELDS and NODES categories)
if ([SearchCriteriaTypeEnum.FIELDS, SearchCriteriaTypeEnum.NODES].includes(category)) {
criteriaToAddToUrl.push({
keyElt: criteria.criteria,
valueElt: value,
labelElt: value.value,
keyTranslated: criteria.keyTranslated,
operator: criteria.operator,
category,
valueTranslated: criteria.valueTranslated,
dataType: criteria.dataType,
});
}
});
});

// Update URL with all restored criteria at once
if (criteriaToAddToUrl.length > 0) {
this.archiveSharedDataService.addSimpleSearchCriteriaSubjects(criteriaToAddToUrl);
}
}

fillTreeNodeAsSearchCriteriaHistory(searchCriteriaList: SearchCriteriaEltements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ export class UpdateUnitManagementRuleService {
this.managementRulesSharedDataService.emitCriteriaSearchListToSave(criteriaSearchList);
this.managementRulesSharedDataService.emitCriteriaSearchDSLQuery(criteriaSearchDSLQueryToSend);

router.navigate(['/archive-search/update-rules/tenant/', tenantIdentifier]);
// Navigate preserving query params in URL to maintain browser history
router.navigate(['/archive-search/update-rules/tenant/', tenantIdentifier], {
queryParamsHandling: 'preserve',
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export class ArchiveSharedDataService {
}
this.simpleSearchCriteriaAddSubject.next(searchCriteria);
});
builder.navigate();

// Update URL with query params and create history entry
builder.navigate({ replaceUrl: false });
}

addSimpleSearchCriteriaSubject(searchCriteria: SearchCriteriaAddAction) {
Expand Down Expand Up @@ -304,7 +306,9 @@ export class ArchiveSharedDataService {
: `${searchCriteriaAction.valueElt.value}/${searchCriteriaAction.valueElt.virtualNodeRealParentId}/${searchCriteriaAction.valueElt.virtualNodeRealParentTitle}`;
builder.removeQueryParam(searchCriteriaAction.valueElt.id, valueToRemove);
this.searchCriteriaRemoveFromChildSubject.next(searchCriteriaAction);
builder.navigate();

// Update URL with query params and create history entry
builder.navigate({ replaceUrl: false });
}

receiveRemoveFromChildSearchCriteriaSubject(): Observable<SearchCriteriaRemoveAction> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import { Location } from '@angular/common';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialog } from '@angular/material/dialog';
Expand Down Expand Up @@ -134,7 +135,13 @@ describe('ArchiveSearchCollectComponent', () => {
};

const setupTest = async (queryParams: Params, withSimpleCriteria = false) => {
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'createUrlTree', 'serializeUrl', 'parseUrl']);
routerSpy.createUrlTree.and.returnValue({});
routerSpy.serializeUrl.and.returnValue('/test-url');
routerSpy.parseUrl.and.returnValue({ queryParams: {} });

const locationSpy = jasmine.createSpyObj('Location', ['replaceState', 'path']);
locationSpy.path.and.returnValue('/test-url');

spyOn(archiveCollectServiceStub, 'searchArchiveUnitsByCriteria').and.callThrough();

Expand Down Expand Up @@ -164,6 +171,7 @@ describe('ArchiveSearchCollectComponent', () => {
{ provide: BASE_URL, useValue: '/fake-api' },
{ provide: ConfigService, useValue: { config$: of() } },
{ provide: ExternalParametersService, useValue: externalParametersServiceStub },
{ provide: Location, useValue: locationSpy },
{ provide: MatDialog, useValue: matDialogSpy },
{ provide: Router, useValue: routerSpy },
{ provide: SchemaService, useValue: { getDescriptiveSchemaTree: () => of(), getSchema: () => of([]) } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,14 +1152,18 @@ export class ArchiveSearchCollectComponent extends SidenavPage<any> implements O
this.searchCriteriaKeys = [];
this.included = false;
}
this.applySearchCriteriaHistory(event);
this.clearCriteria();
setTimeout(() => this.applySearchCriteriaHistory(event));
}

private applySearchCriteriaHistory(storedSearchCriteriaHistory: SearchCriteriaHistory) {
// TODO : to uncomment when filing will be available
// this.setFilingHoldingScheme();
// this.checkAllNodes(false);

// Collect all criteria to update URL at once
const criteriaToAddToUrl: any[] = [];

storedSearchCriteriaHistory.searchCriteriaList.forEach((criteria: SearchCriteriaEltements) => {
this.fillTreeNodeAsSearchCriteriaHistory(criteria);

Expand All @@ -1182,10 +1186,29 @@ export class ArchiveSearchCollectComponent extends SidenavPage<any> implements O
category,
criteria.valueTranslated,
criteria.dataType,
true,
false,
);

// Collect criteria for URL update (only FIELDS and NODES categories)
if ([SearchCriteriaTypeEnum.FIELDS, SearchCriteriaTypeEnum.NODES].includes(category)) {
criteriaToAddToUrl.push({
keyElt: criteria.criteria,
valueElt: value,
labelElt: value.value,
keyTranslated: criteria.keyTranslated,
operator: criteria.operator,
category,
valueTranslated: criteria.valueTranslated,
dataType: criteria.dataType,
});
}
});
});

// Update URL with all restored criteria at once
if (criteriaToAddToUrl.length > 0) {
this.archiveSharedDataService.addSimpleSearchCriteriaSubjects(criteriaToAddToUrl);
}
}

fillTreeNodeAsSearchCriteriaHistory(searchCriteriaList: SearchCriteriaEltements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ export class ArchiveSharedDataService {
}
this.simpleSearchCriteriaAddSubject.next(searchCriteria);
});
builder.navigate();
// Update URL with query params and create history entry
builder.navigate({ replaceUrl: false });
}

addSimpleSearchCriteriaSubject(searchCriteria: SearchCriteriaAddAction) {
Expand Down Expand Up @@ -271,7 +272,9 @@ export class ArchiveSharedDataService {
: `${searchCriteriaAction.valueElt.value}/${searchCriteriaAction.valueElt.virtualNodeRealParentId}/${searchCriteriaAction.valueElt.virtualNodeRealParentTitle}`;
builder.removeQueryParam(searchCriteriaAction.valueElt.id, valueToRemove);
this.searchCriteriaRemoveFromChildSubject.next(searchCriteriaAction);
builder.navigate();

// Update URL with query params and create history entry
builder.navigate({ replaceUrl: false });
}

receiveRemoveFromChildSearchCriteriaSubject(): Observable<SearchCriteriaRemoveAction> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import { Injectable } from '@angular/core';
import { Location } from '@angular/common';
import { ActivatedRoute, NavigationExtras, Params, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { fromPromise } from 'rxjs/internal/observable/innerFrom';
Expand All @@ -43,9 +44,14 @@ class QueryParamBuilder {
#queryParams: Params = {};
constructor(
private router: Router,
route: ActivatedRoute,
private location: Location,
) {
this.#queryParams = { ...route.snapshot.queryParams };
// Use location.path() to get current URL params instead of router.url
// This ensures we get the most up-to-date params, even after Location.replaceState() calls
// router.url is not updated by Location.replaceState(), but location.path() is
const currentPath = this.location.path();
const currentUrlTree = this.router.parseUrl(currentPath);
this.#queryParams = { ...currentUrlTree.queryParams };
}

addQueryParam(key: string, value: string): this {
Expand All @@ -62,6 +68,10 @@ class QueryParamBuilder {
return this;
}

getQueryParams(): Params {
return { ...this.#queryParams };
}

navigate(extras: NavigationExtras = {}): Observable<boolean> {
return fromPromise(
this.router.navigate([], {
Expand All @@ -79,6 +89,7 @@ export class QueryParamsService {
constructor(
private router: Router,
private route: ActivatedRoute,
private location: Location,
) {}

setQueryParams(
Expand All @@ -97,7 +108,7 @@ export class QueryParamsService {
}

builder() {
return new QueryParamBuilder(this.router, this.route);
return new QueryParamBuilder(this.router, this.location);
}

getQueryParams(): Observable<Params> {
Expand Down
Loading