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, applications } = 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- //dynamic refs
21- // const delRef = useRef<any>([]);
22-
23- const navigate = useNavigate ( ) ;
9+ interface ApplicationCardProps {
10+ application : any [ ] ;
11+ i : number ;
12+ setModal : ( modalState : { isOpen : boolean ; type : string } ) => void ;
13+ classes : any ;
14+ }
2415
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' )
16+ import './styles.scss'
4817
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- } ;
18+ const ApplicationsCard :React . FC < ApplicationCardProps > = ( props ) => {
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 { application, i, setModal, classes } = props
21+ const { handleClick, confirmDelete } = getEventHandlers ( { application, setModal } ) ;
6622
6723 return (
6824 < div className = "card" key = { `card-${ i } ` } id = { `card-${ application [ 1 ] } ` } >
@@ -73,8 +29,7 @@ const ApplicationsCard = (props) => {
7329 onClick = { ( ) => handleClick ( application [ 0 ] , application [ 3 ] , i ) }
7430 >
7531 < div className = "databaseIconContainer" >
76- < div className = "databaseIconHeader" >
77- </ div >
32+ < div className = "databaseIconHeader" > </ div >
7833 </ div >
7934
8035 < CardHeader
@@ -84,11 +39,9 @@ const ApplicationsCard = (props) => {
8439 className = { classes . iconbutton }
8540 aria-label = "Delete"
8641 onClick = { event => confirmDelete ( event , i ) }
87- size = "large" >
88- < HighlightOffIcon
89- className = { classes . btnStyle }
90- id = "deleteIcon"
91- />
42+ size = "large"
43+ >
44+ < HighlightOffIcon className = { classes . btnStyle } id = "deleteIcon" />
9245 </ IconButton >
9346 }
9447 />
@@ -110,6 +63,6 @@ const ApplicationsCard = (props) => {
11063 </ Card >
11164 </ div >
11265 ) ;
113- }
66+ } ;
11467
115- export default ApplicationsCard
68+ export default ApplicationsCard ;
0 commit comments