Skip to content

Commit e0e7f90

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
handletransform working, waiting to merge with Chris
2 parents 66f5e09 + c3ead03 commit e0e7f90

File tree

7 files changed

+155
-97
lines changed

7 files changed

+155
-97
lines changed

src/actions/components.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,31 @@ import { loadState } from '../localStorage';
3232
// import createApplicationUtil from '../utils/createApplication.util';
3333

3434
export const loadInitData = () => (dispatch) => {
35-
loadState()
36-
.then(data => dispatch({
37-
type: LOAD_INIT_DATA,
38-
payload: {
39-
data: data ? data.workspace : {},
40-
},
41-
}));
35+
loadState().then(data => dispatch({
36+
type: LOAD_INIT_DATA,
37+
payload: {
38+
data: data ? data.workspace : {},
39+
},
40+
}));
4241
};
4342

44-
export const updateChildren = (({
45-
parentIds, childIndex, childId,
46-
}) => ({
43+
export const updateChildren = ({ parentIds, childIndex, childId }) => ({
4744
type: UPDATE_CHILDREN,
4845
payload: {
49-
parentIds, childIndex, childId,
46+
parentIds,
47+
childIndex,
48+
childId,
5049
},
51-
}));
50+
});
5251

53-
export const parentReassignment = (({ index, id, parentIds }) => ({
52+
export const parentReassignment = ({ index, id, parentIds }) => ({
5453
type: REASSIGN_PARENT,
5554
payload: {
5655
index,
5756
id,
5857
parentIds,
5958
},
60-
}));
59+
});
6160

6261
export const addComponent = ({ title }) => (dispatch) => {
6362
dispatch({ type: ADD_COMPONENT, payload: { title } });
@@ -82,12 +81,20 @@ export const deleteComponent = ({ index, id, parentIds = [] }) => (dispatch) =>
8281
};
8382

8483
export const updateComponent = ({
85-
id, index, newParentId = null, color = null, stateful = null,
84+
id,
85+
index,
86+
newParentId = null,
87+
color = null,
88+
stateful = null,
8689
}) => (dispatch) => {
8790
dispatch({
8891
type: UPDATE_COMPONENT,
8992
payload: {
90-
id, index, newParentId, color, stateful,
93+
id,
94+
index,
95+
newParentId,
96+
color,
97+
stateful,
9198
},
9299
});
93100

@@ -123,12 +130,17 @@ export const handleClose = () => ({
123130
payload: false,
124131
});
125132

126-
export const handleTransform = (id, {
133+
export const handleTransform = (componentId, childId, {
127134
x, y, width, height,
128135
}) => ({
129136
type: HANDLE_TRANSFORM,
130137
payload: {
131-
id, x, y, width, height,
138+
componentId,
139+
childId,
140+
x,
141+
y,
142+
width,
143+
height,
132144
},
133145
});
134146

src/components/KonvaStage.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class KonvaStage extends Component {
1616
this.group = createRef();
1717
}
1818

19+
// Christian - this function causes the expansionPanel of the clicked rect to open
20+
// (and focusedComponent to change, which we don't want)
21+
// could reuse this logic for affecting state of children array
22+
// ADD CHANG FOCUS CHILD FUNCTIONALITY HERE
1923
handleStageMouseDown = e => {
2024
// // clicked on stage - cler selection
2125
// if (e.target === e.target.getStage()) {
@@ -30,13 +34,14 @@ class KonvaStage extends Component {
3034

3135
// find clicked rect by its name
3236
const id = e.target.name();
37+
console.log(e.target);
3338
const rect = this.props.components.find(r => r.id === id);
3439

35-
if (rect) {
36-
this.props.openExpansionPanel(rect);
37-
} else {
38-
this.props.openExpansionPanel({});
39-
}
40+
// if (rect) {
41+
// this.props.openExpansionPanel(rect || this.props.focusComponent);
42+
// } else {
43+
// this.props.openExpansionPanel(this.props.focusComponent);
44+
// }
4045
};
4146

4247
// WAS ALREADY COMMENTED OUT
@@ -92,14 +97,15 @@ class KonvaStage extends Component {
9297
<Rectangle
9398
draggable={child.draggable}
9499
selectedShapeName={selectedShapeName}
95-
key={i + child.componentName}
96-
componentId={child.id}
100+
key={i + `${child.componentName}`}
101+
childId={child.childId}
102+
componentId={focusComponent.id}
97103
x={child.position.x}
98104
y={child.position.y}
99105
width={child.position.width}
100106
height={child.position.height}
101107
title={child.childId + child.componentName}
102-
color={"red"}
108+
color={child.color}
103109
handleTransform={handleTransform}
104110
/>
105111
))}

src/components/LeftColExpansionPanel.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ const LeftColExpansionPanel = (props) => {
3939
<ListItem
4040
button
4141
component="a"
42-
// style={
43-
// if (components.find(comp => comp.title === focusComponent.title))
44-
// }
4542
style={{ color: 'red' }}
4643
onClick={() => {
4744
console.log({ title });

src/components/Rectangle.jsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,53 @@ import { Rect } from 'react-konva';
33
// import PropTypes from 'prop-types';
44

55
class Rectangle extends Component {
6-
extractPositionInfo(componentId, target) {
6+
extractPositionInfo(componentId, childId, target) {
7+
console.log('extracting position info, Rectanlge.jsx');
78
const transformation = {
89
x: target.x(),
910
y: target.y(),
1011
width: target.width() * target.scaleX(),
1112
height: target.height() * target.scaleY(),
1213
};
1314

14-
this.props.handleTransform(componentId, transformation);
15+
this.props.handleTransform(componentId, childId, transformation);
1516
}
1617

1718
render() {
1819
const {
19-
color, x, y, componentId, draggable, width, height, title,
20+
color, x, y, childId, componentId, draggable, width, height, title,
2021
} = this.props;
21-
22+
console.log('childId in rectangle:', childId);
2223
return (
2324
<Rect
24-
name={componentId}
25+
name={`${childId}`}
2526
x={x}
2627
y={y}
27-
componentid={componentId}
28+
childId={childId}
29+
componentId={componentId}
30+
title={title}
2831
scaleX={1}
2932
scaleY={1}
3033
width={width}
3134
height={height}
3235
stroke={color}
3336
strokeWidth={6}
3437
strokeScaleEnabled={false}
35-
onTransformEnd={event => this.extractPositionInfo(componentId, event.target)}
36-
onDragEnd={event => this.extractPositionInfo(componentId, event.target)}
38+
onTransformEnd={event => this.extractPositionInfo(componentId, childId, event.target)}
39+
onDragEnd={event => this.extractPositionInfo(componentId, childId, event.target)}
3740
draggable={draggable}
38-
dragBoundFunc={function dragBoundFunc(pos) {
39-
console.log('binding');
40-
const newY = pos.y < 200 ? 200 : pos.y;
41-
const newX = pos.x < 200 ? 200 : pos.x;
42-
return {
43-
x: newX,
44-
y: newY,
45-
};
46-
}}
41+
color={color}
42+
// use dragBoundFunc to bind children within parents
43+
// (but if only children are rendered/movable, and parent is size of canvas, won't need this anyways )
44+
// dragBoundFunc={function dragBoundFunc(pos) {
45+
// console.log('binding');
46+
// const newY = pos.y < 200 ? 200 : pos.y;
47+
// const newX = pos.x < 200 ? 200 : pos.x;
48+
// return {
49+
// x: newX,
50+
// y: newY,
51+
// };
52+
// }}
4753
/>
4854
);
4955
}

src/components/TransformerComponent.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export default class TransformerComponent extends Component {
1515
const stage = this.transformer.getStage();
1616
const { focusChild } = this.props;
1717
const selectedNode = stage.findOne(`.${focusChild.childId}`);
18-
18+
// console.log('selected node from within TransformerComponent: ', selectedNode);
19+
// console.log('stage: ', stage);
20+
// console.log('focusChild: ', focusChild, focusChild.childId, typeof focusChild.childId);
1921
if (selectedNode === this.transformer.node()) {
2022
return;
2123
}

src/containers/MainContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import KonvaStage from '../components/KonvaStage.jsx';
1616
const IPC = require('electron').ipcRenderer;
1717

1818
const mapDispatchToProps = dispatch => ({
19-
handleTransformation: (id, {
19+
handleTransformation: (componentId, childId, {
2020
x, y, width, height,
2121
}) => dispatch(
22-
handleTransform(id, {
22+
handleTransform(componentId, childId, {
2323
x,
2424
y,
2525
width,

0 commit comments

Comments
 (0)