Skip to content

Commit

Permalink
refactored code and merged
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlabrie committed Feb 25, 2021
1 parent bfd2bf8 commit 129efab
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 156 deletions.
Binary file modified .DS_Store
Binary file not shown.
47 changes: 0 additions & 47 deletions app/server/controllers/mongoSchemaController.js

This file was deleted.

4 changes: 0 additions & 4 deletions app/server/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const MongoClient = require('mongodb').MongoClient;
var pluralize = require('pluralize');
const { ipcMain } = require('electron')


const {
GraphQLObjectType,
GraphQLString,
Expand All @@ -15,7 +14,6 @@ const {
GraphQLNonNull,
} = graphql;


const converter = {};
let rootQueryObj = {};

Expand Down Expand Up @@ -264,10 +262,8 @@ ipcMain.on('selectedSchemas', (event, arg) => {
`${addWhiteSpace(4)}},|`;

// resetting the fieldsObject
// console.log('this is stringObj ====>', strFieldsObj);
fieldsObj = {};
strFields = '';
// mutationObjStr = '';
mutationToString = '';
mongoSchemaStr = '';
}
Expand Down
3 changes: 0 additions & 3 deletions app/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
const fs = require('fs');
const { graphqlHTTP } = require('express-graphql');
const schemaRoute = require('./schema');

const mongoSchemaController = require('./controllers/mongoSchemaController');


app.use(express.json());
app.use(cors());

Expand Down Expand Up @@ -45,7 +43,6 @@ app.use((err, req, res, next) => {
return res.status(errorObj.status).json(errorObj.message);
});


app.listen(3000, () => console.log('listening on port 3000'));
module.exports = app;
})()
2 changes: 2 additions & 0 deletions app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import "./public/index.css";

// Create main App component
const App = () => {
return (
<div>
<Container />
<AutoUpdate />
</div>
)
}
// Export the App component
export default App;
8 changes: 4 additions & 4 deletions app/src/Components/AutoUpdate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import "./public/index.css";
import "../public/index.css";
const { ipcRenderer } = require('electron')

const AutoUpdate = () => {
Expand Down Expand Up @@ -27,12 +27,12 @@ const AutoUpdate = () => {
};

return (
<div id="notification" class="hidden">
<div id="notification" className="hidden">
<p id="message"></p>
<button id="close-button" onClick="closeNotification()">
<button id="close-button" onClick={closeNotification}>
Close
</button>
<button id="restart-button" onClick="restartApp()" class="hidden">
<button id="restart-button" onClick={restartApp} className="hidden">
Restart
</button>
</div>
Expand Down
5 changes: 1 addition & 4 deletions app/src/Components/CheckBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ const CheckBox = (props) => {
<div className="checkboxContainer" id="box">
<form className="checkboxForm">
<label className="checkboxLabel">
<input className="checkbox" type="checkbox" name={props.name} onClick={props.clicked} />
{/* name is the key which is the obj */}
<input className="checkbox" type="checkbox" name={props.name} onClick={props.clicked} disabled={props.toggleCheckbox}/>
{props.name}
</label>
</form>
</div>
)
}



export default CheckBox;
21 changes: 5 additions & 16 deletions app/src/Components/DropDownMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
// research code mirror to hold the schemas
// todo: create functionality so that when a checkbox is clicked, the schema appears on the page

import React, { useState, useEffect } from 'react';
import React from 'react';
import CheckBox from './CheckBox';
import {ipcRenderer} from "electron";


const DropDownMenu = ({schemaData, uriData, sendSchemas, addCheckmark}) => {

const checkHandler = e => {
const schemaNames = Object.keys(schemaData);
const tools = props.schemaNames.clicked; //Array in parent component
const value = e.target.value; //Checkbox value

props.addCheckmark(value);
};

const DropDownMenu = ({schemaData, uriData, sendSchemas, addCheckmark, toggleBtn, toggleCheckbox}) => {
const checkBoxComponents = [];

for (let key in schemaData) {
checkBoxComponents.push(
<CheckBox name={key} key={`checkbox${key}`} clicked={addCheckmark} />
<CheckBox name={key} key={`dropdown${key}`} clicked={addCheckmark} toggleCheckbox={toggleCheckbox} />
)
}

Expand All @@ -30,13 +21,11 @@ const DropDownMenu = ({schemaData, uriData, sendSchemas, addCheckmark}) => {
{checkBoxComponents}
</div>
<div className="addSchemaBtn" >
<button className="AddSelectedSchemasButton" onClick={sendSchemas}><span>Add Selected Schemas</span></button>
<button className={toggleBtn ? "AddSelectedSchemasButton": "disableAddSelected"} onClick={sendSchemas} disabled={!toggleBtn}><span>Add Selected Schemas</span></button>
</div>
</div>
)
}



export default DropDownMenu;

2 changes: 1 addition & 1 deletion app/src/Components/MongoDBURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const MongoDBURI = ({schemaData, uriData, submitbtn, geturi}) => {
<div className="formContainer">
<div className="formClass">
<form className="form__group field">
<input className="form__field" type="input" onChange= {geturi} id='name' placeholder=" Input Your MongoDB URI"/>
<input className="form__field" type="input" onChange={geturi} id='name' placeholder=" Input Your MongoDB URI"/>
<label className="form__label"> MongoDB URI </label>
<input className="URISubmitButton" type="submit" value="Submit" onClick={submitbtn} style={{display: "none"}}/>
</form>
Expand Down
1 change: 1 addition & 0 deletions app/src/Components/MongoSchemaIDE.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const MongoSchemaIDE = ({schemaData, selectedSchemaData, graphQLSchema}) => {
<CodeMirror
value={_.isEmpty(graphQLSchema) ? `/*
*** Input MongoDB Uri ***
*** Press Enter ***
*** Click Add Selected Schemas ***
*** View GraphQL Schemas Here ***
*/` : combined}
Expand Down
11 changes: 11 additions & 0 deletions app/src/Components/ResetButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

const ResetButton = ({resetBtn}) => {
return (
<div>
<button className="resetButton" type="reset" onClick={resetBtn}> RESET </button>
</div>
);
};

export default ResetButton;
2 changes: 1 addition & 1 deletion app/src/Components/Ribbon.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

const Ribbon = () => {
return <div class="corner-ribbon top-right sticky blue"> <a href="https://github.com/oslabs-beta/QLens" target="_blank">See on GitHub</a> </div>;
return <div className="corner-ribbon top-right sticky blue"> <a href="https://github.com/oslabs-beta/QLens" target="_blank">See on GitHub</a> </div>;
};

export default Ribbon;
23 changes: 21 additions & 2 deletions app/src/containers/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Loader from '../Components/Loader';
import Ribbon from '../Components/Ribbon';
import fetch from 'electron-fetch'
import {ipcRenderer} from "electron";
import ResetButton from '../Components/ResetButton'

const Container = () => {
const [schemaData, setSchemaData] = useState({});
Expand All @@ -20,15 +21,25 @@ const Container = () => {
const [graphQLSchema, setGraphQLSchema] = useState({});
const [loading, setLoading] = useState(false);

const [toggleASSBtn, setToggleASSBtn] = useState(false)
const [toggleInput, setToggleInput] = useState(false)
const [toggleCheckbox, setToggleCheckbox] = useState(false)

// enter MongoDBURI to receive schemas
// submit function fetches schemas from backend when Submit button is clicked

const submit = (e) => {
e.preventDefault();
setLoading(true);
ipcRenderer.send('URI', uriId)
setToggleASSBtn(!toggleASSBtn)
setToggleInput(!toggleInput)
};

const resetButton = () => {
window.location.reload(true);
}

ipcRenderer.on('URI-reply', (event, arg) => {
setSchemaData(JSON.parse(arg));
setLoading(false);
Expand All @@ -54,12 +65,14 @@ const Container = () => {
// sendSchema function builds the selectedSchemas object with the schemas that are selected in the DropDownMenu
// sends the selectedSchemas to the backend for migration
const sendSchemas = (e) => {
setSelectedSchemaData([]);
let selectedSchemas = {};
for (let i = 0; i < clicked.length; i += 1) {
selectedSchemas[clicked[i]] = schemaData[clicked[i]];
}
setSelectedSchemaData([selectedSchemas]);
setClicked([])
setToggleASSBtn(!toggleASSBtn)
setToggleCheckbox(!toggleCheckbox)
ipcRenderer.send('selectedSchemas', {selectedSchemas, uriId})
};

Expand Down Expand Up @@ -110,15 +123,18 @@ const Container = () => {
submitbtn={submit}
sendSchemas={sendSchemas}
addCheckmark={addCheckmark}
toggleInput= {toggleInput}
/>
<PlaygroundButton />
</div>
<div className="grid-container">
<DropDownMenu
<DropDownMenu
schemaData={schemaData}
uriData={uriId}
sendSchemas={sendSchemas}
addCheckmark={addCheckmark}
toggleBtn={toggleASSBtn}
toggleCheckbox={toggleCheckbox}
/>
{Object.keys(schemaChart).length > 0 ? (
<TreeGraph schemaChart={schemaChart} />
Expand All @@ -129,6 +145,9 @@ const Container = () => {
/>
</div>
<Ribbon/>
<ResetButton
resetBtn={resetButton}
/>
</div>
</Fragment>
);
Expand Down
Loading

0 comments on commit 129efab

Please sign in to comment.