Skip to content

Commit a60cd78

Browse files
committed
Exit example implemented
Clicking example now populates cards that are not wrapped in a link component. This allows the app to work the traditional way and with our example button. useNavigate hook was used in appplication card component to facilitate. Users can now also click exit example button to reset all states and use the app the traditional way.
1 parent a410461 commit a60cd78

13 files changed

Lines changed: 76 additions & 37 deletions

File tree

app/components/ApplicationsCard/ApplicationsCard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const ApplicationsCard = (props) => {
3131
selectedService: string,
3232
i: number
3333
) => {
34+
const services = ['auth','client','event-bus','items','inventory','orders']
3435
//delRef refers to the delete button
3536
if (delRef.current[i] && !delRef.current[i].contains(event.target)) {
3637
if (
@@ -50,6 +51,7 @@ const ApplicationsCard = (props) => {
5051
setChart('communications')
5152

5253
connectToDB(user, i, app, dbURI, dbType)
54+
navigate(`/applications/example/${services.join(' ')}`)
5355
}
5456
else {
5557
setAppIndex(i);

app/components/Occupied/Occupied.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { Link } from 'react-router-dom';
3838

3939
//v10: Memoized function, without any props. Should theoretically be called only once.
4040
const Occupied = React.memo(() => {
41-
const { setServicesData, app,example } = useContext(ApplicationContext);
41+
const { setServicesData, app, example } = useContext(ApplicationContext);
4242
const { user, applications, getApplications, mode } = useContext(DashboardContext);
4343
const [ modal,setModal ] = useState({isOpen:false,type:''})
4444
const { appIndex } = useContext(ApplicationContext);
@@ -74,7 +74,7 @@ const Occupied = React.memo(() => {
7474
<div
7575
className="cardContainer"
7676
>
77-
77+
{!example &&
7878
<div
7979
className="card"
8080
id="card-add"
@@ -88,26 +88,22 @@ const Occupied = React.memo(() => {
8888
/>
8989
</Button>
9090
</div>
91+
}
9192

9293
{applications
9394
.filter((db: any) => db[0].toLowerCase().includes(searchTerm.toLowerCase()))
9495
.map((application: string[], i: any) => {
95-
const services = ['auth','client','event-bus','items','inventory','orders']
96-
console.log({app,services})
96+
const description = application[3]
97+
if(!example && description === "Example") return <></>
9798
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-
})}
99+
<ApplicationsCard
100+
key={crypto.randomUUID()}
101+
application={application}
102+
i={i}
103+
setModal={setModal}
104+
classes={classes}
105+
/>
106+
)})}
111107

112108
<Modal
113109
open={modal.isOpen}

app/containers/SidebarContainer.tsx

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import { DashboardContext } from '../context/DashboardContext';
1414
const SidebarContainer = React.memo(() => {
1515

1616
// Extract invervalID from ApplicationContext. Initival value: intervalID = null
17-
const { intervalID,setExample } = useContext(ApplicationContext);
17+
const { intervalID,example,setExample,setAppIndex,setApp,setServicesData,setChart } = useContext(ApplicationContext);
1818
// Extract isLoading and setLoading state from AwsContext. Initial value: isLoading = true
1919
const { isLoading, setLoadingState } = useContext(AwsContext);
2020
// clear interval and set loading state to true when leaving graph containers
21-
const { addApp } = useContext(DashboardContext)
21+
const { addApp,setApplications } = useContext(DashboardContext)
2222
/**
2323
* @function handleCLick - check if the 'intervalID' exists. If so, theres a timer running and the fuunction clears the timer using @function clearInterval - function.
2424
* Checks if variable 'isLoading' is false and if so the content is not loading and therefore, sets it to true using the setLoadingState function.
@@ -31,18 +31,46 @@ const SidebarContainer = React.memo(() => {
3131
const handleExample = () => {
3232

3333
setExample(true)
34+
35+
// const examplesData = {
36+
// microServicesFields: {
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',
41+
// description: 'Example'
42+
// },
43+
44+
// ,
45+
// dockerData: {
46+
// typeOfService: 'Docker',
47+
// database: 'MongoDB',
48+
// URI: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5",
49+
// name: 'Docker',
50+
// description: 'Example'
51+
// }
52+
// }
3453

3554
const fields = {
3655
typeOfService: 'Microservices',
3756
database: 'MongoDB',
3857
URI: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5",
39-
name: 'Example',
40-
description: 'Microservices'
58+
name: 'Microservices',
59+
description: 'Example'
4160
}
4261

4362
addApp(fields)
4463
}
4564

65+
const handleExitExample = () => {
66+
setExample(false)
67+
setApplications([])
68+
setAppIndex(0);
69+
setApp('');
70+
setServicesData([]);
71+
setChart('communications')
72+
}
73+
4674
return (
4775
<div className="sidebar-container" id="mySidebar">
4876
<div className="sidebar">
@@ -102,13 +130,25 @@ const SidebarContainer = React.memo(() => {
102130
&emsp;Contact
103131
</Link>
104132
<Link className="sidebar-link" to="/" id="dash" onClick={handleClick}>
105-
<button
106-
className="example-button"
107-
onClick={() => handleExample()}
108-
>
109-
EXAMPLE
110-
</button>
133+
{!example ?
134+
135+
<button
136+
className="example-button"
137+
onClick={() => handleExample()}
138+
>
139+
EXAMPLE
140+
</button>
141+
:
142+
<button
143+
className="example-button"
144+
onClick={() => handleExitExample()}
145+
>
146+
EXIT EXAMPLE
147+
</button>
148+
149+
}
111150
</Link>
151+
112152

113153
</div>
114154
</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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const DashboardContextProvider = React.memo((props: any) => {
6464
JSON.stringify([name, database, URI, description, typeOfService])
6565
);
6666
setApplications(result);
67-
console.log({result})
67+
// console.log({result})
6868
// console.log('the current application that was added is : ', result);
6969
}, []);
7070

examples/docker/auth/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ chronos.docker();
1919
app.use(
2020
cors({
2121
credentials: true,
22-
origin: 'http://localhost:5000',
22+
origin: 'http://localhost:5001',
2323
})
2424
);
2525
app.use(express.json());

examples/docker/inventory/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ chronos.docker();
1919
app.use(
2020
cors({
2121
credentials: true,
22-
origin: 'http://localhost:5000',
22+
origin: 'http://localhost:5001',
2323
})
2424
);
2525
app.use(express.json());

examples/docker/items/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ chronos.docker();
1919
app.use(
2020
cors({
2121
credentials: true,
22-
origin: 'http://localhost:5000',
22+
origin: 'http://localhost:5001',
2323
})
2424
);
2525
app.use(express.json());

examples/docker/orders/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ chronos.docker();
1919
app.use(
2020
cors({
2121
credentials: true,
22-
origin: 'http://localhost:5000',
22+
origin: 'http://localhost:5001',
2323
})
2424
);
2525

examples/microservices/auth/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ app.use(trackingMiddleware);
1919
app.use(
2020
cors({
2121
credentials: true,
22-
origin: 'http://localhost:5000',
22+
origin: 'http://localhost:5001',
2323
})
2424
);
2525
app.use(express.json());

0 commit comments

Comments
 (0)