@@ -4,8 +4,10 @@ import { bindActionCreators } from 'redux';
4
4
import { withRouter } from 'react-router' ;
5
5
import { HotKeys } from 'react-hotkeys' ;
6
6
import Editor from '../../components/Editor' ;
7
+ import Errors from '../../components/Errors' ;
7
8
import Button from '../../components/Button' ;
8
9
import { putConfig , onEditorChange } from '../../actions/config' ;
10
+ import { clearErrors } from '../../actions/utils' ;
9
11
import { getLeaveMessage } from '../../constants/lang' ;
10
12
import { toYAML , preventDefault } from '../../utils/helpers' ;
11
13
@@ -22,6 +24,14 @@ export class Configuration extends Component {
22
24
router . setRouteLeaveHook ( route , this . routerWillLeave . bind ( this ) ) ;
23
25
}
24
26
27
+ componentWillUnmount ( ) {
28
+ const { clearErrors, errors } = this . props ;
29
+ // clear errors if any
30
+ if ( errors . length ) {
31
+ clearErrors ( ) ;
32
+ }
33
+ }
34
+
25
35
routerWillLeave ( nextLocation ) {
26
36
if ( this . props . editorChanged ) {
27
37
return getLeaveMessage ( ) ;
@@ -40,14 +50,15 @@ export class Configuration extends Component {
40
50
}
41
51
42
52
render ( ) {
43
- const { editorChanged, onEditorChange, config, updated } = this . props ;
44
-
53
+ const { editorChanged, onEditorChange, config, updated, errors } = this . props ;
54
+ const { raw_content } = config ;
45
55
const keyboardHandlers = {
46
56
'save' : this . handleClickSave ,
47
57
} ;
48
58
49
59
return (
50
- < HotKeys handlers = { keyboardHandlers } >
60
+ < HotKeys handlers = { keyboardHandlers } className = "single" >
61
+ { errors && errors . length > 0 && < Errors errors = { errors } /> }
51
62
< div className = "content-header" >
52
63
< h1 > Configuration</ h1 >
53
64
< div className = "page-buttons" >
@@ -58,11 +69,14 @@ export class Configuration extends Component {
58
69
triggered = { updated } />
59
70
</ div >
60
71
</ div >
61
- < Editor
62
- editorChanged = { editorChanged }
63
- onEditorChange = { onEditorChange }
64
- content = { toYAML ( config ) }
65
- ref = "editor" />
72
+ {
73
+ raw_content &&
74
+ < Editor
75
+ editorChanged = { editorChanged }
76
+ onEditorChange = { onEditorChange }
77
+ content = { raw_content }
78
+ ref = "editor" />
79
+ }
66
80
</ HotKeys >
67
81
) ;
68
82
}
@@ -74,19 +88,23 @@ Configuration.propTypes = {
74
88
putConfig : PropTypes . func . isRequired ,
75
89
updated : PropTypes . bool . isRequired ,
76
90
editorChanged : PropTypes . bool . isRequired ,
91
+ errors : PropTypes . array . isRequired ,
92
+ clearErrors : PropTypes . func . isRequired ,
77
93
router : PropTypes . object . isRequired ,
78
94
route : PropTypes . object . isRequired
79
95
} ;
80
96
81
97
const mapStateToProps = ( state ) => ( {
82
98
config : state . config . config ,
83
99
updated : state . config . updated ,
84
- editorChanged : state . config . editorChanged
100
+ editorChanged : state . config . editorChanged ,
101
+ errors : state . utils . errors
85
102
} ) ;
86
103
87
104
const mapDispatchToProps = ( dispatch ) => bindActionCreators ( {
88
105
putConfig,
89
- onEditorChange
106
+ onEditorChange,
107
+ clearErrors
90
108
} , dispatch ) ;
91
109
92
110
export default withRouter ( connect ( mapStateToProps , mapDispatchToProps ) ( Configuration ) ) ;
0 commit comments