Skip to content

Commit a20056d

Browse files
author
Salim Terres
committed
Bug #15363 && Bug #15398 - [Search + Collect] When saving a search with multiple filters, only one filter is retained && [Search] Default filter "Archives with objects" gets unchecked.
Bug #15363 && Bug #15398 - [Search + Collect] When saving a search with multiple filters, only one filter is retained && [Search] Default filter "Archives with objects" gets unchecked. Bug #15363 && Bug #15398 - [Search + Collect] When saving a search with multiple filters, only one filter is retained && [Search] Default filter "Archives with objects" gets unchecked. Bug #15363 [Search + Collect] – When saving a search with multiple filters, only one filter is retained.
1 parent a39b8fc commit a20056d

File tree

7 files changed

+54
-10
lines changed

7 files changed

+54
-10
lines changed

ui/ui-frontend/projects/archive-search/src/app/archive/archive-search/archive-search.component.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* The fact that you are presently reading this means that you have had
3535
* knowledge of the CeCILL-C license and that you accept its terms.
3636
*/
37+
import { Location } from '@angular/common';
3738
import { provideHttpClientTesting } from '@angular/common/http/testing';
3839
import { NO_ERRORS_SCHEMA } from '@angular/core';
3940
import { ComponentFixture, TestBed } from '@angular/core/testing';
@@ -129,7 +130,11 @@ describe('ArchiveSearchComponent', () => {
129130
};
130131

131132
const setupTest = async (queryParams: Params) => {
132-
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
133+
const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'createUrlTree', 'serializeUrl']);
134+
routerSpy.createUrlTree.and.returnValue({});
135+
routerSpy.serializeUrl.and.returnValue('/test-url');
136+
137+
const locationSpy = jasmine.createSpyObj('Location', ['replaceState']);
133138

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

@@ -157,6 +162,7 @@ describe('ArchiveSearchComponent', () => {
157162
{ provide: ArchiveUnitEliminationService, useValue: archiveUnitEliminationServiceMock },
158163
{ provide: BASE_URL, useValue: '/fake-api' },
159164
{ provide: ComputeInheritedRulesService, useValue: computeInheritedRulesServiceMock },
165+
{ provide: Location, useValue: locationSpy },
160166
{ provide: MatDialog, useValue: matDialogSpy },
161167
{ provide: Router, useValue: routerSpy },
162168
{ provide: SchemaService, useValue: { getDescriptiveSchemaTree: () => of(), getSchema: () => of([]) } },

ui/ui-frontend/projects/archive-search/src/app/archive/archive-search/archive-search.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ export class ArchiveSearchComponent implements OnInit, OnChanges, OnDestroy, Aft
789789
category,
790790
criteria.valueTranslated,
791791
criteria.dataType,
792-
true,
792+
false,
793793
);
794794
});
795795
});

ui/ui-frontend/projects/archive-search/src/app/core/archive-shared-data.service.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
* The fact that you are presently reading this means that you have had
3535
* knowledge of the CeCILL-C license and that you accept its terms.
3636
*/
37+
import { Location } from '@angular/common';
3738
import { Injectable } from '@angular/core';
39+
import { Router } from '@angular/router';
3840
import { BehaviorSubject, Observable } from 'rxjs';
3941
import {
4042
CriteriaSearchCriteria,
@@ -95,7 +97,11 @@ export class ArchiveSharedDataService {
9597

9698
unitUpdatedWithComputedObjectGroup = new BehaviorSubject<Unit>(null);
9799

98-
constructor(private queryParamsService: QueryParamsService) {}
100+
constructor(
101+
private queryParamsService: QueryParamsService,
102+
private router: Router,
103+
private location: Location,
104+
) {}
99105

100106
emitRuleCategory(ruleCategory: string) {
101107
this.ruleCategory.next(ruleCategory);
@@ -237,7 +243,11 @@ export class ArchiveSharedDataService {
237243
}
238244
this.simpleSearchCriteriaAddSubject.next(searchCriteria);
239245
});
240-
builder.navigate();
246+
247+
// Update URL using Location.replaceState to prevent navigation and overwriting searchCriterias
248+
const queryParams = builder.getQueryParams();
249+
const urlTree = this.router.createUrlTree([], { queryParams });
250+
this.location.replaceState(this.router.serializeUrl(urlTree));
241251
}
242252

243253
addSimpleSearchCriteriaSubject(searchCriteria: SearchCriteriaAddAction) {
@@ -304,7 +314,11 @@ export class ArchiveSharedDataService {
304314
: `${searchCriteriaAction.valueElt.value}/${searchCriteriaAction.valueElt.virtualNodeRealParentId}/${searchCriteriaAction.valueElt.virtualNodeRealParentTitle}`;
305315
builder.removeQueryParam(searchCriteriaAction.valueElt.id, valueToRemove);
306316
this.searchCriteriaRemoveFromChildSubject.next(searchCriteriaAction);
307-
builder.navigate();
317+
318+
// Update URL using Location.replaceState
319+
const queryParams = builder.getQueryParams();
320+
const urlTree = this.router.createUrlTree([], { queryParams });
321+
this.location.replaceState(this.router.serializeUrl(urlTree));
308322
}
309323

310324
receiveRemoveFromChildSearchCriteriaSubject(): Observable<SearchCriteriaRemoveAction> {

ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-collect.component.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* The fact that you are presently reading this means that you have had
3535
* knowledge of the CeCILL-C license and that you accept its terms.
3636
*/
37+
import { Location } from '@angular/common';
3738
import { provideHttpClientTesting } from '@angular/common/http/testing';
3839
import { ComponentFixture, TestBed } from '@angular/core/testing';
3940
import { MatDialog } from '@angular/material/dialog';
@@ -134,7 +135,11 @@ describe('ArchiveSearchCollectComponent', () => {
134135
};
135136

136137
const setupTest = async (queryParams: Params, withSimpleCriteria = false) => {
137-
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
138+
const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'createUrlTree', 'serializeUrl']);
139+
routerSpy.createUrlTree.and.returnValue({});
140+
routerSpy.serializeUrl.and.returnValue('/test-url');
141+
142+
const locationSpy = jasmine.createSpyObj('Location', ['replaceState']);
138143

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

@@ -164,6 +169,7 @@ describe('ArchiveSearchCollectComponent', () => {
164169
{ provide: BASE_URL, useValue: '/fake-api' },
165170
{ provide: ConfigService, useValue: { config$: of() } },
166171
{ provide: ExternalParametersService, useValue: externalParametersServiceStub },
172+
{ provide: Location, useValue: locationSpy },
167173
{ provide: MatDialog, useValue: matDialogSpy },
168174
{ provide: Router, useValue: routerSpy },
169175
{ provide: SchemaService, useValue: { getDescriptiveSchemaTree: () => of(), getSchema: () => of([]) } },

ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-collect.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ export class ArchiveSearchCollectComponent extends SidenavPage<any> implements O
11821182
category,
11831183
criteria.valueTranslated,
11841184
criteria.dataType,
1185-
true,
1185+
false,
11861186
);
11871187
});
11881188
});

ui/ui-frontend/projects/collect/src/app/collect/core/archive-shared-data.service.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
* knowledge of the CeCILL-C license and that you accept its terms.
3636
*/
3737

38+
import { Location } from '@angular/common';
3839
import { Injectable } from '@angular/core';
40+
import { Router } from '@angular/router';
3941
import { BehaviorSubject, Observable } from 'rxjs';
4042
import {
4143
CriteriaSearchCriteria,
@@ -94,7 +96,11 @@ export class ArchiveSharedDataService {
9496
reuseFromMainSearchCriteriaObservable = this.searchReuseCriteriaActionFromMainSubject.asObservable();
9597
disseminationFromMainSearchCriteriaObservable = this.searchDisseminationCriteriaActionFromMainSubject.asObservable();
9698

97-
constructor(private queryParamsService: QueryParamsService) {}
99+
constructor(
100+
private queryParamsService: QueryParamsService,
101+
private router: Router,
102+
private location: Location,
103+
) {}
98104

99105
emitNumberOfAUsWithoutAttachment(value: number) {
100106
this.numberOfAUsWithoutAttachment.next(value);
@@ -232,7 +238,11 @@ export class ArchiveSharedDataService {
232238
}
233239
this.simpleSearchCriteriaAddSubject.next(searchCriteria);
234240
});
235-
builder.navigate();
241+
242+
// Update URL using Location.replaceState to prevent navigation and overwriting searchCriterias
243+
const queryParams = builder.getQueryParams();
244+
const urlTree = this.router.createUrlTree([], { queryParams });
245+
this.location.replaceState(this.router.serializeUrl(urlTree));
236246
}
237247

238248
addSimpleSearchCriteriaSubject(searchCriteria: SearchCriteriaAddAction) {
@@ -271,7 +281,11 @@ export class ArchiveSharedDataService {
271281
: `${searchCriteriaAction.valueElt.value}/${searchCriteriaAction.valueElt.virtualNodeRealParentId}/${searchCriteriaAction.valueElt.virtualNodeRealParentTitle}`;
272282
builder.removeQueryParam(searchCriteriaAction.valueElt.id, valueToRemove);
273283
this.searchCriteriaRemoveFromChildSubject.next(searchCriteriaAction);
274-
builder.navigate();
284+
285+
// Update URL using Location.replaceState
286+
const queryParams = builder.getQueryParams();
287+
const urlTree = this.router.createUrlTree([], { queryParams });
288+
this.location.replaceState(this.router.serializeUrl(urlTree));
275289
}
276290

277291
receiveRemoveFromChildSearchCriteriaSubject(): Observable<SearchCriteriaRemoveAction> {

ui/ui-frontend/projects/vitamui-library/src/app/modules/url/query-params.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class QueryParamBuilder {
6262
return this;
6363
}
6464

65+
getQueryParams(): Params {
66+
return { ...this.#queryParams };
67+
}
68+
6569
navigate(extras: NavigationExtras = {}): Observable<boolean> {
6670
return fromPromise(
6771
this.router.navigate([], {

0 commit comments

Comments
 (0)