Skip to content

Commit e2cb1be

Browse files
committed
pre push commit
1 parent 4c62f5b commit e2cb1be

2 files changed

Lines changed: 71 additions & 86 deletions

File tree

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,68 @@
1-
import React from 'react';
2-
import { Card, CardHeader, IconButton, CardContent, Typography } from "@mui/material";
1+
2+
import React, { useContext, useRef } from "react";
3+
import { useNavigate } from 'react-router-dom';
4+
import { Card,CardHeader,IconButton,CardContent,Typography } from "@mui/material";
5+
import { DashboardContext } from "../../context/DashboardContext";
6+
import { ApplicationContext } from "../../context/ApplicationContext";
37
import HighlightOffIcon from '@mui/icons-material/HighlightOff';
48
import UpdateIcon from '@mui/icons-material/Update';
5-
import { useEventHandlers } from './EventHandlers';
6-
import './styles.scss';
9+
import './styles.scss'
710

811
type ClickEvent = React.MouseEvent<HTMLElement>;
912

10-
interface ApplicationsCardProps {
11-
application: any[];
12-
i: number;
13-
setModal: (modalState: { isOpen: boolean; type: string }) => void;
14-
classes: any;
15-
}
13+
const ApplicationsCard = (props) => {
14+
15+
const { application, i, setModal, classes } = props
16+
const { deleteApp,user,applications } = useContext(DashboardContext)
17+
const { setAppIndex, setApp, setServicesData, app,example,connectToDB,setChart } = useContext(ApplicationContext)
18+
const [ cardName,dbType,dbURI,description,serviceType ] = application
19+
20+
//dynamic refs
21+
// const delRef = useRef<any>([]);
1622

17-
const ApplicationsCard: React.FC<ApplicationsCardProps> = ({ application, i, setModal, classes }) => {
18-
const { handleClick, confirmDelete } = useEventHandlers({ application, setModal });
23+
const navigate = useNavigate();
1924

20-
const [cardName, dbType, dbURI, serviceType, description] = application;
25+
// Handle clicks on Application cards
26+
// v10 info: when card is clicked (not on the delete button) if the service is an AWS instance,
27+
// you are redirected to AWSGraphsContainer passing in the state object containing typeOfService
28+
const handleClick = (
29+
selectedApp: string,
30+
selectedService: string,
31+
i: number
32+
) => {
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);
37+
if (
38+
selectedService === 'AWS' ||
39+
selectedService === 'AWS/EC2' ||
40+
selectedService === 'AWS/ECS' ||
41+
selectedService === 'AWS/EKS'
42+
) {
43+
navigate(`/aws/:${app}`, { state: { typeOfService: selectedService } });
44+
}
45+
else if(example) {
46+
setServicesData([]);
47+
setChart('communications')
48+
49+
connectToDB(user, i, app, dbURI, dbType)
50+
navigate(`/applications/example/${services.join(' ')}`)
51+
}
52+
else {
53+
setServicesData([]);
54+
//When we open the service modal a connection is made to the db in a useEffect inside of the service modal component
55+
setModal({isOpen:true,type:'serviceModal'})
56+
}
57+
// }
58+
};
59+
60+
// Asks user to confirm deletion
61+
const confirmDelete = (event: ClickEvent, i: number) => {
62+
event.stopPropagation()
63+
const message = `The application '${app}' will be permanently deleted. Continue?`;
64+
if (confirm(message)) deleteApp(i,"");
65+
};
2166

2267
return (
2368
<div className="card" key={`card-${i}`} id={`card-${application[1]}`}>
@@ -28,7 +73,8 @@ const ApplicationsCard: React.FC<ApplicationsCardProps> = ({ application, i, set
2873
onClick={() => handleClick(application[0], application[3], i)}
2974
>
3075
<div className="databaseIconContainer">
31-
<div className="databaseIconHeader"></div>
76+
<div className="databaseIconHeader">
77+
</div>
3278
</div>
3379

3480
<CardHeader
@@ -37,31 +83,33 @@ const ApplicationsCard: React.FC<ApplicationsCardProps> = ({ application, i, set
3783
id="iconButton"
3884
className={classes.iconbutton}
3985
aria-label="Delete"
40-
onClick={(event) => confirmDelete(event, i)}
41-
size="large"
42-
>
43-
<HighlightOffIcon className={classes.btnStyle} id="deleteIcon" />
86+
onClick={event => confirmDelete(event, i)}
87+
size="large">
88+
<HighlightOffIcon
89+
className={classes.btnStyle}
90+
id="deleteIcon"
91+
/>
4492
</IconButton>
4593
}
4694
/>
4795
<CardContent>
4896
<Typography noWrap id="databaseName" className={classes.fontStyles}>
49-
{cardName}
97+
{application[0]}
5098
</Typography>
5199
<p id="serviceName">Service:</p>
52-
<Typography className={classes.fontStyles}>{serviceType}</Typography>
100+
<Typography className={classes.fontStyles}>{application[3]}</Typography>
53101
</CardContent>
54102
<hr className="cardLine" />
55103

56104
<div className="cardFooter">
57105
<UpdateIcon className="cardFooterIcon" />
58106
<em>
59-
<p id="cardFooterText">{description}</p>
107+
<p id="cardFooterText">{application[4]}</p>
60108
</em>
61109
</div>
62110
</Card>
63111
</div>
64112
);
65-
};
113+
}
66114

67-
export default ApplicationsCard;
115+
export default ApplicationsCard

app/components/GraphNavBar/useGraphNavBar.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)