From 4cafe7d707f9c90f7c6822520837248be9c568ec Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Wed, 14 Apr 2021 11:46:51 +0200
Subject: [PATCH] fix: search query param

---
 .../admin/components/panel/panel.component.ts    |  3 +--
 .../components/search/search.component.ts        | 16 +++++++++++-----
 .../structure-details.component.ts               |  6 +++++-
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/app/admin/components/panel/panel.component.ts b/src/app/admin/components/panel/panel.component.ts
index 15052b621..47b402519 100644
--- a/src/app/admin/components/panel/panel.component.ts
+++ b/src/app/admin/components/panel/panel.component.ts
@@ -15,10 +15,9 @@ export class PanelComponent implements OnInit {
 
   ngOnInit(): void {
     this.selectedFeature = this.features.pendingStructures;
-    console.log(this.ghostLink);
   }
 
-  public changeActiveFeature(newFeature: AdminPannelEnum) {
+  public changeActiveFeature(newFeature: AdminPannelEnum): void {
     this.selectedFeature = newFeature;
   }
 }
diff --git a/src/app/structure-list/components/search/search.component.ts b/src/app/structure-list/components/search/search.component.ts
index e6011a8fe..a95eacead 100644
--- a/src/app/structure-list/components/search/search.component.ts
+++ b/src/app/structure-list/components/search/search.component.ts
@@ -10,7 +10,7 @@ import { Module } from '../../models/module.model';
 import { StructureCounter } from '../../models/structureCounter.model';
 import { SearchService } from '../../services/search.service';
 import { Location } from '@angular/common';
-import { ActivatedRoute } from '@angular/router';
+import { ActivatedRoute, Router } from '@angular/router';
 
 @Component({
   selector: 'app-structure-list-search',
@@ -49,7 +49,9 @@ export class SearchComponent implements OnInit, OnChanges {
     private fb: FormBuilder,
     private geoJsonService: GeojsonService,
     private activatedRoute: ActivatedRoute,
-    private location: Location
+    private location: Location,
+    private route: ActivatedRoute,
+    private router: Router
   ) {
     this.searchForm = this.fb.group({
       searchTerm: '',
@@ -91,9 +93,13 @@ export class SearchComponent implements OnInit, OnChanges {
   public applyFilter(term: string): void {
     // Add search input filter
     if (term) {
-      this.location.go('/acteurs?search=' + term);
-    } else {
-      this.location.go('/acteurs');
+      this.router.navigate(['/acteurs'], {
+        relativeTo: this.route,
+        queryParams: {
+          search: term,
+        },
+        queryParamsHandling: 'merge',
+      });
     }
     const filters: Filter[] = [];
     if (term) {
diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts
index 79042b400..ae688aeaa 100644
--- a/src/app/structure-list/components/structure-details/structure-details.component.ts
+++ b/src/app/structure-list/components/structure-details/structure-details.component.ts
@@ -121,8 +121,12 @@ export class StructureDetailsComponent implements OnInit {
   }
 
   public close(): void {
-    this.router.navigate([], {
+    this.router.navigate(['/acteurs'], {
       relativeTo: this.route,
+      queryParams: {
+        id: null,
+      },
+      queryParamsHandling: 'merge',
     });
   }
 
-- 
GitLab