Fix clear history.

REL-1_X
Harshal Dhumal 2017-07-07 15:50:56 +01:00 committed by Dave Page
parent fae185ff66
commit fc78202600
4 changed files with 23 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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();
}
},

View File

@ -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([]);
});
});