Fix clear history.
parent
fae185ff66
commit
fc78202600
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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([]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue