From 17ab893494ab5d80bf141fbb067df668151187da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= <francois.agneray@lam.fr>
Date: Fri, 30 Jul 2021 16:48:11 +0200
Subject: [PATCH] Keep search query params for detail page

---
 .../search/components/result/datatable-tab.component.html     | 1 +
 .../search/components/result/datatable-tab.component.ts       | 3 ++-
 .../src/app/instance/search/containers/result.component.html  | 1 +
 .../components/datatable/datatable.component.html             | 1 +
 .../shared-search/components/datatable/datatable.component.ts | 3 ++-
 .../datatable/renderer/detail-renderer.component.html         | 4 +++-
 .../datatable/renderer/detail-renderer.component.ts           | 2 ++
 .../shared-search/detail/containers/detail.component.ts       | 3 +++
 8 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/client/src/app/instance/search/components/result/datatable-tab.component.html b/client/src/app/instance/search/components/result/datatable-tab.component.html
index 335af332..f9f6b3aa 100644
--- a/client/src/app/instance/search/components/result/datatable-tab.component.html
+++ b/client/src/app/instance/search/components/result/datatable-tab.component.html
@@ -13,6 +13,7 @@
                 [instance]="instance"
                 [attributeList]="attributeList"
                 [outputList]="outputList"
+                [queryParams]="queryParams"
                 [dataLength]="dataLength"
                 [data]="data"
                 [dataIsLoading]="dataIsLoading"
diff --git a/client/src/app/instance/search/components/result/datatable-tab.component.ts b/client/src/app/instance/search/components/result/datatable-tab.component.ts
index 57333dc2..a276dec4 100644
--- a/client/src/app/instance/search/components/result/datatable-tab.component.ts
+++ b/client/src/app/instance/search/components/result/datatable-tab.component.ts
@@ -10,7 +10,7 @@
 import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
 
 import { Instance, Attribute, Dataset } from 'src/app/metamodel/models';
-import { Pagination } from 'src/app/instance/store/models';
+import { Pagination, SearchQueryParams } from 'src/app/instance/store/models';
 
 @Component({
     selector: 'app-datatable-tab',
@@ -27,6 +27,7 @@ export class DatatableTabComponent {
     @Input() datasetList: Dataset[];
     @Input() attributeList: Attribute[];
     @Input() outputList: number[];
+    @Input() queryParams: SearchQueryParams;
     @Input() dataLength: number;
     @Input() data: any[];
     @Input() dataIsLoading: boolean;
diff --git a/client/src/app/instance/search/containers/result.component.html b/client/src/app/instance/search/containers/result.component.html
index f5ede714..d9b4fdbf 100644
--- a/client/src/app/instance/search/containers/result.component.html
+++ b/client/src/app/instance/search/containers/result.component.html
@@ -76,6 +76,7 @@
                 [datasetList]="datasetList | async"
                 [attributeList]="attributeList | async"
                 [outputList]="outputList | async"
+                [queryParams]="queryParams | async"
                 [dataLength]="dataLength | async"
                 [data]="data | async"
                 [dataIsLoading]="dataIsLoading | async"
diff --git a/client/src/app/instance/shared-search/components/datatable/datatable.component.html b/client/src/app/instance/shared-search/components/datatable/datatable.component.html
index cd7506a1..7b7ee23a 100644
--- a/client/src/app/instance/shared-search/components/datatable/datatable.component.html
+++ b/client/src/app/instance/shared-search/components/datatable/datatable.component.html
@@ -46,6 +46,7 @@
                                 [value]="datum[attribute.label]"
                                 [datasetName]="dataset.name"
                                 [instanceSelected]="instance.name"
+                                [queryParams]="queryParams"
                                 [config]="getRendererConfig(attribute)">
                             </app-detail-renderer>
                         </div>
diff --git a/client/src/app/instance/shared-search/components/datatable/datatable.component.ts b/client/src/app/instance/shared-search/components/datatable/datatable.component.ts
index 9df8e30a..1e90851c 100644
--- a/client/src/app/instance/shared-search/components/datatable/datatable.component.ts
+++ b/client/src/app/instance/shared-search/components/datatable/datatable.component.ts
@@ -10,7 +10,7 @@
 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
 
 import { Instance, Attribute, Dataset, DetailRendererConfig, DownloadRendererConfig, ImageRendererConfig, LinkRendererConfig, RendererConfig } from 'src/app/metamodel/models';
-import { Pagination, PaginationOrder } from 'src/app/instance/store/models';
+import { Pagination, PaginationOrder, SearchQueryParams } from 'src/app/instance/store/models';
 
 @Component({
     selector: 'app-datatable',
@@ -28,6 +28,7 @@ export class DatatableComponent implements OnInit {
     @Input() instance: Instance;
     @Input() attributeList: Attribute[];
     @Input() outputList: number[];
+    @Input() queryParams: SearchQueryParams;
     @Input() dataLength: number;
     @Input() data: any[];
     @Input() dataIsLoading: boolean;
diff --git a/client/src/app/instance/shared-search/components/datatable/renderer/detail-renderer.component.html b/client/src/app/instance/shared-search/components/datatable/renderer/detail-renderer.component.html
index e597c8db..bb61c20c 100644
--- a/client/src/app/instance/shared-search/components/datatable/renderer/detail-renderer.component.html
+++ b/client/src/app/instance/shared-search/components/datatable/renderer/detail-renderer.component.html
@@ -1,4 +1,6 @@
-<a routerLink="/instance/{{ instanceSelected }}/search/detail/{{ datasetName }}/{{ value }}" [target]="config.blank == true ? '_blank' : '_self'"
+<a routerLink="/instance/{{ instanceSelected }}/search/detail/{{ datasetName }}/{{ value }}" 
+    [target]="config.blank == true ? '_blank' : '_self'"
+    [queryParams]="queryParams"
     [ngClass]="{'btn btn-outline-primary btn-sm' : config.display == 'text-button'}">
     {{ value }}
 </a>
diff --git a/client/src/app/instance/shared-search/components/datatable/renderer/detail-renderer.component.ts b/client/src/app/instance/shared-search/components/datatable/renderer/detail-renderer.component.ts
index d6df4dfd..8d148a3f 100644
--- a/client/src/app/instance/shared-search/components/datatable/renderer/detail-renderer.component.ts
+++ b/client/src/app/instance/shared-search/components/datatable/renderer/detail-renderer.component.ts
@@ -9,6 +9,7 @@
 
 import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
 
+import { SearchQueryParams } from 'src/app/instance/store/models';
 import { DetailRendererConfig } from 'src/app/metamodel/models/renderers/detail-renderer-config.model';
 
 @Component({
@@ -24,5 +25,6 @@ export class DetailRendererComponent {
     @Input() value: string | number;
     @Input() datasetName: string;
     @Input() instanceSelected: string;
+    @Input() queryParams: SearchQueryParams;
     @Input() config: DetailRendererConfig;
 }
diff --git a/client/src/app/instance/shared-search/detail/containers/detail.component.ts b/client/src/app/instance/shared-search/detail/containers/detail.component.ts
index 7e82b70d..8fd9b25b 100644
--- a/client/src/app/instance/shared-search/detail/containers/detail.component.ts
+++ b/client/src/app/instance/shared-search/detail/containers/detail.component.ts
@@ -22,6 +22,7 @@ import * as searchSelector from 'src/app/instance/store/selectors/search.selecto
 import * as outputFamilySelector from 'src/app/metamodel/selectors/output-family.selector';
 import * as outputCategorySelector from 'src/app/metamodel/selectors/output-category.selector';
 import * as attributeSelector from 'src/app/metamodel/selectors/attribute.selector';
+import * as searchActions from 'src/app/instance/store/actions/search.actions';
 
 /**
  * Interface for store state.
@@ -87,8 +88,10 @@ export class DetailComponent implements OnInit, OnDestroy {
     ngOnInit() {
         // Create a micro task that is processed after the current synchronous code
         // This micro task prevent the expression has changed after view init error
+        Promise.resolve(null).then(() => this.store.dispatch(searchActions.initSearch()));
         this.attributeListIsLoadedSubscription = this.attributeListIsLoaded.subscribe(attributeListIsLoaded => {
             if (attributeListIsLoaded) {
+                Promise.resolve(null).then(() => this.store.dispatch(searchActions.loadDefaultFormParameters()));
                 Promise.resolve(null).then(() => this.store.dispatch(detailActions.retrieveObject()));
             }
         });
-- 
GitLab