@@ -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- }
0 commit comments