11
2- import React , { useContext , useRef } from "react" ;
3- import { useNavigate } from 'react-router-dom' ;
2+ import React from "react" ;
43import { Card , CardHeader , IconButton , CardContent , Typography } from "@mui/material" ;
5- import { DashboardContext } from "../../context/DashboardContext" ;
6- import { ApplicationContext } from "../../context/ApplicationContext" ;
74import HighlightOffIcon from '@mui/icons-material/HighlightOff' ;
85import UpdateIcon from '@mui/icons-material/Update' ;
9- import './styles.scss'
10-
11- type ClickEvent = React . MouseEvent < HTMLElement > ;
12-
13- const ApplicationsCard = ( props ) => {
14-
15- const { application, i, setModal, classes } = props
16- const { deleteApp, user } = useContext ( DashboardContext )
17- const { setAppIndex, setApp, setServicesData, app, example, connectToDB, setChart } = useContext ( ApplicationContext )
18- const [ cardName , dbType , dbURI , description , serviceType ] = application
6+ import './styles.scss' ;
7+ import { getEventHandlers } from './EventHandlers' ;
198
20- const navigate = useNavigate ( ) ;
9+ interface ApplicationCardProps {
10+ application : any [ ] ;
11+ i : number ;
12+ setModal : ( modalState : { isOpen : boolean ; type : string } ) => void ;
13+ classes : any ;
14+ }
2115
22- // Handle clicks on Application cards
23- // v10 info: when card is clicked (not on the delete button) if the service is an AWS instance,
24- // you are redirected to AWSGraphsContainer passing in the state object containing typeOfService
25- const handleClick = (
26- selectedApp : string ,
27- selectedService : string ,
28- i : number
29- ) => {
30- const services = [ 'auth' , 'client' , 'event-bus' , 'items' , 'inventory' , 'orders' ]
31- // if (delRef.current[i] && !delRef.current[i].contains(event.target)) {
32- setAppIndex ( i ) ;
33- setApp ( selectedApp ) ;
34- if (
35- selectedService === 'AWS' ||
36- selectedService === 'AWS/EC2' ||
37- selectedService === 'AWS/ECS' ||
38- selectedService === 'AWS/EKS'
39- ) {
40- navigate ( `/aws/:${ app } ` , { state : { typeOfService : selectedService } } ) ;
41- }
42- else if ( example ) {
43- setServicesData ( [ ] ) ;
44- setChart ( 'all' )
16+ import './styles.scss'
4517
46- connectToDB ( user , i , app , dbURI , dbType )
47- navigate ( `/applications/example/${ services . join ( ' ' ) } ` )
48- }
49- else {
50- setServicesData ( [ ] ) ;
51- //When we open the service modal a connection is made to the db in a useEffect inside of the service modal component
52- setModal ( { isOpen :true , type :'serviceModal' } )
53- }
54- // }
55- } ;
18+ const ApplicationsCard :React . FC < ApplicationCardProps > = ( props ) => {
5619
57- // Asks user to confirm deletion
58- const confirmDelete = ( event : ClickEvent , i : number ) => {
59- event . stopPropagation ( )
60- const message = `The application '${ app } ' will be permanently deleted. Continue?` ;
61- if ( confirm ( message ) ) deleteApp ( i , "" ) ;
62- } ;
20+ const { application, i, setModal, classes } = props
21+ const { handleClick, confirmDelete } = getEventHandlers ( { application, setModal } ) ;
6322
6423 return (
6524 < div className = "card" key = { `card-${ i } ` } id = { `card-${ application [ 1 ] } ` } >
@@ -70,8 +29,7 @@ const ApplicationsCard = (props) => {
7029 onClick = { ( ) => handleClick ( application [ 0 ] , application [ 3 ] , i ) }
7130 >
7231 < div className = "databaseIconContainer" >
73- < div className = "databaseIconHeader" >
74- </ div >
32+ < div className = "databaseIconHeader" > </ div >
7533 </ div >
7634
7735 < CardHeader
@@ -81,11 +39,9 @@ const ApplicationsCard = (props) => {
8139 className = { classes . iconbutton }
8240 aria-label = "Delete"
8341 onClick = { event => confirmDelete ( event , i ) }
84- size = "large" >
85- < HighlightOffIcon
86- className = { classes . btnStyle }
87- id = "deleteIcon"
88- />
42+ size = "large"
43+ >
44+ < HighlightOffIcon className = { classes . btnStyle } id = "deleteIcon" />
8945 </ IconButton >
9046 }
9147 />
@@ -107,6 +63,6 @@ const ApplicationsCard = (props) => {
10763 </ Card >
10864 </ div >
10965 ) ;
110- }
66+ } ;
11167
112- export default ApplicationsCard
68+ export default ApplicationsCard ;
0 commit comments