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' ;
7
3
import HighlightOffIcon from '@mui/icons-material/HighlightOff' ;
8
4
import 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
19
-
20
- //dynamic refs
21
- // const delRef = useRef<any>([]);
5
+ import './styles.scss' ;
6
+ import { getEventHandlers } from './EventHandlers' ;
22
7
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' )
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
- } ;
8
+ interface ApplicationCardProps {
9
+ application : any [ ] ;
10
+ i : number ;
11
+ setModal : ( modalState : { isOpen : boolean ; type : string } ) => void ;
12
+ classes : any ;
13
+ }
59
14
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
- } ;
15
+ const ApplicationsCard : React . FC < ApplicationCardProps > = ( props : ApplicationCardProps ) => {
16
+ const { application, i, setModal, classes } = props ;
17
+ const { handleClick, confirmDelete } = getEventHandlers ( { application, setModal } ) ;
66
18
67
19
return (
68
20
< div className = "card" key = { `card-${ i } ` } id = { `card-${ application [ 1 ] } ` } >
@@ -73,8 +25,7 @@ const ApplicationsCard = (props) => {
73
25
onClick = { ( ) => handleClick ( application [ 0 ] , application [ 3 ] , i ) }
74
26
>
75
27
< div className = "databaseIconContainer" >
76
- < div className = "databaseIconHeader" >
77
- </ div >
28
+ < div className = "databaseIconHeader" > </ div >
78
29
</ div >
79
30
80
31
< CardHeader
@@ -84,11 +35,9 @@ const ApplicationsCard = (props) => {
84
35
className = { classes . iconbutton }
85
36
aria-label = "Delete"
86
37
onClick = { event => confirmDelete ( event , i ) }
87
- size = "large" >
88
- < HighlightOffIcon
89
- className = { classes . btnStyle }
90
- id = "deleteIcon"
91
- />
38
+ size = "large"
39
+ >
40
+ < HighlightOffIcon className = { classes . btnStyle } id = "deleteIcon" />
92
41
</ IconButton >
93
42
}
94
43
/>
@@ -110,6 +59,6 @@ const ApplicationsCard = (props) => {
110
59
</ Card >
111
60
</ div >
112
61
) ;
113
- }
62
+ } ;
114
63
115
- export default ApplicationsCard
64
+ export default ApplicationsCard ;
0 commit comments