Skip to content

Commit 8ca951b

Browse files
authored
Merge pull request #35 from brianjshan/left
Fixed some component 🐛s
2 parents a75a199 + c8a326f commit 8ca951b

File tree

11 files changed

+286
-90
lines changed

11 files changed

+286
-90
lines changed

__tests__/enzyme.test.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,37 @@ import LeftContainer from '../app/src/containers/LeftContainer';
1616

1717
// npm test -- -u
1818

19-
2019
describe('Test the CanvasContainer component', () => {
2120
const target = shallow(<CanvasContainer />);
2221
it('Matches snapshot', () => {
23-
expect(target).toMatchSnapshot()
24-
})
22+
expect(target).toMatchSnapshot();
23+
});
2524
it('Contains Canvas component', () => {
2625
expect(target.contains(<Canvas />)).toBe(true);
27-
})
28-
})
26+
});
27+
});
2928

3029
describe('Test the MainContainer component', () => {
3130
const target = shallow(<MainContainer />);
3231
it('Contains CanvasContainer component', () => {
3332
expect(target.contains(<CanvasContainer />)).toBe(true);
34-
})
33+
});
3534
it('Contains BottomPanel component', () => {
3635
expect(target.contains(<BottomPanel />)).toBe(true);
37-
})
38-
})
36+
});
37+
});
3938

4039
describe('Test the BottomTabs component', () => {
4140
const target = shallow(<BottomTabs />);
4241
it('Matches snapshot', () => {
43-
expect(target).toMatchSnapshot()
44-
})
45-
})
42+
expect(target).toMatchSnapshot();
43+
});
44+
});
4645

4746
describe('Test All 10 default HTML elements have rendered', () => {
48-
4947
const target = shallow(
50-
<DndProvider backend={HTML5Backend} >
51-
<StateContext.Provider value={initialState} >
48+
<DndProvider backend={HTML5Backend}>
49+
<StateContext.Provider value={initialState}>
5250
<HTMLPanel />
5351
</StateContext.Provider>
5452
</DndProvider>

app/electron/main.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ app.on('web-contents-created', (event, contents) => {
251251
'https://github.com',
252252
'https://nextjs.org',
253253
'https://developer.mozilla.org',
254-
'https://www.facebook.com',
254+
'https://www.facebook.com'
255255
];
256256

257257
// Log and prevent the app from redirecting to a new page
@@ -406,12 +406,10 @@ ipcMain.on('github', event => {
406406
});
407407
// const authUrl =
408408
// githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scopes;
409-
const authUrl =
410-
`${githubUrl}client_id=${process.env.GITHUB_ID}`;
409+
const authUrl = `${githubUrl}client_id=${process.env.GITHUB_ID}`;
411410
github.loadURL(authUrl);
412411
github.show();
413-
const handleCallback = (url) => {
414-
412+
const handleCallback = url => {
415413
const raw_code = /code=([^&]\*)/.exec(url) || null;
416414
const code = raw_code && raw_code.length > 1 ? raw_code[1] : null;
417415
const error = /\?error=(.+)\$/.exec(url);
@@ -430,18 +428,20 @@ ipcMain.on('github', event => {
430428
'log you in using Github. Please try again.'
431429
);
432430
}
433-
}
431+
};
434432

435433
github.webContents.on('will-navigate', (e, url) => handleCallback(url));
436434

437435
github.webContents.on('did-finish-load', (e, url, a, b) => {
438436
github.webContents.selectAll();
439-
})
437+
});
440438

441-
github.webContents.on('did-get-redirect-request', (e, oldUrl, newUrl) => handleCallback(newUrl));
439+
github.webContents.on('did-get-redirect-request', (e, oldUrl, newUrl) =>
440+
handleCallback(newUrl)
441+
);
442442

443443
// Reset the authWindow on close
444-
github.on('close', () => authWindow = null, false);
444+
github.on('close', () => (authWindow = null), false);
445445

446446
// if final callback is reached and we get a redirect from server back to our app, close oauth window
447447
github.webContents.on('will-redirect', (e, callbackUrl) => {
@@ -460,9 +460,10 @@ ipcMain.on('github', event => {
460460
message: 'Github Oauth Successful!'
461461
});
462462
github.close();
463-
win.webContents.executeJavaScript(`window.localStorage.setItem('ssid', '${ssid}')`)
463+
win.webContents
464+
.executeJavaScript(`window.localStorage.setItem('ssid', '${ssid}')`)
464465
.then(result => win.loadURL(selfHost))
465-
.catch(err => console.log(err))
466+
.catch(err => console.log(err));
466467
}
467468
});
468469
});

app/src/components/bottom/BottomTabs.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,27 @@ const BottomTabs = () => {
6262
value={theme}
6363
onChange={changeTheme}
6464
>
65-
<option style ={{backgroundColor: '#252526'}} value={'monokai'}>Monokai</option>
66-
<option style ={{backgroundColor: '#252526'}} value={'github'}>Github</option>
67-
<option style ={{backgroundColor: '#252526'}} value={'solarized_dark'}>Solarized Dark</option>
68-
<option style ={{backgroundColor: '#252526'}} value={'terminal'}>Terminal</option>
69-
<option style ={{backgroundColor: '#252526'}} value={'solarized_light'}>Solarized Light</option>
65+
<option style={{ backgroundColor: '#252526' }} value={'monokai'}>
66+
Monokai
67+
</option>
68+
<option style={{ backgroundColor: '#252526' }} value={'github'}>
69+
Github
70+
</option>
71+
<option
72+
style={{ backgroundColor: '#252526' }}
73+
value={'solarized_dark'}
74+
>
75+
Solarized Dark
76+
</option>
77+
<option style={{ backgroundColor: '#252526' }} value={'terminal'}>
78+
Terminal
79+
</option>
80+
<option
81+
style={{ backgroundColor: '#252526' }}
82+
value={'solarized_light'}
83+
>
84+
Solarized Light
85+
</option>
7086
</NativeSelect>
7187
</div>
7288
</FormControl>
@@ -83,7 +99,7 @@ const useStyles = makeStyles(theme => ({
8399
backgroundColor: '#333333',
84100
height: '100%',
85101
color: '#fff',
86-
boxShadow: '0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)',
102+
boxShadow: '0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)'
87103
},
88104
bottomHeader: {
89105
flex: 1,

app/src/components/left/HTMLPanel.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const HTMLPanel = (): JSX.Element => {
1515
let startingID = 0;
1616
state.HTMLTypes.forEach(element => {
1717
if (element.id >= startingID) startingID = element.id;
18-
})
18+
});
1919
startingID += 1;
2020

2121
const [currentID, setCurrentID] = useState(startingID);
@@ -90,7 +90,7 @@ const HTMLPanel = (): JSX.Element => {
9090
setName('');
9191
};
9292

93-
const alphanumeric = (input:string): boolean => {
93+
const alphanumeric = (input: string): boolean => {
9494
let letterNumber = /^[0-9a-zA-Z]+$/;
9595
if (input.match(letterNumber)) return true;
9696
return false;
@@ -118,10 +118,10 @@ const HTMLPanel = (): JSX.Element => {
118118

119119
const handleDelete = (id: number): void => {
120120
dispatch({
121-
type: "DELETE ELEMENT",
121+
type: 'DELETE ELEMENT',
122122
payload: id
123123
});
124-
}
124+
};
125125

126126
return (
127127
<div>

app/src/components/main/Canvas.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import renderChildren from '../../helperFunctions/renderChildren';
99
const findNestedChild = (curr, components) => {
1010
components.forEach((comp, i) => {
1111
comp.children.forEach(child => {
12-
if (child.name === curr.name) console.log(child.name)
12+
if (child.name === curr.name) console.log('childname', child.name);
1313
});
1414
if (comp.children.length !== 0) findNestedChild(curr, comp.children);
1515
});
16-
}
16+
};
1717

1818
function Canvas() {
1919
const [state, dispatch] = useContext(StateContext);

app/src/containers/RightContainer.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,25 @@ const RightContainer = (): JSX.Element => {
153153

154154
const isChildOfPage = (): boolean => {
155155
let isChild: boolean = false;
156+
157+
// id of target we want to check
156158
const { id } = configTarget;
159+
// put in logic here to check for all nested children
160+
// const checkAllChildren = comps => {
161+
// comps.forEach(el => {
162+
// if (el.children.length > 0) {
163+
// checkAllChildren(el.children);
164+
// }
165+
// if (el.type === 'Component' && el.typeId === id) {
166+
// isChild = true;
167+
// }
168+
// });
169+
// };
170+
// const copyComp = [...state.components];
171+
// checkAllChildren(copyComp);
172+
// return isChild;
173+
174+
// was here previously
157175
state.components.forEach(comp => {
158176
comp.children.forEach(child => {
159177
if (child.type === 'Component' && child.typeId === id) {
@@ -215,9 +233,10 @@ const RightContainer = (): JSX.Element => {
215233
};
216234

217235
const handleDeleteReusableComponent = () => {
218-
isChildOfPage()
219-
? handleDialogError('component')
220-
: dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
236+
// isChildOfPage()
237+
// ? handleDialogError('component')
238+
// :
239+
dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
221240
};
222241

223242
const isReusable = (configTarget): boolean => {

app/src/helperFunctions/generateCode.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { Component, State, ChildElement, HTMLType } from '../interfaces/Interfaces';
2-
1+
import {
2+
Component,
3+
State,
4+
ChildElement,
5+
HTMLType
6+
} from '../interfaces/Interfaces';
37

48
declare global {
59
interface Window {
@@ -28,6 +32,7 @@ const generateUnformattedCode = (
2832
const getEnrichedChildren = (currentComponent: Component | ChildElement) => {
2933
const enrichedChildren = currentComponent.children.map((elem: any) => {
3034
const child = { ...elem };
35+
console.log('child', child);
3136
if (child.type === 'Component') {
3237
const referencedComponent = components.find(
3338
elem => elem.id === child.typeId
@@ -220,7 +225,6 @@ const generateUnformattedCode = (
220225

221226
// formats code with prettier linter
222227
const formatCode = (code: string) => {
223-
224228
// in test environment, window.api is not defined,
225229
// so we reference original prettier format function instead
226230
if (process.env.NODE_ENV === 'test') {

app/src/helperFunctions/renderChildren.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const renderChildren = (children: ChildElement[]) => {
1414
const [state, dispatch] = useContext(StateContext);
1515
return children.map((child: ChildElement, i: number) => {
1616
const { type, typeId, style, childId, children, attributes, name } = child;
17-
if (name === '') child.name = state.components[typeId - 1 ].name;
17+
if (name === '') child.name = state.components[typeId - 1].name;
1818
// A DirectChildComponent is an instance of a top level component
1919
// This component will render IndirectChild components (div/components rendered inside a child component)
2020
if (type === 'Component') {

0 commit comments

Comments
 (0)