Skip to content

Commit b23fd76

Browse files
del reusable comps
1 parent 8024867 commit b23fd76

File tree

6 files changed

+51
-37
lines changed

6 files changed

+51
-37
lines changed

app/electron/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,5 @@ ipcMain.on('github', event => {
396396
}
397397
});
398398
});
399+
400+
//module.exports = dialog;

app/src/components/left/ComponentPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const ComponentPanel = (): JSX.Element => {
8282
};
8383

8484
const handleNameSubmit = () => {
85-
let letters = /[a-z]/;
85+
let letters = /[a-zA-Z]/;
8686
if (!compName.charAt(0).match(letters)) {
8787
triggerError('letters');
8888
return;

app/src/components/main/Canvas.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function Canvas() {
3838

3939
// if item dropped is going to be a new instance (i.e. it came from the left panel), then create a new child component
4040
if (item.newInstance) {
41-
console.log('new item dropped')
4241
dispatch({
4342
type: 'ADD CHILD',
4443
payload: {
@@ -76,6 +75,8 @@ function Canvas() {
7675
// Combine the default styles of the canvas with the custom styles set by the user for that component
7776
// The render children function renders all direct children of a given component
7877
// Direct children are draggable/clickable
78+
//console.log('curr comp =>', currentComponent);
79+
//console.log('curr comp style', currentComponent.style);
7980
const canvasStyle = combineStyles(defaultCanvasStyle, currentComponent.style);
8081
return (
8182
<div ref={drop} style={canvasStyle} onClick={onClickHandler}>

app/src/components/main/DirectChildComponent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
7272
const renderIndirectChildren = (
7373
referencedComponent: Component | ChildElement
7474
) => {
75+
console.log('referenced comp => ', referencedComponent);
7576
// iterate through all children of referenced
7677
return referencedComponent.children.map(child => {
7778
if (child.type === 'Component') {

app/src/containers/RightContainer.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ const RightContainer = (props): JSX.Element => {
156156
dispatch({ type: 'DELETE CHILD', payload: {} });
157157
};
158158

159-
const handleDeleteReusableComponent = (id) => () => {
160-
//console.log(id);
161-
dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: { id} });
159+
const handleDeleteReusableComponent = () => {
160+
dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
162161
}
163162

164163
const isReusable = (configTarget): boolean => {
@@ -374,7 +373,7 @@ const RightContainer = (props): JSX.Element => {
374373
<Button
375374
color="secondary"
376375
className={classes.button}
377-
onClick={handleDeleteReusableComponent(configTarget.id)}
376+
onClick={handleDeleteReusableComponent}
378377
>
379378
DELETE REUSABLE COMPONENT
380379
</Button>

app/src/reducers/componentReducer.ts

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,27 @@ const reducer = (state: State, action: Action) => {
8888
return;
8989
};
9090

91+
const isChildOfPage = (id: number): boolean => {
92+
// TODO: refactor
93+
// TODO: output parent name and id to refocus canvas on parent
94+
let isChild: boolean = false;
95+
state.components.forEach(comp => {
96+
console.log('comp =>', comp);
97+
comp.children.forEach(child => {
98+
if (child.type === 'Component' && child.typeId === id) {
99+
isChild = true;
100+
console.log('parent name =>', comp.name);
101+
console.log('parent id =>', comp.name);
102+
}
103+
});
104+
});
105+
return isChild;
106+
}
107+
108+
const updateIds = (components: Array<Object>) => {
109+
components.forEach((comp, i) => comp.id = i + 1);
110+
}
111+
91112
switch (action.type) {
92113
// Add a new component type
93114
// add component to the component array and increment our counter for the componentId
@@ -290,39 +311,29 @@ const reducer = (state: State, action: Action) => {
290311
}
291312

292313
case 'DELETE REUSABLE COMPONENT' : {
293-
// const component = findComponent(
294-
// components,
295-
// state.canvasFocus.componentId
296-
// );
297-
const { id } = action.payload;
298-
// slice id out of components
299-
const components = [...state.components].filter(comp => comp.id != id);
300-
const component = findComponent(
301-
state.components,
302-
state.canvasFocus.componentId
303-
);
304-
//const newComponents = components
305-
306-
console.log('components', state.components);
307-
console.log('new components', components);
308-
//console.log('id', id);
309-
//console.log(state.canvasFocus.componentId);
310-
// component.code = generateCode(
311-
// components,
312-
// state.canvasFocus.componentId,
313-
// [...state.rootComponents],
314-
// state.projectType
315-
// );
316-
//console.log('deleted component', component);
317-
//component.code = '';
318-
const canvasFocus = { ...state.canvasFocus, childId: null };
319-
return {...state, components, canvasFocus};
320-
}
321-
322-
323-
314+
// TODO: bug when deleting element inside page
315+
// can't edit component name
316+
// happens sometimes. not sure exactly when
317+
318+
const id: number = state.canvasFocus.componentId;
319+
// check if component is a child element of a page
320+
if(isChildOfPage(id)) {
321+
// TODO: include name of parent in alert
322+
// TODO: change canvas focus to parent
323+
//dialog.showErrorBox('error','Reusable components inside of a page must be deleted from the page');
324+
alert('Reusable components inside of a page must be deleted from the page');
325+
//const canvasFocus:Object = { componentId: id, childId: null };
326+
return { ...state }
327+
}
328+
// filter out components that don't match id
329+
const components: Array<Object> = [...state.components].filter(comp => comp.id != id);
324330

331+
updateIds(components);
325332

333+
// TODO: temporary fix. should point to id directly
334+
const canvasFocus = { componentId: 1, childId: null };
335+
return {...state, components, canvasFocus};
336+
}
326337

327338
case 'SET INITIAL STATE': {
328339
// set the canvas focus to be the first component

0 commit comments

Comments
 (0)