Skip to content

Commit 2b5ee5f

Browse files
Satyadurran
authored andcommitted
COMPASS-142 showing error message on mondal on index drop error (#556)
* COMPASS-142 showing error message on mondal on index drop error * COMPASS-141 added progress to the drop index modal
1 parent 1d52a0a commit 2b5ee5f

File tree

3 files changed

+88
-17
lines changed

3 files changed

+88
-17
lines changed

src/internal-packages/indexes/lib/component/create-index-modal.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const CreateIndexTextField = require('./create-index-text-field');
1010
const OptionsToggleBar = require('./options-toggle-bar');
1111
const Action = require('../action/index-actions');
1212

13+
// const debug = require('debug')('mongodb-compass:ddl:index');
14+
1315
/**
1416
* The index options and parameters to display.
1517
*/
@@ -116,6 +118,7 @@ class CreateIndexModal extends React.Component {
116118
* Close modal when cancel is clicked.
117119
*/
118120
handleCancel() {
121+
Action.updateStatus('cancel');
119122
this.close();
120123
}
121124

src/internal-packages/indexes/lib/component/drop-index-modal.jsx

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
const app = require('ampersand-app');
12
const React = require('react');
23
const Modal = require('react-bootstrap').Modal;
34
const Action = require('../action/index-actions');
5+
const DDLStatusStore = require('../store/ddl-status-store');
6+
7+
8+
// const debug = require('debug')('mongodb-compass:ddl:index');
49

510
/**
611
* Component for the drop confirmation modal.
@@ -17,13 +22,54 @@ class DropIndexModal extends React.Component {
1722
this.state = {
1823
confirmName: ''
1924
};
25+
this.ModalStatusMessage = app.appRegistry.getComponent('App.ModalStatusMessage');
26+
}
27+
28+
/**
29+
* Subscribe on mount.
30+
*/
31+
componentWillMount() {
32+
this.unsubscribeDDLStatus = DDLStatusStore.listen(this.handleStatusChange.bind(this));
33+
}
34+
35+
/**
36+
* Unsubscribe on unmount.
37+
*/
38+
componentWillUnmount() {
39+
this.unsubscribeDDLStatus();
40+
}
41+
42+
/**
43+
* Handle changes in creation state (success, error, or complete).
44+
*
45+
* @param {string} status - The status.
46+
* @param {string} message - The error message.
47+
*/
48+
handleStatusChange(status, message) {
49+
if (status === 'inProgress') {
50+
this.setState({inProgress: true, error: false, errorMessage: message});
51+
} else if (status === 'error') {
52+
this.setState({inProgress: false, error: true, errorMessage: message});
53+
} else {
54+
this.handleClose();
55+
}
56+
}
57+
58+
/**
59+
* Clean up after a close events
60+
*/
61+
handleClose() {
62+
// this.props.indexName = '';
63+
this.setState({inProgress: false, error: false, errorMessage: ''});
64+
this.props.close();
2065
}
2166

2267
/**
2368
* Close drop index modal when cancel is clicked.
2469
*/
2570
handleCancel() {
26-
this.props.close();
71+
Action.updateStatus('cancel');
72+
this.handleClose();
2773
}
2874

2975
/**
@@ -44,7 +90,31 @@ class DropIndexModal extends React.Component {
4490
evt.preventDefault();
4591
evt.stopPropagation();
4692
Action.dropIndex(this.props.indexName);
47-
this.props.close();
93+
// this.props.close();
94+
}
95+
96+
/**
97+
* Render the create and cancel buttons.
98+
*
99+
* @returns {React.Component} The create and cancel buttons.
100+
*/
101+
renderButtons() {
102+
return (
103+
<div className="drop-btn-container">
104+
<button
105+
className="drop-btn btn btn-default btn-sm"
106+
type="button"
107+
onClick={this.handleCancel.bind(this)}>
108+
Cancel
109+
</button>
110+
<button
111+
className="drop-btn btn btn-primary btn-sm"
112+
disabled={this.state.confirmName !== this.props.indexName}
113+
type="submit">
114+
Drop
115+
</button>
116+
</div>
117+
);
48118
}
49119

50120
/**
@@ -58,7 +128,7 @@ class DropIndexModal extends React.Component {
58128
backdrop="static"
59129
dialogClassName="drop-index-modal"
60130
keyboard={false}
61-
onHide={this.props.close} >
131+
onHide={this.handleClose.bind(this)} >
62132
<div className="drop-index-modal-content">
63133
<Modal.Header>
64134
<Modal.Title>Index Drop</Modal.Title>
@@ -81,20 +151,13 @@ class DropIndexModal extends React.Component {
81151
value={this.state.confirmName}
82152
onChange={this.handleChange.bind(this)} />
83153
</div>
84-
<div className="drop-btn-container">
85-
<button
86-
className="drop-btn btn btn-default btn-sm"
87-
type="button"
88-
onClick={this.handleCancel.bind(this)}>
89-
Cancel
90-
</button>
91-
<button
92-
className="drop-btn btn btn-primary btn-sm"
93-
disabled={this.state.confirmName !== this.props.indexName}
94-
type="submit">
95-
Drop
96-
</button>
97-
</div>
154+
{this.state.error ?
155+
<this.ModalStatusMessage icon="times" message={this.state.errorMessage} type="error" />
156+
: null}
157+
158+
{this.state.inProgress ?
159+
<this.ModalStatusMessage icon="align-center" message={'Drop in Progress'} type="in-progress" />
160+
: this.renderButtons()}
98161
</form>
99162
</Modal.Body>
100163
</div>

src/internal-packages/indexes/lib/store/update-indexes-store.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const NamespaceStore = require('hadron-reflux-store').NamespaceStore;
44
const LoadIndexesStore = require('./load-indexes-store');
55
const Action = require('../action/index-actions');
66

7+
// const debug = require('debug')('mongodb-compass:stores:ddl');
8+
79
/**
810
* The reflux store for updating indexes.
911
*/
@@ -37,6 +39,9 @@ const UpdateIndexesStore = Reflux.createStore({
3739
if (!err) {
3840
this.indexes = this.indexes.filter(index => index.name !== indexName);
3941
this.trigger(this.indexes);
42+
Action.updateStatus('complete');
43+
} else {
44+
Action.updateStatus('error', this._parseErrorMsg(err));
4045
}
4146
});
4247
},

0 commit comments

Comments
 (0)