1
- import React , { useContext } from 'react' ;
2
- import StateContext from "../../../context/context" ;
1
+ import React , { useContext } from 'react' ;
3
2
import Table from '@mui/material/Table' ;
4
3
import TableBody from '@mui/material/TableBody' ;
5
4
import TableContainer from '@mui/material/TableContainer' ;
@@ -8,100 +7,103 @@ import TableRow from '@mui/material/TableRow';
8
7
import Paper from '@mui/material/Paper' ;
9
8
import { styled } from '@mui/material/styles' ;
10
9
import TableCell , { tableCellClasses } from '@mui/material/TableCell' ;
10
+ import StateContext from '../../../context/context' ;
11
11
12
12
const StyledTableCell = styled ( TableCell ) ( ( { theme } ) => ( {
13
13
[ `&.${ tableCellClasses . head } ` ] : {
14
14
backgroundColor : theme . palette . common . black ,
15
- color : theme . palette . common . white
15
+ color : theme . palette . common . white ,
16
16
} ,
17
17
[ `&.${ tableCellClasses . body } ` ] : {
18
- fontSize : 14
19
- }
18
+ fontSize : 14 ,
19
+ } ,
20
20
} ) ) ;
21
21
22
22
const StyledTableRow = styled ( TableRow ) ( ( { theme } ) => ( {
23
23
'&:nth-of-type(odd)' : {
24
- backgroundColor : theme . palette . action . hover
24
+ backgroundColor : theme . palette . action . hover ,
25
25
} ,
26
26
// hide last border
27
27
'&:last-child td, &:last-child th' : {
28
- border : 0
29
- }
28
+ border : 0 ,
29
+ } ,
30
30
} ) ) ;
31
31
32
32
export default function DataTable ( props ) {
33
- const { currComponentState, parentProps, clickedComp, data } = props ;
33
+ const {
34
+ currComponentState, parentProps, clickedComp, data,
35
+ } = props ;
34
36
const [ state , dispatch ] = useContext ( StateContext ) ;
35
37
36
- //determine if the current component is a root component
38
+ // determine if the current component is a root component
37
39
let isRoot = false ;
38
40
39
41
for ( let i = 0 ; i < data . length ; i ++ ) {
40
- if ( data [ i ] [ ' name' ] === clickedComp ) {
41
- if ( state . rootComponents . includes ( data [ i ] [ 'id' ] ) ) isRoot = true ;
42
+ if ( data [ i ] . name === clickedComp ) {
43
+ if ( state . rootComponents . includes ( data [ i ] . id ) ) isRoot = true ;
42
44
}
43
45
}
44
-
46
+
45
47
return (
46
- < >
47
- < TableContainer component = { Paper } sx = { { maxHeight : '350px' } } >
48
- < Table
49
- sx = { { width : '510px' } }
50
- aria-label = "customized table"
51
- stickyHeader
52
- >
53
-
54
- { /* we are checking if the clicked component is a root component-- if yes, it doesn't have any parents so don't need passed-in props table*/ }
55
- { ( ! isRoot &&
56
- < >
57
- < TableHead >
58
- < TableRow >
59
- < StyledTableCell align = "center" colSpan = { 3 } >
60
- { 'Props Passed in from Parent:' }
61
- </ StyledTableCell >
62
- </ TableRow >
63
- </ TableHead >
64
- < TableBody >
48
+ < TableContainer component = { Paper } sx = { { maxHeight : '350px' } } >
49
+ < Table
50
+ sx = { { width : '510px' } }
51
+ aria-label = "customized table"
52
+ stickyHeader
53
+ >
54
+
55
+ { /* we are checking if the clicked component is a root component-- if yes, it doesn't have any parents so don't need passed-in props table */ }
56
+ { ( ! isRoot
57
+ && (
58
+ < >
59
+ < TableHead >
60
+ < TableRow >
61
+ < StyledTableCell align = "center" colSpan = { 3 } >
62
+ Props Passed in from Parent:
63
+ </ StyledTableCell >
64
+ </ TableRow >
65
+ </ TableHead >
66
+ < TableBody >
67
+ < StyledTableRow >
68
+ < StyledTableCell component = "th" scope = "row" > < b > Key</ b > </ StyledTableCell >
69
+ < StyledTableCell align = "right" > < b > Type</ b > </ StyledTableCell >
70
+ < StyledTableCell align = "right" > < b > Initial Value</ b > </ StyledTableCell >
71
+ </ StyledTableRow >
72
+ { parentProps ? parentProps . map ( ( data , index ) => (
73
+ < StyledTableRow key = { index } >
74
+ < StyledTableCell component = "th" scope = "row" > { data . key } </ StyledTableCell >
75
+ < StyledTableCell align = "right" > { data . type } </ StyledTableCell >
76
+ < StyledTableCell align = "right" > { data . value } </ StyledTableCell >
77
+ </ StyledTableRow >
78
+ ) ) : '' }
79
+ </ TableBody >
80
+ </ >
81
+ )
82
+ ) }
83
+
84
+ { /* The below table will contain the state initialized within the clicked component */ }
85
+ < TableHead >
86
+ < TableRow >
87
+ < StyledTableCell align = "center" colSpan = { 3 } >
88
+ State Initialized in Current Component:
89
+ </ StyledTableCell >
90
+ </ TableRow >
91
+ </ TableHead >
92
+ < TableBody >
65
93
< StyledTableRow >
66
- < StyledTableCell component = "th" scope = "row" > < b > Key</ b > </ StyledTableCell >
67
- < StyledTableCell align = "right" > < b > Type</ b > </ StyledTableCell >
68
- < StyledTableCell align = "right" > < b > Initial Value</ b > </ StyledTableCell >
94
+ < StyledTableCell component = "th" scope = "row" > < b > Key</ b > </ StyledTableCell >
95
+ < StyledTableCell align = "right" > < b > Type</ b > </ StyledTableCell >
96
+ < StyledTableCell align = "right" > < b > Initial Value</ b > </ StyledTableCell >
69
97
</ StyledTableRow >
70
- { parentProps ? parentProps . map ( ( data , index ) => (
98
+ { currComponentState ? currComponentState . map ( ( data , index ) => (
71
99
< StyledTableRow key = { index } >
72
100
< StyledTableCell component = "th" scope = "row" > { data . key } </ StyledTableCell >
73
101
< StyledTableCell align = "right" > { data . type } </ StyledTableCell >
74
102
< StyledTableCell align = "right" > { data . value } </ StyledTableCell >
75
103
</ StyledTableRow >
76
- ) ) : '' }
104
+ ) ) : '' }
77
105
</ TableBody >
78
- </ >
79
- ) }
80
-
81
- { /* The below table will contain the state initialized within the clicked component */ }
82
- < TableHead >
83
- < TableRow >
84
- < StyledTableCell align = "center" colSpan = { 3 } >
85
- { 'State Initialized in Current Component:' }
86
- </ StyledTableCell >
87
- </ TableRow >
88
- </ TableHead >
89
- < TableBody >
90
- < StyledTableRow >
91
- < StyledTableCell component = "th" scope = "row" > < b > Key</ b > </ StyledTableCell >
92
- < StyledTableCell align = "right" > < b > Type</ b > </ StyledTableCell >
93
- < StyledTableCell align = "right" > < b > Initial Value</ b > </ StyledTableCell >
94
- </ StyledTableRow >
95
- { currComponentState ? currComponentState . map ( ( data , index ) => (
96
- < StyledTableRow key = { index } >
97
- < StyledTableCell component = "th" scope = "row" > { data . key } </ StyledTableCell >
98
- < StyledTableCell align = "right" > { data . type } </ StyledTableCell >
99
- < StyledTableCell align = "right" > { data . value } </ StyledTableCell >
100
- </ StyledTableRow >
101
- ) ) : '' }
102
- </ TableBody >
103
- </ Table >
104
- </ TableContainer >
105
- </ >
106
+ </ Table >
107
+ </ TableContainer >
106
108
) ;
107
109
}
0 commit comments