Skip to content

Commit 4e01bb4

Browse files
committed
Displaying error modal should not remove rest of the content
Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
1 parent 22a29db commit 4e01bb4

3 files changed

Lines changed: 49 additions & 38 deletions

File tree

public/js/error_modal.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,34 @@ import React from 'react';
66
* to set modal title. errorData.message is inserted as HTML text in modal
77
* body. And errorData.more_info is shown using a pre tag in modal body.
88
*
9-
* The component is stateless. The displayed modal dialog cannot be dismissed.
9+
* The displayed modal dialog cannot be dismissed.
1010
* The user must close the tab or press back button to go back to search form.
1111
*/
12-
class ErrorModal extends React.Component {
12+
export default class ErrorModal extends React.Component {
1313

1414
constructor(props) {
1515
super(props);
16+
this.state = { errorData: {} };
1617
}
1718

1819
// HTML for Bootstrap modal.
1920
render() {
2021
return (
21-
<div
22-
id="error" ref="errorModal" className="modal fade"
22+
<div id="error" ref="modal" className="modal fade"
2323
data-keyboard="false" data-backdrop="static">
24-
<div
25-
className="modal-dialog modal-lg">
26-
<div
27-
className="modal-content">
28-
<div
29-
className="modal-header">
30-
<h3>{this.props.errorData.title}</h3>
24+
<div className="modal-dialog modal-lg">
25+
<div className="modal-content">
26+
<div className="modal-header">
27+
<h3>{this.state.errorData.title}</h3>
3128
</div>
3229

33-
<div
34-
className="modal-body">
35-
<p dangerouslySetInnerHTML={{ __html: this.props.errorData.message}}></p>
30+
<div className="modal-body">
31+
<p dangerouslySetInnerHTML={{ __html: this.state.errorData.message}}></p>
3632

3733
{
38-
this.props.errorData.more_info &&
34+
this.state.errorData.more_info &&
3935
<pre className="pre-scrollable">
40-
{this.props.errorData.more_info}
36+
{this.state.errorData.more_info}
4137
</pre>
4238
}
4339
</div>
@@ -47,21 +43,23 @@ class ErrorModal extends React.Component {
4743
);
4844
}
4945

50-
// Show the modal once the component is mounted.
51-
componentDidMount() {
46+
/*
47+
* Returns jQuery reference to the main modal container.
48+
*/
49+
modal () {
50+
return $(React.findDOMNode(this.refs.modal));
51+
}
52+
53+
/**
54+
* Shows error viewer.
55+
*/
56+
show (errorData, beforeShow) {
57+
this.setState({errorData: errorData});
5258
// Caller can specify an amount of time to wait for before showing the
5359
// modal. This is helpful if the caller wants to finish some work
5460
// before showing error modal.
55-
setTimeout(function () {
56-
$(React.findDOMNode(this.refs.errorModal)).modal('show');
57-
}.bind(this), this.props.beforeShow || 0);
61+
setTimeout(() => {
62+
this.modal().modal('show');
63+
}, beforeShow || 0);
5864
}
5965
}
60-
61-
/**
62-
* Renders ErrorModal.
63-
*/
64-
export default function showErrorModal (errorData, beforeShow) {
65-
React.render(<ErrorModal errorData={errorData}
66-
beforeShow={beforeShow}/>, document.getElementById('view'));
67-
}

public/js/report.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Hit from './hit';
99
import HSP from './hsp';
1010

1111
import SequenceModal from './sequence_modal';
12-
import showErrorModal from './error_modal';
12+
import ErrorModal from './error_modal';
1313

1414
/**
1515
* Base component of report page. This component is later rendered into page's
@@ -23,7 +23,8 @@ var Page = React.createClass({
2323
the Report component to render itself in. */}
2424
<div className="container">
2525
<Report showSequenceModal={ _ => this.showSequenceModal(_) }
26-
getCharacterWidth={ () => this.getCharacterWidth() } />
26+
getCharacterWidth={ () => this.getCharacterWidth() }
27+
showErrorModal={ (...args) => this.showErrorModal(...args) } />
2728
</div>
2829

2930
{/* Add a hidden span tag containing chars used in HSPs */}
@@ -34,7 +35,10 @@ var Page = React.createClass({
3435
{/* Required by Grapher for SVG and PNG download */}
3536
<canvas id="png-exporter" hidden></canvas>
3637

37-
<SequenceModal ref="sequenceModal" />
38+
<SequenceModal ref="sequenceModal"
39+
showErrorModal={ (...args) => this.showErrorModal(...args) }/>
40+
41+
<ErrorModal ref="errorModal" />
3842
</div>
3943
);
4044
},
@@ -48,6 +52,10 @@ var Page = React.createClass({
4852
this.refs.sequenceModal.show(url);
4953
},
5054

55+
showErrorModal: function (errorData, beforeShow) {
56+
this.refs.errorModal.show(errorData, beforeShow);
57+
},
58+
5159
getCharacterWidth: function () {
5260
if (!this.characterWidth) {
5361
var $hspChars = $(React.findDOMNode(this.refs.hspChars));
@@ -118,7 +126,7 @@ var Report = React.createClass({
118126
case 404:
119127
case 400:
120128
case 500:
121-
showErrorModal(jqXHR.responseJSON);
129+
component.props.showErrorModal(jqXHR.responseJSON);
122130
break;
123131
}
124132
});

public/js/sequence_modal.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import './sequence';
22
import React from 'react';
33
import _ from 'underscore';
4-
import showErrorModal from './error_modal';
54

65
/**
76
* Takes sequence accession as props, fetches the sequence from the server, and
@@ -54,6 +53,13 @@ export default class SequenceModal extends React.Component {
5453
});
5554
}
5655

56+
/**
57+
* Hide sequence viewer.
58+
*/
59+
hide () {
60+
this.modal().modal('hide');
61+
}
62+
5763
/**
5864
* Loads sequence using AJAX and updates modal state.
5965
*/
@@ -67,10 +73,9 @@ export default class SequenceModal extends React.Component {
6773
requestCompleted: true
6874
});
6975
}, this))
70-
.fail(function (jqXHR, status, error) {
71-
showErrorModal(jqXHR, function () {
72-
this.hide();
73-
});
76+
.fail((jqXHR, status, error) => {
77+
this.hide();
78+
this.props.showErrorModal(jqXHR.responseJSON);
7479
});
7580

7681
}

0 commit comments

Comments
 (0)