1
1
import React , { Component } from 'react'
2
2
import createFragment from 'react-addons-create-fragment'
3
- import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
4
3
import classNames from 'classnames'
5
4
import PropTypes from 'prop-types'
6
5
@@ -14,6 +13,7 @@ export default class BodySchema extends Component {
14
13
15
14
this . renderPropertyRow = this . renderPropertyRow . bind ( this )
16
15
this . renderSubsetProperties = this . renderSubsetProperties . bind ( this )
16
+ this . onClick = this . onClick . bind ( this )
17
17
18
18
this . state = {
19
19
expandedProp : [ ]
@@ -28,41 +28,37 @@ export default class BodySchema extends Component {
28
28
}
29
29
30
30
const { expandedProp } = this . state
31
- let iterator = 0
31
+
32
32
return (
33
33
< table className = { classNames ( 'body-schema' , `body-schema--${ styleVariation } ` ) } >
34
34
< tbody >
35
- { properties . map ( ( property ) => {
36
- iterator = iterator + 1
37
- let isLast = false
38
- if ( properties . length === iterator ) {
39
- isLast = true
40
- }
35
+ { properties . map ( ( property , i ) => {
36
+ const isLast = ( properties . length === i + 1 )
41
37
42
- if ( property . type . includes ( 'array' ) && expandedProp . includes ( property . name ) && property . properties !== undefined ) {
43
- return createFragment ( {
44
- property : this . renderPropertyRow ( property , isLast , true ) ,
45
- subset : this . renderSubsetProperties ( property , true )
46
- } )
47
- } else if ( property . type . includes ( 'array' ) && property . properties !== undefined ) {
48
- return this . renderPropertyRow ( property , isLast , false )
49
- } else if ( property . type . includes ( 'object' ) && expandedProp . includes ( property . name ) && property . properties !== undefined ) {
50
- return createFragment ( {
51
- property : this . renderPropertyRow ( property , isLast , true ) ,
52
- subset : this . renderSubsetProperties ( property )
53
- } )
54
- } else if ( property . type . includes ( 'object' ) && property . properties !== undefined ) {
55
- return this . renderPropertyRow ( property , isLast , false )
56
- } else {
38
+ if ( property . properties === undefined ) {
57
39
return this . renderPropertyRow ( property , isLast )
58
40
}
41
+
42
+ const isPropertyArray = property . type . includes ( 'array' )
43
+ const isPropertyObject = property . type . includes ( 'object' )
44
+
45
+ if ( isPropertyArray || isPropertyObject ) {
46
+ if ( expandedProp . includes ( property . name ) ) {
47
+ return createFragment ( {
48
+ property : this . renderPropertyRow ( property , isLast , true , true ) ,
49
+ subset : this . renderSubsetProperties ( property , isPropertyArray )
50
+ } )
51
+ }
52
+
53
+ return this . renderPropertyRow ( property , isLast , false , true )
54
+ }
59
55
} ) }
60
56
</ tbody >
61
57
</ table >
62
58
)
63
59
}
64
60
65
- renderPropertyRow ( property , isLast , isOpen ) {
61
+ renderPropertyRow ( property , isLast , isOpen = undefined , hasSubset = false ) {
66
62
return (
67
63
< Property
68
64
key = { property . name }
@@ -73,7 +69,7 @@ export default class BodySchema extends Component {
73
69
enumValues = { property . enum }
74
70
defaultValue = { property . defaultValue }
75
71
constraints = { property . constraints }
76
- onClick = { this . onClick . bind ( this , property . name ) }
72
+ onClick = { hasSubset ? this . onClick : undefined }
77
73
isRequired = { property . required }
78
74
isOpen = { isOpen }
79
75
isLast = { isLast }
@@ -83,28 +79,18 @@ export default class BodySchema extends Component {
83
79
84
80
renderSubsetProperties ( property , isArray = false ) {
85
81
const { styleVariation } = this . props
86
- let nextStyleVariation = 'even'
87
- if ( styleVariation === 'even' ) {
88
- nextStyleVariation = 'odd'
89
- }
82
+ const nextStyleVariation = ( styleVariation === 'even' ) ? 'odd' : 'even'
83
+
90
84
return (
91
85
< tr className = 'body-schema-subset' >
92
86
< td colSpan = '100' >
93
- < ReactCSSTransitionGroup
94
- transitionName = 'schema-slide-toggle'
95
- transitionEnterTimeout = { 500 }
96
- transitionLeaveTimeout = { 500 }
97
- transitionAppear
98
- transitionAppearTimeout = { 500 }
99
- >
100
- { isArray && < div > Array [</ div > }
101
- < BodySchema
102
- key = { `${ property . name } -properties` }
103
- properties = { property . properties }
104
- styleVariation = { nextStyleVariation }
105
- />
106
- { isArray && < div > ]</ div > }
107
- </ ReactCSSTransitionGroup >
87
+ { isArray && < div > Array [</ div > }
88
+ < BodySchema
89
+ key = { `${ property . name } -properties` }
90
+ properties = { property . properties }
91
+ styleVariation = { nextStyleVariation }
92
+ />
93
+ { isArray && < div > ]</ div > }
108
94
</ td >
109
95
</ tr >
110
96
)
0 commit comments