1
+ const app = require ( 'ampersand-app' ) ;
1
2
const React = require ( 'react' ) ;
2
3
const Modal = require ( 'react-bootstrap' ) . Modal ;
3
4
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');
4
9
5
10
/**
6
11
* Component for the drop confirmation modal.
@@ -17,13 +22,54 @@ class DropIndexModal extends React.Component {
17
22
this . state = {
18
23
confirmName : ''
19
24
} ;
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 ( ) ;
20
65
}
21
66
22
67
/**
23
68
* Close drop index modal when cancel is clicked.
24
69
*/
25
70
handleCancel ( ) {
26
- this . props . close ( ) ;
71
+ Action . updateStatus ( 'cancel' ) ;
72
+ this . handleClose ( ) ;
27
73
}
28
74
29
75
/**
@@ -44,7 +90,31 @@ class DropIndexModal extends React.Component {
44
90
evt . preventDefault ( ) ;
45
91
evt . stopPropagation ( ) ;
46
92
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
+ ) ;
48
118
}
49
119
50
120
/**
@@ -58,7 +128,7 @@ class DropIndexModal extends React.Component {
58
128
backdrop = "static"
59
129
dialogClassName = "drop-index-modal"
60
130
keyboard = { false }
61
- onHide = { this . props . close } >
131
+ onHide = { this . handleClose . bind ( this ) } >
62
132
< div className = "drop-index-modal-content" >
63
133
< Modal . Header >
64
134
< Modal . Title > Index Drop</ Modal . Title >
@@ -81,20 +151,13 @@ class DropIndexModal extends React.Component {
81
151
value = { this . state . confirmName }
82
152
onChange = { this . handleChange . bind ( this ) } />
83
153
</ 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 ( ) }
98
161
</ form >
99
162
</ Modal . Body >
100
163
</ div >
0 commit comments