Skip to content

Commit 2087549

Browse files
committed
updated ApplicationCard, functioning
1 parent 73895c5 commit 2087549

1 file changed

Lines changed: 23 additions & 71 deletions

File tree

Lines changed: 23 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,23 @@
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";
1+
import React from 'react';
2+
import { Card, CardHeader, IconButton, CardContent, Typography } from "@mui/material";
73
import HighlightOffIcon from '@mui/icons-material/HighlightOff';
84
import UpdateIcon from '@mui/icons-material/Update';
9-
import './styles.scss'
5+
import { useEventHandlers } from './EventHandlers';
6+
import './styles.scss';
107

118
type ClickEvent = React.MouseEvent<HTMLElement>;
129

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>([]);
22-
23-
const navigate = useNavigate();
24-
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')
10+
interface ApplicationsCardProps {
11+
application: any[];
12+
i: number;
13+
setModal: (modalState: { isOpen: boolean; type: string }) => void;
14+
classes: any;
15+
}
4816

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-
};
17+
const ApplicationsCard: React.FC<ApplicationsCardProps> = ({ application, i, setModal, classes }) => {
18+
const { handleClick, confirmDelete } = useEventHandlers({ application, setModal });
5919

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-
};
20+
const [cardName, dbType, dbURI, serviceType, description] = application;
6621

6722
return (
6823
<div className="card" key={`card-${i}`} id={`card-${application[1]}`}>
@@ -73,8 +28,7 @@ const ApplicationsCard = (props) => {
7328
onClick={() => handleClick(application[0], application[3], i)}
7429
>
7530
<div className="databaseIconContainer">
76-
<div className="databaseIconHeader">
77-
</div>
31+
<div className="databaseIconHeader"></div>
7832
</div>
7933

8034
<CardHeader
@@ -83,33 +37,31 @@ const ApplicationsCard = (props) => {
8337
id="iconButton"
8438
className={classes.iconbutton}
8539
aria-label="Delete"
86-
onClick={event => confirmDelete(event, i)}
87-
size="large">
88-
<HighlightOffIcon
89-
className={classes.btnStyle}
90-
id="deleteIcon"
91-
/>
40+
onClick={(event) => confirmDelete(event, i)}
41+
size="large"
42+
>
43+
<HighlightOffIcon className={classes.btnStyle} id="deleteIcon" />
9244
</IconButton>
9345
}
9446
/>
9547
<CardContent>
9648
<Typography noWrap id="databaseName" className={classes.fontStyles}>
97-
{application[0]}
49+
{cardName}
9850
</Typography>
9951
<p id="serviceName">Service:</p>
100-
<Typography className={classes.fontStyles}>{application[3]}</Typography>
52+
<Typography className={classes.fontStyles}>{serviceType}</Typography>
10153
</CardContent>
10254
<hr className="cardLine" />
10355

10456
<div className="cardFooter">
10557
<UpdateIcon className="cardFooterIcon" />
10658
<em>
107-
<p id="cardFooterText">{application[4]}</p>
59+
<p id="cardFooterText">{description}</p>
10860
</em>
10961
</div>
11062
</Card>
11163
</div>
11264
);
113-
}
65+
};
11466

115-
export default ApplicationsCard
67+
export default ApplicationsCard;

0 commit comments

Comments
 (0)