Skip to content

Commit b75a750

Browse files
authored
Merge pull request #20 from oslabs-beta/feature/example
Feature/example
2 parents 83d19e5 + 5e8a6fd commit b75a750

File tree

16 files changed

+131
-91
lines changed

16 files changed

+131
-91
lines changed

app/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import './index.scss';
77
// this is the fitness gram pacer test
88
// React memo helps with rendering optimization. The components within React memo will only be rerendered if prompt has changed
99
const App: React.FC = React.memo(() => {
10-
console.log('test')
1110
return (
1211
<div>
1312
<Splash />

app/components/ApplicationsCard/ApplicationsCard.tsx

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,53 @@ const ApplicationsCard = (props) => {
1515
const { application, i, setModal, classes } = props
1616
const { deleteApp,user,applications } = useContext(DashboardContext)
1717
const { setAppIndex, setApp, setServicesData, app,example,connectToDB,setChart } = useContext(ApplicationContext)
18-
const [ cardName,dbType,dbURI,description,serviceType ] = applications[i]
18+
const [ cardName,dbType,dbURI,description,serviceType ] = application
1919

2020
//dynamic refs
21-
const delRef = useRef<any>([]);
21+
// const delRef = useRef<any>([]);
2222

2323
const navigate = useNavigate();
2424

2525
// Handle clicks on Application cards
2626
// v10 info: when card is clicked (not on the delete button) if the service is an AWS instance,
2727
// you are redirected to AWSGraphsContainer passing in the state object containing typeOfService
2828
const handleClick = (
29-
event: ClickEvent,
3029
selectedApp: string,
3130
selectedService: string,
3231
i: number
3332
) => {
34-
//delRef refers to the delete button
35-
if (delRef.current[i] && !delRef.current[i].contains(event.target)) {
33+
const services = ['auth','client','event-bus','items','inventory','orders']
34+
// if (delRef.current[i] && !delRef.current[i].contains(event.target)) {
35+
setAppIndex(i);
36+
setApp(selectedApp);
3637
if (
3738
selectedService === 'AWS' ||
3839
selectedService === 'AWS/EC2' ||
3940
selectedService === 'AWS/ECS' ||
4041
selectedService === 'AWS/EKS'
4142
) {
42-
setAppIndex(i);
43-
setApp(selectedApp);
4443
navigate(`/aws/:${app}`, { state: { typeOfService: selectedService } });
4544
}
4645
else if(example) {
47-
setAppIndex(i);
48-
setApp(selectedApp);
4946
setServicesData([]);
5047
setChart('communications')
5148

5249
connectToDB(user, i, app, dbURI, dbType)
50+
navigate(`/applications/example/${services.join(' ')}`)
5351
}
5452
else {
55-
setAppIndex(i);
56-
setApp(selectedApp);
5753
setServicesData([]);
5854
//When we open the service modal a connection is made to the db in a useEffect inside of the service modal component
5955
setModal({isOpen:true,type:'serviceModal'})
6056
}
61-
}
57+
// }
6258
};
6359

6460
// Asks user to confirm deletion
65-
const confirmDelete = (event: ClickEvent, application: string, i: number) => {
61+
const confirmDelete = (event: ClickEvent, i: number) => {
62+
event.stopPropagation()
6663
const message = `The application '${app}' will be permanently deleted. Continue?`;
67-
if (confirm(message)) deleteApp(i);
64+
if (confirm(message)) deleteApp(i,"");
6865
};
6966

7067
return (
@@ -73,41 +70,29 @@ const ApplicationsCard = (props) => {
7370
key={`card-${i}`}
7471
className={classes.paper}
7572
variant="outlined"
76-
onClick={event => handleClick(event, application[0], application[3], i)}
73+
onClick={() => handleClick(application[0], application[3], i)}
7774
>
7875
<div className="databaseIconContainer">
7976
<div className="databaseIconHeader">
80-
{/* {application[1] === 'SQL' ? (
81-
<img className="databaseIcon" alt="SQL" />
82-
) : (
83-
<img className="databaseIcon" alt="MongoDB" />
84-
)} */}
8577
</div>
8678
</div>
8779

8880
<CardHeader
8981
avatar={
9082
<IconButton
9183
id="iconButton"
92-
ref={element => {
93-
delRef.current[i] = element;
94-
}}
9584
className={classes.iconbutton}
9685
aria-label="Delete"
97-
onClick={event => confirmDelete(event, application[0], i)}
86+
onClick={event => confirmDelete(event, i)}
9887
>
9988
<HighlightOffIcon
10089
className={classes.btnStyle}
10190
id="deleteIcon"
102-
ref={element => {
103-
delRef.current[i] = element;
104-
}}
10591
/>
10692
</IconButton>
10793
}
10894
/>
10995
<CardContent>
110-
{/* <p id="databaseName">Name:</p> */}
11196
<Typography noWrap id="databaseName" className={classes.fontStyles}>
11297
{application[0]}
11398
</Typography>

app/components/Occupied/Occupied.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ import DashboardIcons from '../DashboardIcons/DashboardIcons';
3434
import ApplicationsCard from '../ApplicationsCard/ApplicationsCard';
3535

3636
import { useStylesLight, useStylesDark } from './helpers/muiHelper'
37-
import { Link } from 'react-router-dom';
3837

3938
//v10: Memoized function, without any props. Should theoretically be called only once.
4039
const Occupied = React.memo(() => {
41-
const { setServicesData, app,example } = useContext(ApplicationContext);
40+
const { setServicesData, app, example } = useContext(ApplicationContext);
4241
const { user, applications, getApplications, mode } = useContext(DashboardContext);
4342
const [ modal,setModal ] = useState({isOpen:false,type:''})
4443
const { appIndex } = useContext(ApplicationContext);
@@ -74,7 +73,7 @@ const Occupied = React.memo(() => {
7473
<div
7574
className="cardContainer"
7675
>
77-
76+
{!example &&
7877
<div
7978
className="card"
8079
id="card-add"
@@ -88,26 +87,24 @@ const Occupied = React.memo(() => {
8887
/>
8988
</Button>
9089
</div>
90+
}
9191

9292
{applications
93-
.filter((db: any) => db[0].toLowerCase().includes(searchTerm.toLowerCase()))
9493
.map((application: string[], i: any) => {
95-
const services = ['auth','client','event-bus','items','inventory','orders']
96-
console.log({app,services})
94+
const description = application[3]
95+
const cardName = application[0]
96+
const isFiltered = cardName.toLowerCase().includes(searchTerm.toLowerCase())
97+
98+
if((!example && description === "Example") || !isFiltered) return <></>
9799
return (
98-
<Link
99-
to={services.length > 0 ? `/applications/example/${services.join(' ')}` : '#'}
100-
className=''>
101-
<ApplicationsCard
102-
key={crypto.randomUUID()}
103-
application={application}
104-
i={i}
105-
setModal={setModal}
106-
classes={classes}
107-
/>
108-
</Link>
109-
)
110-
})}
100+
<ApplicationsCard
101+
key={crypto.randomUUID()}
102+
application={application}
103+
i={i}
104+
setModal={setModal}
105+
classes={classes}
106+
/>
107+
)})}
111108

112109
<Modal
113110
open={modal.isOpen}

app/containers/SidebarContainer/SidebarContainer.tsx

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import { DashboardContext } from '../../context/DashboardContext';
1313

1414
const SidebarContainer = React.memo(() => {
1515
// Extract invervalID from ApplicationContext. Initival value: intervalID = null
16-
const { intervalID, setExample } = useContext(ApplicationContext);
16+
const { intervalID,example,setExample,setAppIndex,setApp,setServicesData,setChart } = useContext(ApplicationContext);
1717
// Extract isLoading and setLoading state from AwsContext. Initial value: isLoading = true
1818
const { isLoading, setLoadingState } = useContext(AwsContext);
1919
// clear interval and set loading state to true when leaving graph containers
20-
const { addApp } = useContext(DashboardContext);
20+
const { addApp,setApplications,deleteApp } = useContext(DashboardContext)
21+
2122
/**
2223
* @function handleCLick - check if the 'intervalID' exists. If so, theres a timer running and the fuunction clears the timer using @function clearInterval - function.
2324
* Checks if variable 'isLoading' is false and if so the content is not loading and therefore, sets it to true using the setLoadingState function.
@@ -28,17 +29,53 @@ const SidebarContainer = React.memo(() => {
2829
};
2930

3031
const handleExample = () => {
31-
setExample(true);
3232

33-
const fields = {
34-
typeOfService: 'Microservices',
35-
database: 'MongoDB',
36-
URI: 'mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5',
37-
name: 'Example',
38-
description: 'Microservices',
39-
};
40-
addApp(fields);
41-
};
33+
setExample(true)
34+
35+
const examplesData = {
36+
microServicesMongoFields: {
37+
typeOfService: 'Microservices',
38+
database: 'MongoDB',
39+
URI: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5",
40+
name: 'Microservices-Mongo',
41+
description: 'Mongo Microservices Example'
42+
},
43+
microServicesSQLFields: {
44+
typeOfService: 'Microservices',
45+
database: 'SQL',
46+
URI: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5",
47+
name: 'Microservices-SQL',
48+
description: 'SQL Microservices Example'
49+
}
50+
,
51+
dockerMongoData: {
52+
typeOfService: 'Docker',
53+
database: 'MongoDB',
54+
URI: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5",
55+
name: 'Docker-Mongo',
56+
description: 'Docker Example'
57+
},
58+
dockerSQLData: {
59+
typeOfService: 'Docker',
60+
database: 'SQL',
61+
URI: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5",
62+
name: 'Docker-SQL',
63+
description: 'Docker Example'
64+
}
65+
}
66+
67+
addApp(examplesData)
68+
}
69+
70+
const handleExitExample = () => {
71+
setExample(false)
72+
// setApplications([])
73+
setAppIndex(0);
74+
setApp('');
75+
setServicesData([]);
76+
setChart('communications')
77+
deleteApp(0,'all')
78+
}
4279

4380
return (
4481
<div className="sidebar-container" id="mySidebar">
@@ -99,9 +136,23 @@ const SidebarContainer = React.memo(() => {
99136
&emsp;Contact
100137
</Link>
101138
<Link className="sidebar-link" to="/" id="dash" onClick={handleClick}>
102-
<button className="example-button" onClick={() => handleExample()}>
103-
EXAMPLE
104-
</button>
139+
{!example ?
140+
141+
<button
142+
className="example-button"
143+
onClick={() => handleExample()}
144+
>
145+
EXAMPLE
146+
</button>
147+
:
148+
<button
149+
className="example-button"
150+
onClick={() => handleExitExample()}
151+
>
152+
EXIT EXAMPLE
153+
</button>
154+
155+
}
105156
</Link>
106157
</div>
107158
</div>

app/context/ApplicationContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
4141
// v10: Invoked by connectToDB, passing in app (card title)
4242
const fetchServicesNames = useCallback((application: string) => {
4343
// console.log('Hi, inside ApplicationConext - fetchServicesNames callback. Sending servicesRequest to ipcMain.');
44-
// console.log('app when fetch services name: ', application);
44+
console.log('app when fetch services name: ', application);
45+
console.log(application)
4546
ipcRenderer.send('servicesRequest');
4647
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
4748
//data here refers to the data coming the services document of the database

app/context/DashboardContext.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-console */
22
/* eslint-disable no-throw-literal */
33
import React, { useState, createContext, useCallback } from 'react';
4+
import { ApplicationContext } from './ApplicationContext';
45
const { ipcRenderer } = window.require('electron');
56

67
interface IFields {
@@ -27,6 +28,7 @@ interface AwsFields {
2728

2829
export const DashboardContext = createContext<any>(null);
2930

31+
3032
/**
3133
* MANAGES THE FOLLOWING DATA AND ACTIONS:
3234
* @property {Array} applications List of all applications, their description, database type and creation date
@@ -42,26 +44,29 @@ const DashboardContextProvider = React.memo((props: any) => {
4244
const children = props.children;
4345

4446
// Initial user will always be the guest
47+
4548
const [user, setUser] = useState<string>('guest');
4649
const [applications, setApplications] = useState<string[][]>([]);
47-
// console.log({applications})
50+
console.log({applications})
4851
const [mode, setMode] = useState<string>('light');
4952

50-
5153
const getApplications = useCallback(() => {
5254
const result = ipcRenderer.sendSync('getApps');
5355
setApplications(result);
5456
}, []);
5557

56-
const addApp = useCallback((fields: IFields) => {
57-
const { typeOfService, database, URI, name, description } = fields;
58+
const addApp = useCallback((fields: any) => {
59+
60+
for(let field of Object.keys(fields)) {
61+
const { typeOfService, database, URI, name, description } = fields[field];
62+
const result = ipcRenderer.sendSync(
63+
'addApp',
64+
JSON.stringify([name, database, URI, description, typeOfService])
65+
);
66+
setApplications(result);
67+
}
68+
5869

59-
const result = ipcRenderer.sendSync(
60-
'addApp',
61-
JSON.stringify([name, database, URI, description, typeOfService])
62-
);
63-
setApplications(result);
64-
// console.log('the current application that was added is : ', result);
6570
}, []);
6671

6772
const addAwsApp = useCallback((awsFields: AwsFields) => {
@@ -75,8 +80,8 @@ const DashboardContextProvider = React.memo((props: any) => {
7580
// console.log('the current application that was added is : ', result)
7681
}, []);
7782

78-
const deleteApp = useCallback((index: number) => {
79-
const result = ipcRenderer.sendSync('deleteApp', index);
83+
const deleteApp = useCallback((index: number,action:string) => {
84+
const result = ipcRenderer.sendSync('deleteApp', index,action);
8085
setApplications(result);
8186
}, []);
8287

app/modals/AddModal/AddModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface IFields {
1616
}
1717

1818
interface IDashboard {
19-
addApp: (fields: IFields) => void;
19+
addApp: (fields:any) => void;
2020
setApplications: any;
2121
}
2222

@@ -26,7 +26,7 @@ type FormElement = React.FormEvent<HTMLFormElement>;
2626
const AddModal: React.FC<TModalSetter> = React.memo(({ setModal }) => {
2727
const { addApp }: IDashboard = useContext(DashboardContext);
2828

29-
const [fields, setFields] = useState<IFields>({
29+
const [fields, setFields] = useState<any>({
3030
typeOfService: 'Docker',
3131
database: 'SQL',
3232
URI: '',
@@ -39,7 +39,7 @@ const AddModal: React.FC<TModalSetter> = React.memo(({ setModal }) => {
3939
event.preventDefault();
4040
// const newApp = [name, database, URI, description, typeOfService];
4141
// setApplications(prev => [...prev, ...newApp])
42-
addApp(fields);
42+
addApp({fields});
4343
setModal({isOpen:false,type:''})
4444
};
4545

0 commit comments

Comments
 (0)