Hi,

Please find attached patch to fix clear history functionality in query tool.

-- 
*Harshal Dhumal*
*Sr. Software Engineer*

EnterpriseDB India: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/static/js/history/history_collection.js b/web/pgadmin/static/js/history/history_collection.js
index f7b6acd..22a86f7 100644
--- a/web/pgadmin/static/js/history/history_collection.js
+++ b/web/pgadmin/static/js/history/history_collection.js
@@ -25,10 +25,14 @@ export default class HistoryCollection {
 
   reset() {
     this.historyList = [];
-    this.onChangeHandler(this.historyList);
+    this.onResetHandler(this.historyList);
   }
 
   onChange(onChangeHandler) {
     this.onChangeHandler = onChangeHandler;
   }
+
+  onReset(onResetHandler) {
+    this.onResetHandler = onResetHandler;
+  }
 }
\ No newline at end of file
diff --git a/web/pgadmin/static/jsx/history/query_history.jsx b/web/pgadmin/static/jsx/history/query_history.jsx
index 0d9222d..270dbf1 100644
--- a/web/pgadmin/static/jsx/history/query_history.jsx
+++ b/web/pgadmin/static/jsx/history/query_history.jsx
@@ -36,6 +36,10 @@ export default class QueryHistory extends React.Component {
     this.props.historyCollection.onChange((historyList) => {
       this.resetCurrentHistoryDetail(historyList);
     });
+
+    this.props.historyCollection.onReset((historyList) => {
+      this.clearCurrentHistoryDetail(historyList);
+    });
   }
 
   componentDidMount() {
@@ -58,6 +62,14 @@ export default class QueryHistory extends React.Component {
     this.setCurrentHistoryDetail(0, historyList);
   }
 
+  clearCurrentHistoryDetail(historyList) {
+    this.setState({
+      history: historyList,
+      currentHistoryDetail: undefined,
+      selectedEntry: 0,
+    });
+  }
+
   retrieveOrderedHistory() {
     return _.chain(this.state.history)
       .sortBy(historyEntry => historyEntry.start_time)
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
index 0584df5..8a797ab 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
@@ -1325,8 +1325,7 @@ define([
         alertify.confirm(gettext("Clear history"),
           gettext("Are you sure you wish to clear the history?"),
           function() {
-            // Remove any existing grid first
-            if (self.history_grid) {
+            if (self.history_collection) {
               self.history_collection.reset();
             }
           },
diff --git a/web/regression/javascript/history/history_collection_spec.js b/web/regression/javascript/history/history_collection_spec.js
index 9c10b90..b952c92 100644
--- a/web/regression/javascript/history/history_collection_spec.js
+++ b/web/regression/javascript/history/history_collection_spec.js
@@ -10,13 +10,15 @@
 import HistoryCollection from '../../../pgadmin/static/js/history/history_collection';
 
 describe('historyCollection', function () {
-  let historyCollection, historyModel, onChangeSpy;
+  let historyCollection, historyModel, onChangeSpy, onResetSpy;
   beforeEach(() => {
     historyModel = [{some: 'thing', someOther: ['array element']}];
     historyCollection = new HistoryCollection(historyModel);
     onChangeSpy = jasmine.createSpy('onChangeHandler');
+    onResetSpy = jasmine.createSpy('onResetHandler');
 
     historyCollection.onChange(onChangeSpy);
+    historyCollection.onReset(onResetSpy);
   });
 
   describe('length', function () {
@@ -61,8 +63,8 @@ describe('historyCollection', function () {
       expect(historyCollection.length()).toBe(0);
     });
 
-    it('calls the onChange function', function () {
-      expect(onChangeSpy).toHaveBeenCalledWith([]);
+    it('calls the onReset function', function () {
+      expect(onResetSpy).toHaveBeenCalledWith([]);
     });
   });
 

Reply via email to