Skip to content

Commit 742af53

Browse files
authored
Merge pull request #24 from sean1292/staging
Change focus component can now be done from component tree graph
2 parents 2e73814 + 9b012a0 commit 742af53

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/components/BottomPanel.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { connect } from 'react-redux';
33
import { handleClose, deleteProp, addProp } from '../actions/components';
44
import BottomTabs from './BottomTabs';
55
import { PropsInt, PropInt } from '../utils/Interfaces';
6+
import { changeFocusComponent } from '../utils/componentReducer.util';
67

78
const IPC = require('electron').ipcRenderer;
89

@@ -20,11 +21,19 @@ const mapStateToProps = (store: any) => ({
2021
interface BottomPanelPropsInt extends PropsInt {
2122
deleteProp(id: number): void;
2223
addProp(prop: PropInt): void;
24+
changeFocusComponent(arg: { title: string }): void;
2325
}
2426

2527
class BottomPanel extends Component<BottomPanelPropsInt> {
2628
render() {
27-
const { components, focusComponent, deleteProp, addProp, focusChild } = this.props;
29+
const {
30+
components,
31+
focusComponent,
32+
deleteProp,
33+
addProp,
34+
focusChild,
35+
changeFocusComponent
36+
} = this.props;
2837

2938
return (
3039
<div className="bottom-panel" style={{ width: '100%' }}>
@@ -34,6 +43,7 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
3443
deleteProp={deleteProp}
3544
addProp={addProp}
3645
focusChild={focusChild}
46+
changeFocusComponent={changeFocusComponent}
3747
/>
3848
</div>
3949
);

src/components/BottomTabs.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface BottomTabsPropsInt extends PropsInt {
1212
deleteProp(id: number): void;
1313
addProp(prop: PropInt): void;
1414
classes: any;
15+
changeFocusComponent(arg: { title: string }): void;
1516
}
1617

1718
// interface TreeInt {
@@ -102,6 +103,10 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
102103
this.setState({ value });
103104
};
104105

106+
handleClick = (event: any, node: any) => {
107+
this.props.changeFocusComponent({ title: event.name });
108+
};
109+
105110
generateComponentTree(componentId: number, components: ComponentsInt) {
106111
const component = components.find(comp => comp.id === componentId);
107112
const tree: any = { name: component.title, attributes: {}, children: [] };
@@ -177,6 +182,7 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
177182
separation={{ siblings: 0.3, nonSiblings: 0.3 }}
178183
transitionDuration={0}
179184
translate={this.state.translate}
185+
onClick={this.handleClick}
180186
styles={{
181187
nodes: {
182188
node: {

src/containers/MainContainer.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
handleTransform,
1111
changeFocusChild,
1212
changeComponentFocusChild,
13-
deleteChild
13+
deleteChild,
14+
changeFocusComponent
1415
} from '../actions/components';
1516
import KonvaStage from '../components/KonvaStage';
1617
import { PropsInt, ApplicationStateInt } from '../utils/Interfaces';
@@ -24,6 +25,7 @@ interface MainContPropsInt extends PropsInt {
2425
): void;
2526
changeComponentFocusChild(arg: { componentId: number; childId: number }): void;
2627
deleteChild(obj: object): void;
28+
changeFocusComponent(arg: { title: string }): void;
2729
}
2830

2931
interface StateInt {
@@ -57,6 +59,8 @@ const mapDispatchToProps = (dispatch: any) => ({
5759
// changeImagePath: (imageSource: string) =>
5860
// dispatch(actions.changeImagePath(imageSource)),
5961

62+
changeFocusComponent: ({ title }: { title: string }) => dispatch(changeFocusComponent({ title })),
63+
6064
//this function changes the focus of the child within the focused component, thereby binding it to the transformer as a node
6165
changeFocusChild: ({ childId }: { childId: number }) => dispatch(changeFocusChild({ childId })),
6266

@@ -94,6 +98,7 @@ class MainContainer extends Component<MainContPropsInt, StateInt> {
9498
focusComponent,
9599
focusChild,
96100
changeFocusChild,
101+
changeFocusComponent,
97102
changeComponentFocusChild,
98103
deleteChild,
99104
image
@@ -123,7 +128,10 @@ class MainContainer extends Component<MainContPropsInt, StateInt> {
123128
/* classes={classes} commented out because not used anywhere*/
124129
/>
125130
</div>
126-
<BottomPanel focusComponent={focusComponent} />
131+
<BottomPanel
132+
focusComponent={focusComponent}
133+
changeFocusComponent={changeFocusComponent}
134+
/>
127135
</div>
128136
</MuiThemeProvider>
129137
);

0 commit comments

Comments
 (0)