Skip to content

Commit e6eca04

Browse files
durrankangas
authored andcommitted
INT-1783: Add error messages to insert dialog (#474)
(cherry picked from commit 178ae70)
1 parent 968a4c5 commit e6eca04

File tree

3 files changed

+138
-3
lines changed

3 files changed

+138
-3
lines changed

src/internal-packages/crud/lib/component/insert-document-dialog.jsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
const React = require('react');
44
const Modal = require('react-bootstrap').Modal;
55
const OpenInsertDocumentDialogStore = require('../store/open-insert-document-dialog-store');
6+
const InsertDocumentStore = require('../store/insert-document-store');
67
const InsertDocument = require('./insert-document');
8+
const InsertDocumentFooter = require('./insert-document-footer');
79
const TextButton = require('hadron-app-registry').TextButton;
810
const Actions = require('../actions');
911

@@ -22,27 +24,62 @@ class InsertDocumentDialog extends React.Component {
2224
this.state = { open: false };
2325
}
2426

27+
/**
28+
* Subscribe to the open dialog store.
29+
*/
2530
componentWillMount() {
2631
this.unsubscribeOpen = OpenInsertDocumentDialogStore.listen(this.handleStoreOpen.bind(this));
32+
this.unsubscribeInsert = InsertDocumentStore.listen(this.handleDocumentInsert.bind(this));
2733
}
2834

35+
/**
36+
* Unsubscribe from the store.
37+
*/
2938
componentWillUnmount() {
3039
this.unsubscribeOpen();
40+
this.unsubscribeInsert();
3141
}
3242

43+
/**
44+
* Handle opening the dialog with the new document.
45+
*
46+
* @param {Object} doc - The document.
47+
*/
3348
handleStoreOpen(doc) {
3449
this.setState({ doc: doc, open: true });
3550
}
3651

52+
/**
53+
* Handle canceling the insert.
54+
*/
3755
handleCancel() {
3856
this.setState({ open: false });
3957
}
4058

59+
/**
60+
* Handles completion of the document insert.
61+
*
62+
* @param {Boolean} success - If the operation succeeded.
63+
* @param {Object} doc - The document or error.
64+
*/
65+
handleDocumentInsert(success, doc) {
66+
if (success) {
67+
this.setState({ open: false });
68+
}
69+
}
70+
71+
/**
72+
* Handle the insert.
73+
*/
4174
handleInsert() {
42-
this.setState({ open: false });
4375
Actions.insertDocument(this.state.doc.generateObject());
4476
}
4577

78+
/**
79+
* Render the modal dialog.
80+
*
81+
* @returns {React.Component} The react component.
82+
*/
4683
render() {
4784
return (
4885
<Modal show={this.state.open} backdrop='static' keyboard={false}>
@@ -52,6 +89,7 @@ class InsertDocumentDialog extends React.Component {
5289

5390
<Modal.Body>
5491
<InsertDocument doc={this.state.doc} />
92+
<InsertDocumentFooter />
5593
</Modal.Body>
5694

5795
<Modal.Footer>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
const InsertDocumentStore = require('../store/insert-document-store');
5+
const Actions = require('../actions');
6+
7+
const INSERTING = 'Inserting Document';
8+
9+
/**
10+
* Map of modes to styles.
11+
*/
12+
const MODES = {
13+
'Progress': 'in-progress',
14+
'Error': 'error',
15+
'Modifying': 'modifying'
16+
}
17+
18+
/**
19+
* Component for the insert document footer.
20+
*/
21+
class InsertDocumentFooter extends React.Component {
22+
23+
/**
24+
* The component constructor.
25+
*
26+
* @param {Object} props - The properties.
27+
*/
28+
constructor(props) {
29+
super(props);
30+
this.state = { message: '', mode: 'Modifying' };
31+
}
32+
33+
/**
34+
* Subscribe to the insert document store.
35+
*/
36+
componentWillMount() {
37+
this.unsubscribeInsert = InsertDocumentStore.listen(this.handleDocumentInsert.bind(this));
38+
this.unsubscribeStart = Actions.insertDocument.listen(this.handleInsertStart.bind(this));
39+
}
40+
41+
/**
42+
* Unsubscribe from the store.
43+
*/
44+
componentWillUnmount() {
45+
this.unsubscribeInsert();
46+
this.unsubscribeStart();
47+
}
48+
49+
/**
50+
* Handles completion of document insert.
51+
*
52+
* @param {Boolean} success - If the operation succeeded.
53+
* @param {Object} doc - The document or error.
54+
*/
55+
handleDocumentInsert(success, doc) {
56+
if (!success) {
57+
this.setState({ message: doc.message, mode: 'Error' });
58+
}
59+
}
60+
61+
/**
62+
* Handles the start of a document insert.
63+
*/
64+
handleInsertStart() {
65+
this.setState({ message: INSERTING, mode: 'Progess' });
66+
}
67+
68+
/**
69+
* Get the style of the footer based on the current mode.
70+
*
71+
* @returns {String} The style.
72+
*/
73+
style() {
74+
return `document-footer ${MODES[this.state.mode]}`;
75+
}
76+
77+
/**
78+
* Render the footer.
79+
*
80+
* @returns {Component} The footer component.
81+
*/
82+
render() {
83+
return (
84+
<div className={this.style()}>
85+
<div className='edit-message' title={this.state.message}>
86+
{this.state.message}
87+
</div>
88+
</div>
89+
);
90+
}
91+
}
92+
93+
InsertDocumentFooter.displayName = 'InsertDocumentFooter';
94+
95+
module.exports = InsertDocumentFooter;

src/internal-packages/query/lib/component/sampling-message.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ class SamplingMessage extends React.Component {
4848
/**
4949
* Handle updating the count on document insert.
5050
*/
51-
handleInsert() {
52-
this.setState({ count: this.state.count + 1 });
51+
handleInsert(success) {
52+
if (success) {
53+
this.setState({ count: this.state.count + 1 });
54+
}
5355
}
5456

5557
/**

0 commit comments

Comments
 (0)