diff --git a/src/internal-packages/indexes/lib/component/create-index-modal.jsx b/src/internal-packages/indexes/lib/component/create-index-modal.jsx index 50a18bb69ee..6504705f89d 100644 --- a/src/internal-packages/indexes/lib/component/create-index-modal.jsx +++ b/src/internal-packages/indexes/lib/component/create-index-modal.jsx @@ -10,6 +10,8 @@ const CreateIndexTextField = require('./create-index-text-field'); const OptionsToggleBar = require('./options-toggle-bar'); const Action = require('../action/index-actions'); +// const debug = require('debug')('mongodb-compass:ddl:index'); + /** * The index options and parameters to display. */ @@ -116,6 +118,7 @@ class CreateIndexModal extends React.Component { * Close modal when cancel is clicked. */ handleCancel() { + Action.updateStatus('cancel'); this.close(); } diff --git a/src/internal-packages/indexes/lib/component/drop-index-modal.jsx b/src/internal-packages/indexes/lib/component/drop-index-modal.jsx index 893c053b375..774fff92efc 100644 --- a/src/internal-packages/indexes/lib/component/drop-index-modal.jsx +++ b/src/internal-packages/indexes/lib/component/drop-index-modal.jsx @@ -1,6 +1,11 @@ +const app = require('ampersand-app'); const React = require('react'); const Modal = require('react-bootstrap').Modal; const Action = require('../action/index-actions'); +const DDLStatusStore = require('../store/ddl-status-store'); + + +// const debug = require('debug')('mongodb-compass:ddl:index'); /** * Component for the drop confirmation modal. @@ -17,13 +22,54 @@ class DropIndexModal extends React.Component { this.state = { confirmName: '' }; + this.ModalStatusMessage = app.appRegistry.getComponent('App.ModalStatusMessage'); + } + + /** + * Subscribe on mount. + */ + componentWillMount() { + this.unsubscribeDDLStatus = DDLStatusStore.listen(this.handleStatusChange.bind(this)); + } + + /** + * Unsubscribe on unmount. + */ + componentWillUnmount() { + this.unsubscribeDDLStatus(); + } + + /** + * Handle changes in creation state (success, error, or complete). + * + * @param {string} status - The status. + * @param {string} message - The error message. + */ + handleStatusChange(status, message) { + if (status === 'inProgress') { + this.setState({inProgress: true, error: false, errorMessage: message}); + } else if (status === 'error') { + this.setState({inProgress: false, error: true, errorMessage: message}); + } else { + this.handleClose(); + } + } + + /** + * Clean up after a close events + */ + handleClose() { + // this.props.indexName = ''; + this.setState({inProgress: false, error: false, errorMessage: ''}); + this.props.close(); } /** * Close drop index modal when cancel is clicked. */ handleCancel() { - this.props.close(); + Action.updateStatus('cancel'); + this.handleClose(); } /** @@ -44,7 +90,31 @@ class DropIndexModal extends React.Component { evt.preventDefault(); evt.stopPropagation(); Action.dropIndex(this.props.indexName); - this.props.close(); + // this.props.close(); + } + + /** + * Render the create and cancel buttons. + * + * @returns {React.Component} The create and cancel buttons. + */ + renderButtons() { + return ( +