1- var React = require ( 'react' ) ;
1+ import React from 'react' ;
22
33import AttributeRow from './AttributeRow' ;
44import Collapsible from '../Collapsible' ;
55
66function isSingleProperty ( schema ) {
7- if ( 'type' in schema ) {
8- return typeof schema . type === 'string' ;
9- }
10- return 'default' in schema ;
7+ if ( 'type' in schema ) {
8+ return typeof schema . type === 'string' ;
9+ }
10+ return 'default' in schema ;
1111}
1212
1313export default class Component extends React . Component {
14+ static propTypes = {
15+ component : React . PropTypes . any ,
16+ entity : React . PropTypes . object ,
17+ name : React . PropTypes . string
18+ } ;
19+
1420 deleteComponent = event => {
1521 event . stopPropagation ( ) ;
1622 this . props . entity . removeAttribute ( this . props . name ) ;
@@ -21,44 +27,48 @@ export default class Component extends React.Component {
2127 this . props . entity . setAttribute ( this . props . name , { } ) ;
2228 }
2329
24- render ( ) {
25- var componentData = this . props . component ;
26- var componentName = this . props . name . toUpperCase ( ) ;
27- var subComponentName = '' ;
30+ render ( ) {
31+ const componentData = this . props . component ;
32+ let componentName = this . props . name . toUpperCase ( ) ;
33+ let subComponentName = '' ;
2834
2935 if ( componentName . indexOf ( '__' ) !== - 1 ) {
3036 subComponentName = componentName ;
3137 componentName = componentName . substr ( 0 , componentName . indexOf ( '__' ) ) ;
3238 }
3339
34- var attributeRows = '' ;
40+ let attributeRows ;
3541 if ( isSingleProperty ( componentData . schema ) ) {
3642 var key = componentName . toLowerCase ( ) ;
3743 var schema = AFRAME . components [ key . toLowerCase ( ) ] . schema ;
38- var data = isSingleProperty ( schema ) ? componentData . data : componentData . data [ key ] ;
39- attributeRows = < AttributeRow key = { key } name = { key } schema = { schema } data = { componentData . data } componentname = { key } entity = { this . props . entity } />
40- //attributeRows = <AttributeRow key={key} name={key} schema={componentData.schema[key]} data={componentData.data[key]} componentname={this.props.name} entity={this.props.entity} />
44+ attributeRows = (
45+ < AttributeRow key = { key } name = { key } schema = { schema }
46+ data = { componentData . data } componentname = { key }
47+ entity = { this . props . entity } />
48+ ) ;
4149 } else {
42- attributeRows = Object . keys ( componentData . schema ) . map ( function ( key ) {
43- //var data = isSingleProperty(schema) ? componentData.data : componentData.data[key];
44- var schema = componentData . schema [ key ] ;
45- return < AttributeRow key = { key } name = { key } schema = { componentData . schema [ key ] } data = { componentData . data [ key ] } componentname = { this . props . name } entity = { this . props . entity } />
46- } . bind ( this ) )
50+ attributeRows = Object . keys ( componentData . schema ) . map ( key => {
51+ return (
52+ < AttributeRow key = { key } name = { key } schema = { componentData . schema [ key ] }
53+ data = { componentData . data [ key ] } componentname = { this . props . name }
54+ entity = { this . props . entity } />
55+ ) ;
56+ } ) ;
4757 }
4858
4959 return (
5060 < Collapsible >
51- < div className = " collapsible-header" >
52- < span > { componentName } < span className = " subcomponent" > { subComponentName } </ span > </ span >
53- < div className = " dropdown menu" >
54- < div className = " dropdown-content" >
55- < a href = "#" onClick = { this . deleteComponent } > Delete</ a >
56- < a href = "#" onClick = { this . resetComponent } > Reset to default</ a >
57- < a href = "#" className = " disabled" > Copy to clipboard</ a >
61+ < div className = ' collapsible-header' >
62+ < span > { componentName } < span className = ' subcomponent' > { subComponentName } </ span > </ span >
63+ < div className = ' dropdown menu' >
64+ < div className = ' dropdown-content' >
65+ < a href = '#' onClick = { this . deleteComponent } > Delete</ a >
66+ < a href = '#' onClick = { this . resetComponent } > Reset to default</ a >
67+ < a href = '#' className = ' disabled' > Copy to clipboard</ a >
5868 </ div >
5969 </ div >
6070 </ div >
61- < div className = " collapsible-content" > { attributeRows } </ div >
71+ < div className = ' collapsible-content' > { attributeRows } </ div >
6272 </ Collapsible >
6373 ) ;
6474 }
0 commit comments