Skip to content

Commit b301d3b

Browse files
author
Brendan Abbott
committed
Fix react/jsx-no-bind on BodySchema component
1 parent 7a8bce8 commit b301d3b

File tree

4 files changed

+52
-61
lines changed

4 files changed

+52
-61
lines changed

.eslintrc.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@
88
"browser": true,
99
"node": true,
1010
"jest": true
11-
},
12-
"rules": {
13-
// Temporary, components need to be rewritten to take advantage of this
14-
"react/jsx-no-bind": 0
1511
}
1612
}

src/components/BodySchema/BodySchema.js

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { Component } from 'react'
22
import createFragment from 'react-addons-create-fragment'
3-
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
43
import classNames from 'classnames'
54
import PropTypes from 'prop-types'
65

@@ -14,6 +13,7 @@ export default class BodySchema extends Component {
1413

1514
this.renderPropertyRow = this.renderPropertyRow.bind(this)
1615
this.renderSubsetProperties = this.renderSubsetProperties.bind(this)
16+
this.onClick = this.onClick.bind(this)
1717

1818
this.state = {
1919
expandedProp: []
@@ -28,41 +28,37 @@ export default class BodySchema extends Component {
2828
}
2929

3030
const { expandedProp } = this.state
31-
let iterator = 0
31+
3232
return (
3333
<table className={classNames('body-schema', `body-schema--${styleVariation}`)}>
3434
<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)
4137

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) {
5739
return this.renderPropertyRow(property, isLast)
5840
}
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+
}
5955
})}
6056
</tbody>
6157
</table>
6258
)
6359
}
6460

65-
renderPropertyRow (property, isLast, isOpen) {
61+
renderPropertyRow (property, isLast, isOpen = undefined, hasSubset = false) {
6662
return (
6763
<Property
6864
key={property.name}
@@ -73,7 +69,7 @@ export default class BodySchema extends Component {
7369
enumValues={property.enum}
7470
defaultValue={property.defaultValue}
7571
constraints={property.constraints}
76-
onClick={this.onClick.bind(this, property.name)}
72+
onClick={hasSubset ? this.onClick : undefined}
7773
isRequired={property.required}
7874
isOpen={isOpen}
7975
isLast={isLast}
@@ -83,28 +79,18 @@ export default class BodySchema extends Component {
8379

8480
renderSubsetProperties (property, isArray = false) {
8581
const { styleVariation } = this.props
86-
let nextStyleVariation = 'even'
87-
if (styleVariation === 'even') {
88-
nextStyleVariation = 'odd'
89-
}
82+
const nextStyleVariation = (styleVariation === 'even') ? 'odd' : 'even'
83+
9084
return (
9185
<tr className='body-schema-subset'>
9286
<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>}
10894
</td>
10995
</tr>
11096
)

src/components/Property/Property.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,30 @@ import PropertyConstraints from '../PropertyConstraints/PropertyConstraints'
99
import './Property.scss'
1010

1111
export default class Property extends Component {
12+
constructor (props) {
13+
super(props)
14+
15+
this.handleClick = this.handleClick.bind(this)
16+
}
17+
18+
handleClick () {
19+
if (this.props.onClick) {
20+
this.props.onClick(this.props.name)
21+
}
22+
}
23+
1224
render () {
1325
const {
1426
name, type, title, description, constraints, isRequired, enumValues, defaultValue, onClick, isOpen, isLast
1527
} = this.props
1628

29+
const isClickable = onClick !== undefined
30+
1731
let subtype
1832
if (type.includes('array')) {
1933
subtype = this.props.subtype
2034
}
2135

22-
let isClickable = false
23-
if (isOpen !== undefined) {
24-
isClickable = true
25-
}
26-
2736
let status
2837
if (isOpen) {
2938
status = 'open'
@@ -34,7 +43,7 @@ export default class Property extends Component {
3443
className={classNames('property', {
3544
last: isLast
3645
})}
37-
onClick={onClick}
46+
onClick={this.handleClick}
3847
>
3948
<td className={classNames('property-name', {
4049
'property--isclickable': isClickable

test/components/__snapshots__/Property.test.js.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`<Property /> can render a basic property 1`] = `
44
<tr
55
className="property last"
6-
onClick={undefined}
6+
onClick={[Function]}
77
>
88
<td
99
className="property-name"
@@ -36,7 +36,7 @@ exports[`<Property /> can render a basic property 1`] = `
3636
exports[`<Property /> can render a property with a format 1`] = `
3737
<tr
3838
className="property"
39-
onClick={undefined}
39+
onClick={[Function]}
4040
>
4141
<td
4242
className="property-name"
@@ -70,7 +70,7 @@ exports[`<Property /> can render a property with a format 1`] = `
7070
exports[`<Property /> can render a property with a subtype 1`] = `
7171
<tr
7272
className="property"
73-
onClick={undefined}
73+
onClick={[Function]}
7474
>
7575
<td
7676
className="property-name"
@@ -102,7 +102,7 @@ exports[`<Property /> can render a property with a subtype 1`] = `
102102
exports[`<Property /> can render a property with description 1`] = `
103103
<tr
104104
className="property"
105-
onClick={undefined}
105+
onClick={[Function]}
106106
>
107107
<td
108108
className="property-name"
@@ -138,7 +138,7 @@ exports[`<Property /> can render a property with description 1`] = `
138138
exports[`<Property /> can render a property with enum 1`] = `
139139
<tr
140140
className="property"
141-
onClick={undefined}
141+
onClick={[Function]}
142142
>
143143
<td
144144
className="property-name"
@@ -186,7 +186,7 @@ exports[`<Property /> can render a property with enum 1`] = `
186186
exports[`<Property /> can render a property with multiple types 1`] = `
187187
<tr
188188
className="property"
189-
onClick={undefined}
189+
onClick={[Function]}
190190
>
191191
<td
192192
className="property-name"
@@ -213,7 +213,7 @@ exports[`<Property /> can render a property with multiple types 1`] = `
213213
exports[`<Property /> can render a property with numerical constraints 1`] = `
214214
<tr
215215
className="property"
216-
onClick={undefined}
216+
onClick={[Function]}
217217
>
218218
<td
219219
className="property-name"

0 commit comments

Comments
 (0)