@@ -23,16 +23,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
23
23
} ;
24
24
var React = require ( 'react' ) ;
25
25
var react_redux_1 = require ( 'react-redux' ) ;
26
+ var redux_form_1 = require ( 'redux-form' ) ;
26
27
var SelectField_1 = require ( 'material-ui/SelectField' ) ;
27
28
var Card_1 = require ( 'material-ui/Card' ) ;
28
29
var RaisedButton_1 = require ( 'material-ui/RaisedButton' ) ;
29
30
var actions_1 = require ( '../../actions' ) ;
30
31
var languageItems_1 = require ( './languageItems' ) ;
31
32
var runnerItems_1 = require ( './runnerItems' ) ;
32
33
var Top_1 = require ( '../TopPanel/Top' ) ;
33
- var redux_form_1 = require ( 'redux-form' ) ;
34
- var coderoad_cli_1 = require ( 'coderoad-cli' ) ;
35
34
var TextField_1 = require ( 'material-ui/TextField' ) ;
35
+ var formSelector = redux_form_1 . formValueSelector ( 'tutorialConfig' ) ;
36
36
var styles = {
37
37
card : {
38
38
margin : '10px' ,
@@ -43,76 +43,60 @@ var styles = {
43
43
margin : '30px 10px 20px 10px' ,
44
44
} ,
45
45
} ;
46
- var fields = [ 'name' , 'language' , 'runner' ] ;
47
- var validate = function ( values ) {
48
- var errors = { } ;
49
- if ( ! name ) {
50
- errors . name = 'Required' ;
51
- }
52
- else if ( ! coderoad_cli_1 . validateName ( name ) ) {
53
- errors . name = 'Invalid "coderoad-*" name' ;
54
- }
55
- if ( ! values . language ) {
56
- errors . language = 'Required' ;
57
- }
58
- if ( ! values . runner ) {
59
- errors . runner = 'Required' ;
60
- }
61
- return errors ;
62
- } ;
63
46
var TutorialConfig = ( function ( _super ) {
64
47
__extends ( TutorialConfig , _super ) ;
65
- function TutorialConfig ( props ) {
66
- _super . call ( this , props ) ;
67
- var _a = this . props . packageJson , name = _a . name , config = _a . config ;
68
- this . state = {
69
- name : name ,
70
- language : config . language ,
71
- runner : config . runner ,
72
- } ;
48
+ function TutorialConfig ( ) {
49
+ _super . apply ( this , arguments ) ;
73
50
}
74
51
TutorialConfig . prototype . componentDidMount = function ( ) {
75
52
Top_1 . default . toggle ( false ) ;
76
53
} ;
77
- TutorialConfig . prototype . handleText = function ( prop , event , value ) {
78
- var next = { } ;
79
- next [ prop ] = value ;
80
- this . setState ( Object . assign ( { } , this . state , next ) ) ;
81
- } ;
82
- TutorialConfig . prototype . handleSelect = function ( prop , event , index , value ) {
83
- var next = { } ;
84
- next [ prop ] = value ;
85
- this . setState ( Object . assign ( { } , this . state , next ) ) ;
86
- } ;
87
- TutorialConfig . prototype . submit = function ( ) {
88
- var _a = this . state , name = _a . name , language = _a . language , runner = _a . runner ;
89
- this . props . save ( Object . assign ( { } , this . props . packageJson , {
90
- name : name ,
91
- config : {
92
- language : language , runner : runner
93
- }
94
- } ) ) ;
54
+ TutorialConfig . prototype . handleSubmit = function ( e ) {
55
+ console . log ( e ) ;
56
+ console . log ( this . props . values ) ;
95
57
} ;
96
58
TutorialConfig . prototype . render = function ( ) {
97
- var _a = this . state , name = _a . name , language = _a . language , runner = _a . runner ;
98
- return ( React . createElement ( Card_1 . Card , { style : styles . card } , React . createElement ( Card_1 . CardHeader , { title : 'Tutorial Configuration' } ) , React . createElement ( TextField_1 . default , { className : 'native-key-bindings' , value : name , onChange : this . handleText . bind ( this , 'name' ) } ) , React . createElement ( "br" , null ) , React . createElement ( SelectField_1 . default , __assign ( { floatingLabelText : 'Language' , value : language } , language , { onChange : this . handleSelect . bind ( this , 'language' ) } ) , languageItems_1 . default ( ) ) , React . createElement ( "br" , null ) , React . createElement ( SelectField_1 . default , __assign ( { floatingLabelText : 'Test Runner' , value : runner } , runner , { onChange : this . handleSelect . bind ( this , 'runner' ) } ) , runnerItems_1 . default ( language ) ) , React . createElement ( "br" , null ) , React . createElement ( RaisedButton_1 . default , { type : 'submit' , style : styles . button , label : 'Save' , primary : true , onTouchTap : this . submit . bind ( this ) } ) , React . createElement ( RaisedButton_1 . default , { style : styles . button , label : 'Continue' , secondary : true , onTouchTap : this . props . routeToPage . bind ( this ) } ) ) ) ;
59
+ var _this = this ;
60
+ console . log ( this . props . values ) ;
61
+ var name = this . props . packageJson . name ;
62
+ var _a = this . props . packageJson . config , language = _a . language , runner = _a . runner ;
63
+ var _b = this . props , pristine = _b . pristine , submitting = _b . submitting ;
64
+ return ( React . createElement ( Card_1 . Card , { style : styles . card } , React . createElement ( Card_1 . CardHeader , { title : 'Tutorial Configuration' } ) , React . createElement ( "form" , { onSubmit : this . handleSubmit } , React . createElement ( redux_form_1 . Field , { name : 'name' , component : function ( name ) { return ( React . createElement ( TextField_1 . default , __assign ( { name : 'name' , className : 'native-key-bindings' , hintText : 'coderoad-tutorial-name' , floatingLabelText : 'Tutorial Name' , errorText : name . touched && name . error } , name ) ) ) ; } } ) , React . createElement ( "br" , null ) , React . createElement ( redux_form_1 . Field , { name : 'language' , component : function ( props ) {
65
+ return React . createElement ( "div" , null , React . createElement ( SelectField_1 . default , __assign ( { value : props . value , floatingLabelText : 'Language' , errorText : props . touched && props . error } , props , { onChange : function ( event , index , value ) { return props . onChange ( value ) ; } } ) , languageItems_1 . default ( ) ) ) ;
66
+ } } ) , React . createElement ( redux_form_1 . Field , { name : 'runner' , component : function ( props ) {
67
+ return React . createElement ( "div" , null , React . createElement ( SelectField_1 . default , __assign ( { value : props . value , floatingLabelText : 'Test Runner' , errorText : props . touched && props . error } , props , { onChange : function ( event , index , value ) { return props . onChange ( value ) ; } } ) , runnerItems_1 . default ( _this . props . values . language ) ) ) ;
68
+ } } ) , React . createElement ( "br" , null ) , React . createElement ( RaisedButton_1 . default , { type : 'submit' , style : styles . button , label : 'Save' , primary : true , disabled : pristine || submitting , onTouchTap : this . submit . bind ( this ) } ) , React . createElement ( RaisedButton_1 . default , { style : styles . button , label : 'Continue' , secondary : true , onTouchTap : this . props . routeToPage . bind ( this ) } ) ) ) ) ;
99
69
} ;
100
70
TutorialConfig = __decorate ( [
101
71
react_redux_1 . connect ( function ( state ) { return ( {
102
72
packageJson : state . packageJson ,
73
+ values : formSelector ( state , 'name' , 'language' , 'runner' ) ,
103
74
} ) ; } , function ( dispatch ) { return ( {
104
75
save : function ( pj ) { return dispatch ( actions_1 . pjSave ( pj ) ) ; } ,
105
76
routeToPage : function ( ) {
106
77
dispatch ( actions_1 . tutorialInit ( ) ) ;
107
78
dispatch ( actions_1 . routeSet ( 'page' ) ) ;
108
79
}
109
80
} ) ; } ) ,
110
- __metadata ( 'design:paramtypes' , [ Object ] )
81
+ __metadata ( 'design:paramtypes' , [ ] )
111
82
] , TutorialConfig ) ;
112
83
return TutorialConfig ;
113
84
} ( React . Component ) ) ;
85
+ var validate = function ( values ) {
86
+ var errors = { } ;
87
+ var requiredFields = [ 'name' , 'language' , 'runner' ] ;
88
+ requiredFields . forEach ( function ( field ) {
89
+ if ( ! values [ field ] ) {
90
+ errors [ field ] = 'Required' ;
91
+ }
92
+ } ) ;
93
+ if ( values . name && ! values . name . match ( / ^ c o d e r o a d - [ A - Z a - z 0 - 9 \- ] + $ / ) ) {
94
+ errors . name = 'Invalid "coderoad-*" name' ;
95
+ }
96
+ return errors ;
97
+ } ;
114
98
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
115
99
exports . default = redux_form_1 . reduxForm ( {
116
- form : 'config ' ,
117
- fields : fields ,
100
+ form : 'tutorialConfig ' ,
101
+ validate : validate ,
118
102
} ) ( TutorialConfig ) ;
0 commit comments