Skip to content

Commit c1ea8fe

Browse files
Satyarueckstiess
authored andcommitted
COMPASS-291 explain only executes on apply press, otherwise remains z… (#614)
* COMPASS-291 explain only executes on apply press, otherwise remains zero state * defined debug * COMPASS-291 added a status to query store, apply and reset
1 parent 32608fb commit c1ea8fe

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/internal-packages/explain/lib/components/compass-explain.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const app = require('ampersand-app');
33
const ExplainBody = require('./explain-body');
44
const ExplainHeader = require('./explain-header');
55

6-
const ExplainActions = require('../actions');
7-
86
// const debug = require('debug')('mongodb-compass:explain');
97

108
/**
@@ -30,7 +28,6 @@ class CompassExplain extends React.Component {
3028
}
3129

3230
componentWillMount() {
33-
ExplainActions.fetchExplainPlan();
3431
this.queryBar = app.appRegistry.getComponent('Query.QueryBar');
3532
}
3633

src/internal-packages/explain/lib/stores/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const CompassExplainStore = Reflux.createStore({
3636
if (ns && toNS(ns).collection) {
3737
this.query = {};
3838
this._reset();
39-
this.fetchExplainPlan();
4039
}
4140
});
4241

@@ -54,9 +53,14 @@ const CompassExplainStore = Reflux.createStore({
5453
},
5554

5655
onQueryChanged(state) {
57-
this.query = state.query;
58-
this._reset();
59-
this.fetchExplainPlan();
56+
if (state.query) {
57+
this.query = state.query;
58+
if (state.queryState === 'reset') {
59+
this._reset();
60+
} else {
61+
this.fetchExplainPlan();
62+
}
63+
}
6064
},
6165

6266
/**

src/internal-packages/query/lib/store/query-changed-store.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const QueryChangedStore = Reflux.createStore({
3030
getInitialState() {
3131
return {
3232
query: null,
33+
queryState: 'reset',
3334
sort: {},
3435
limit: 0,
3536
skip: 0,
@@ -47,6 +48,7 @@ const QueryChangedStore = Reflux.createStore({
4748
if (!_.isEqual(this.state.query, state.lastExecutedQuery)) {
4849
this.setState({
4950
query: state.lastExecutedQuery,
51+
queryState: state.queryState,
5052
sort: state.sort,
5153
limit: state.limit,
5254
skip: state.skip,

src/internal-packages/query/lib/store/query-store.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ const debug = require('debug')('mongodb-compass:stores:query');
1515

1616
const USER_TYPING_DEBOUNCE_MS = 100;
1717
const FEATURE_FLAG_REGEX = /^(enable|disable) (\w+)\s*$/;
18+
const RESET_STATE = 'reset';
19+
const APPLY_STATE = 'apply';
1820

1921
const DEFAULT_QUERY = {};
2022
const DEFAULT_SORT = { _id: -1 };
2123
const DEFAULT_LIMIT = 1000;
2224
const DEFAULT_SKIP = 0;
2325
const DEFAULT_PROJECT = {};
2426
const DEFAULT_MAX_TIME_MS = ms('10 seconds');
27+
const DEFAULT_STATE = RESET_STATE;
28+
// const DEFAULT_QUERY_STRING = '{}';
2529

2630
/**
2731
* The reflux store for the schema.
@@ -59,6 +63,7 @@ const QueryStore = Reflux.createStore({
5963
project: DEFAULT_PROJECT,
6064
maxTimeMS: DEFAULT_MAX_TIME_MS,
6165
queryString: '',
66+
queryState: DEFAULT_STATE, // either apply or reset
6267
valid: true,
6368
featureFlag: false,
6469
lastExecutedQuery: null,
@@ -404,6 +409,8 @@ const QueryStore = Reflux.createStore({
404409
return;
405410
}
406411

412+
this.setState({queryState: APPLY_STATE});
413+
407414
// empty string is interpreted as {}
408415
if (this.state.queryString === '') {
409416
this.setQuery({});
@@ -419,10 +426,15 @@ const QueryStore = Reflux.createStore({
419426
* dismiss current changes to the query and restore `{}` as the query.
420427
*/
421428
reset() {
429+
this.setState({queryState: RESET_STATE});
422430
if (!_.isEqual(this.state.query, {})) {
423431
this.setQuery({});
424432
if (!_.isEqual(this.state.lastExecutedQuery, {})) {
425-
this.apply();
433+
if (this.state.valid) {
434+
this.setState({
435+
lastExecutedQuery: _.clone(this.state.query)
436+
});
437+
}
426438
}
427439
}
428440
},

0 commit comments

Comments
 (0)