From 32cf3e784680a82068a63ad687da501da9e08f95 Mon Sep 17 00:00:00 2001
From: esikkala <esko.ikkala@aalto.fi>
Date: Mon, 26 Nov 2018 14:37:48 +0200
Subject: [PATCH] Results table: re-render when filters have changed

---
 src/client/components/Manuscripts.js | 2 ++
 src/client/components/ResultTable.js | 7 +++++++
 src/client/containers/MapApp.js      | 1 +
 3 files changed, 10 insertions(+)

diff --git a/src/client/components/Manuscripts.js b/src/client/components/Manuscripts.js
index 18076b0a..f8ba7ebd 100644
--- a/src/client/components/Manuscripts.js
+++ b/src/client/components/Manuscripts.js
@@ -21,6 +21,7 @@ let Manuscripts = props => {
         render={routeProps =>
           <ResultTable
             rows={props.search.manuscripts}
+            facetFilters={props.facetFilters}
             fetchManuscripts={props.fetchManuscripts}
             fetchingManuscripts={props.search.fetchingManuscripts}
             resultCount={props.search.manuscriptCount}
@@ -67,6 +68,7 @@ let Manuscripts = props => {
 Manuscripts.propTypes = {
   map: PropTypes.object.isRequired,
   search: PropTypes.object.isRequired,
+  facetFilters: PropTypes.object.isRequired,
   fetchManuscripts: PropTypes.func.isRequired,
   fetchPlaces: PropTypes.func.isRequired,
   fetchPlace:  PropTypes.func.isRequired,
diff --git a/src/client/components/ResultTable.js b/src/client/components/ResultTable.js
index 98fca3e4..a692bb78 100644
--- a/src/client/components/ResultTable.js
+++ b/src/client/components/ResultTable.js
@@ -81,6 +81,12 @@ class ResultTable extends React.Component {
         search: `?page=${this.props.page}`,
       });
     }
+    if (prevProps.facetFilters != this.props.facetFilters) {
+      // console.log('filters updated')
+      this.props.updatePage(0);
+      this.props.fetchManuscripts();
+    }
+
   }
 
   idRenderer = id => {
@@ -298,6 +304,7 @@ class ResultTable extends React.Component {
 ResultTable.propTypes = {
   classes: PropTypes.object.isRequired,
   rows: PropTypes.array.isRequired,
+  facetFilters: PropTypes.object.isRequired,
   fetchManuscripts: PropTypes.func.isRequired,
   fetchingManuscripts: PropTypes.bool.isRequired,
   resultCount: PropTypes.number.isRequired,
diff --git a/src/client/containers/MapApp.js b/src/client/containers/MapApp.js
index fc110cae..2715d4a6 100644
--- a/src/client/containers/MapApp.js
+++ b/src/client/containers/MapApp.js
@@ -107,6 +107,7 @@ let MapApp = (props) => {
                   <Manuscripts
                     map={props.map}
                     search={props.search}
+                    facetFilters={props.facet.facetFilters}
                     fetchManuscripts={props.fetchManuscripts}
                     fetchPlaces={props.fetchPlaces}
                     fetchPlace={props.fetchPlace}
-- 
GitLab