@@ -6,8 +6,8 @@ import TransformerComponent from './TransformerComponent.jsx';
6
6
// import PropTypes from 'prop-types';
7
7
8
8
class Rectangle extends Component {
9
- handleResize ( componentId , childId , target , components ) {
10
- const focChild = components
9
+ handleResize ( componentId , childId , target ) {
10
+ const focChild = this . props . components
11
11
. find ( comp => comp . id === componentId )
12
12
. childrenArray . find ( child => child . childId === childId ) ;
13
13
@@ -31,42 +31,41 @@ class Rectangle extends Component {
31
31
this . props . handleTransform ( componentId , childId , transformation ) ;
32
32
}
33
33
34
- findDescendants ( component , components , descendants = [ ] ) {
35
- // fix this stuff Adam
36
- if ( ! component ) return ;
37
- component . childrenArray . forEach ( ( child ) => {
38
- descendants . push ( child ) ;
39
- const childComponent = components . find ( comp => comp . title === child . componentName ) ;
40
- this . findDescendants ( childComponent , components , descendants ) ;
41
- } ) ;
42
- return descendants ;
34
+ getComponentOfThisChild ( ) {
35
+ console . log ( 'title of this child: ' , componentName ) ;
36
+ console . log (
37
+ 'component of this child: ' ,
38
+ this . props . components . find ( comp => comp . title === componentName ) ,
39
+ ) ;
43
40
}
44
41
45
42
render ( ) {
46
43
const {
47
44
color,
48
45
x,
49
46
y,
47
+ scaleX,
48
+ scaleY,
50
49
childId,
51
50
componentId,
52
- draggable ,
51
+ componentName ,
53
52
width,
54
53
height,
55
54
title,
56
55
focusChild,
57
- focusComponent,
58
56
components,
57
+ draggable,
59
58
} = this . props ;
60
59
61
60
// the Group is responsible for dragging of all children
62
61
// the Rect emits changes to child width and height with help from Transformer
63
62
return (
64
63
< Group
65
- draggable = { true }
64
+ draggable = { draggable }
66
65
x = { x }
67
66
y = { y }
68
- scaleX = { 1 }
69
- scaleY = { 1 }
67
+ scaleX = { scaleX }
68
+ scaleY = { scaleY }
70
69
width = { width }
71
70
height = { height }
72
71
onDragEnd = { event => this . handleDrag ( componentId , childId , event . target ) }
@@ -87,17 +86,37 @@ class Rectangle extends Component {
87
86
color = { color }
88
87
// fill={color}
89
88
// opacity={0.8}
90
- onTransformEnd = { event => this . handleResize ( componentId , childId , event . target , components )
91
- }
89
+ onTransformEnd = { event => this . handleResize ( componentId , childId , event . target ) }
92
90
strokeWidth = { 4 }
93
91
strokeScaleEnabled = { false }
94
92
draggable = { false }
95
93
/>
96
94
< Label >
97
95
< Text text = { title } fill = { 'white' } />
98
96
</ Label >
99
- { /* {this.findDescendants().map} */ }
100
- < Rect
97
+ { components
98
+ . find ( comp => comp . title === componentName )
99
+ . childrenArray . map ( ( grandchild , i ) => (
100
+ < Rectangle
101
+ key = { i }
102
+ components = { components }
103
+ componentId = { componentId }
104
+ componentName = { grandchild . componentName }
105
+ focusChild = { focusChild }
106
+ childId = { grandchild . childId }
107
+ x = { grandchild . position . x }
108
+ y = { grandchild . position . y }
109
+ scaleX = { 0.8 }
110
+ scaleY = { 0.8 }
111
+ width = { grandchild . position . width }
112
+ height = { grandchild . position . height }
113
+ // title={child.componentName + child.childId}
114
+ color = { color }
115
+ handleTransform = { ( ) => { } }
116
+ draggable = { false }
117
+ />
118
+ ) ) }
119
+ { /* <Rect
101
120
// replace with grandchildren rectangles
102
121
scaleX={0.2}
103
122
scaleY={0.2}
@@ -107,9 +126,9 @@ class Rectangle extends Component {
107
126
color={color}
108
127
strokeWidth={4}
109
128
draggable={false}
110
- />
111
- { focusChild . childId === childId ? (
112
- < TransformerComponent focusComponent = { focusComponent } focusChild = { focusChild } />
129
+ /> */ }
130
+ { focusChild . childId === childId && draggable ? (
131
+ < TransformerComponent focusChild = { focusChild } />
113
132
) : (
114
133
< Label />
115
134
) }
0 commit comments