From 5f884fa33c7600083a5576484c190ffc6e49a6c2 Mon Sep 17 00:00:00 2001 From: KeyboardTsundoku Date: Tue, 1 Nov 2016 11:50:45 +1100 Subject: [PATCH 1/2] COMPASS-142 showing error message on mondal on index drop error --- .../lib/component/create-index-modal.jsx | 3 + .../lib/component/drop-index-modal.jsx | 55 ++++++++++++++++++- .../indexes/lib/store/update-indexes-store.js | 5 ++ 3 files changed, 60 insertions(+), 3 deletions(-) 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..193f9832e6e 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,7 @@ class DropIndexModal extends React.Component { evt.preventDefault(); evt.stopPropagation(); Action.dropIndex(this.props.indexName); - this.props.close(); + // this.props.close(); } /** @@ -58,7 +104,7 @@ class DropIndexModal extends React.Component { backdrop="static" dialogClassName="drop-index-modal" keyboard={false} - onHide={this.props.close} > + onHide={this.handleClose.bind(this)} >
Index Drop @@ -95,6 +141,9 @@ class DropIndexModal extends React.Component { Drop
+ {this.state.error ? + + : null} diff --git a/src/internal-packages/indexes/lib/store/update-indexes-store.js b/src/internal-packages/indexes/lib/store/update-indexes-store.js index f39ce62a8cd..60c0511b332 100644 --- a/src/internal-packages/indexes/lib/store/update-indexes-store.js +++ b/src/internal-packages/indexes/lib/store/update-indexes-store.js @@ -4,6 +4,8 @@ const NamespaceStore = require('hadron-reflux-store').NamespaceStore; const LoadIndexesStore = require('./load-indexes-store'); const Action = require('../action/index-actions'); +// const debug = require('debug')('mongodb-compass:stores:ddl'); + /** * The reflux store for updating indexes. */ @@ -37,6 +39,9 @@ const UpdateIndexesStore = Reflux.createStore({ if (!err) { this.indexes = this.indexes.filter(index => index.name !== indexName); this.trigger(this.indexes); + Action.updateStatus('complete'); + } else { + Action.updateStatus('error', this._parseErrorMsg(err)); } }); }, From a40429eac112c3be97a39a5f6b0349fc016682e2 Mon Sep 17 00:00:00 2001 From: KeyboardTsundoku Date: Tue, 1 Nov 2016 13:32:21 +1100 Subject: [PATCH 2/2] COMPASS-141 added progress to the drop index modal --- .../lib/component/drop-index-modal.jsx | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) 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 193f9832e6e..774fff92efc 100644 --- a/src/internal-packages/indexes/lib/component/drop-index-modal.jsx +++ b/src/internal-packages/indexes/lib/component/drop-index-modal.jsx @@ -93,6 +93,30 @@ class DropIndexModal extends React.Component { // this.props.close(); } + /** + * Render the create and cancel buttons. + * + * @returns {React.Component} The create and cancel buttons. + */ + renderButtons() { + return ( +
+ + +
+ ); + } + /** * Render drop confirmation modal. * @@ -127,23 +151,13 @@ class DropIndexModal extends React.Component { value={this.state.confirmName} onChange={this.handleChange.bind(this)} /> -
- - -
{this.state.error ? : null} + + {this.state.inProgress ? + + : this.renderButtons()}