@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
value : true
5
5
} ) ;
6
6
7
+ var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
8
+
7
9
var _react = require ( 'react' ) ;
8
10
9
11
var _react2 = _interopRequireDefault ( _react ) ;
@@ -14,93 +16,110 @@ var _propTypes2 = _interopRequireDefault(_propTypes);
14
16
15
17
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
16
18
17
- var Errors = function Errors ( props ) {
18
- var hasErrors = function hasErrors ( error ) {
19
- if ( Array . isArray ( error ) ) {
20
- return error . filter ( function ( item ) {
21
- return ! ! item ;
22
- } ) . length !== 0 ;
23
- }
19
+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
24
20
25
- return ! ! error ;
26
- } ;
21
+ function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
27
22
28
- var formatError = function formatError ( error ) {
29
- if ( typeof error === 'string' ) {
30
- return error ;
31
- }
23
+ function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . __proto__ = superClass ; }
32
24
33
- if ( Array . isArray ( error ) ) {
34
- return error . map ( formatError ) ;
35
- }
25
+ var Errors = function ( _Component ) {
26
+ _inherits ( Errors , _Component ) ;
36
27
37
- if ( error . hasOwnProperty ( 'errors' ) ) {
38
- return Object . keys ( error . errors ) . map ( function ( key , index ) {
39
- var item = error . errors [ key ] ;
40
- return _react2 . default . createElement (
41
- 'div' ,
42
- { key : index } ,
43
- _react2 . default . createElement (
44
- 'strong' ,
45
- null ,
46
- item . name ,
47
- ' (' ,
48
- item . path ,
49
- ')'
50
- ) ,
51
- ' - ' ,
52
- item . message
53
- ) ;
54
- } ) ;
55
- }
28
+ function Errors ( ) {
29
+ _classCallCheck ( this , Errors ) ;
56
30
57
- // If this is a standard error.
58
- if ( error . hasOwnProperty ( 'message' ) ) {
59
- return error . message ;
60
- }
31
+ return _possibleConstructorReturn ( this , ( Errors . __proto__ || Object . getPrototypeOf ( Errors ) ) . apply ( this , arguments ) ) ;
32
+ }
61
33
62
- // If this is a joy validation error.
63
- if ( error . hasOwnProperty ( 'name' ) && error . name === 'ValidationError' ) {
64
- return error . details . map ( function ( item , index ) {
65
- return _react2 . default . createElement (
66
- 'div' ,
67
- { key : index } ,
68
- item . message
69
- ) ;
70
- } ) ;
71
- }
34
+ _createClass ( Errors , [ {
35
+ key : 'hasErrors' ,
36
+ value : function hasErrors ( error ) {
37
+ if ( Array . isArray ( error ) ) {
38
+ return error . filter ( function ( item ) {
39
+ return ! ! item ;
40
+ } ) . length !== 0 ;
41
+ }
72
42
73
- // If a conflict error occurs on a form, the form is returned.
74
- if ( error . hasOwnProperty ( '_id' ) && error . hasOwnProperty ( 'display' ) ) {
75
- return 'Another user has saved this form already. Please reload and re-apply your changes.' ;
43
+ return ! ! error ;
76
44
}
45
+ } , {
46
+ key : 'formatError' ,
47
+ value : function formatError ( error ) {
48
+ if ( typeof error === 'string' ) {
49
+ return error ;
50
+ }
51
+
52
+ if ( Array . isArray ( error ) ) {
53
+ return error . map ( this . formatError ) ;
54
+ }
55
+
56
+ if ( error . hasOwnProperty ( 'errors' ) ) {
57
+ return Object . keys ( error . errors ) . map ( function ( key , index ) {
58
+ var item = error . errors [ key ] ;
59
+ return _react2 . default . createElement (
60
+ 'div' ,
61
+ { key : index } ,
62
+ _react2 . default . createElement (
63
+ 'strong' ,
64
+ null ,
65
+ item . name ,
66
+ ' (' ,
67
+ item . path ,
68
+ ')'
69
+ ) ,
70
+ ' - ' ,
71
+ item . message
72
+ ) ;
73
+ } ) ;
74
+ }
75
+
76
+ // If this is a standard error.
77
+ if ( error . hasOwnProperty ( 'message' ) ) {
78
+ return error . message ;
79
+ }
80
+
81
+ // If this is a joy validation error.
82
+ if ( error . hasOwnProperty ( 'name' ) && error . name === 'ValidationError' ) {
83
+ return error . details . map ( function ( item , index ) {
84
+ return _react2 . default . createElement (
85
+ 'div' ,
86
+ { key : index } ,
87
+ item . message
88
+ ) ;
89
+ } ) ;
90
+ }
91
+
92
+ // If a conflict error occurs on a form, the form is returned.
93
+ if ( error . hasOwnProperty ( '_id' ) && error . hasOwnProperty ( 'display' ) ) {
94
+ return 'Another user has saved this form already. Please reload and re-apply your changes.' ;
95
+ }
96
+
97
+ return 'An error occurred. See console logs for details.' ;
98
+ }
99
+ } , {
100
+ key : 'render' ,
101
+ value : function render ( ) {
102
+ // If there are no errors, don't render anything.
103
+ if ( ! this . hasErrors ( this . props . errors ) ) {
104
+ return null ;
105
+ }
106
+
107
+ return _react2 . default . createElement (
108
+ 'div' ,
109
+ { className : 'alert alert-' + this . props . type , role : 'alert' } ,
110
+ this . formatError ( this . props . errors )
111
+ ) ;
112
+ }
113
+ } ] ) ;
77
114
78
- return 'An error occurred. See console logs for details.' ;
79
- } ;
80
-
81
- // If there are no errors, don't render anything.
82
- var errors = props . errors ,
83
- type = props . type ;
84
-
85
-
86
- if ( ! hasErrors ( errors ) ) {
87
- return null ;
88
- }
89
-
90
- return _react2 . default . createElement (
91
- 'div' ,
92
- { className : 'alert alert-' + type , role : 'alert' } ,
93
- formatError ( errors )
94
- ) ;
95
- } ;
115
+ return Errors ;
116
+ } ( _react . Component ) ;
96
117
97
118
Errors . propTypes = {
98
119
errors : _propTypes2 . default . any ,
99
120
type : _propTypes2 . default . string
100
121
} ;
101
-
102
122
Errors . defaultProps = {
103
123
type : 'danger'
104
124
} ;
105
-
106
125
exports . default = Errors ;
0 commit comments