1
1
import React , { Component } from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
+ import { ComponentInt , ApplicationStateInt } from '../../interfaces/Interfaces' ;
3
4
import { addProp , deleteProp } from '../../actions/actionCreators' ;
4
5
import MaterialTable from 'material-table' ;
5
6
6
- const mapDispatchToProps = ( dispatch : any ) => ( {
7
- addProp : ( {
8
- key,
9
- value,
10
- required,
11
- type
12
- } : {
13
- key : string ;
14
- value : string ;
15
- required : boolean ;
16
- type : string ;
17
- } ) =>
18
- dispatch (
19
- addProp ( {
20
- key,
21
- value,
22
- required,
23
- type
24
- } )
25
- ) ,
26
- deleteProp : ( propId : number ) => dispatch ( deleteProp ( propId ) )
27
- } ) ;
28
-
29
- const mapStateToProps = ( store : any ) => ( {
7
+ const mapStateToProps = ( store : { workspace : ApplicationStateInt } ) => ( {
30
8
focusComponent : store . workspace . focusComponent
31
9
} ) ;
32
10
33
- class AddChildProps extends Component {
34
- tableRef = React . createRef ( ) ;
35
- // state = {
36
- // propVariables: '',
37
- // propValue: '',
38
- // propRequired: true,
39
- // propType: ''
40
- // };
41
-
42
- // handleChange = (event: MouseEvent | any) => {
43
- // if (event.target.id === 'propVariable') {
44
- // this.setState({
45
- // [event.target.id]: event.target.value.trim()
46
- // });
47
- // } else {
48
- // this.setState({
49
- // [event.target.id]: event.target.value
50
- // });
51
- // }
52
- // };
53
-
54
- // togglePropRequired = () => {
55
- // this.setState({
56
- // propRequired: !this.state.propRequired
57
- // });
58
- // };
59
-
60
- // function that handles the addition of props to a given componnent
61
- // added regex to strip usr input from non alpha numeric properties
62
- // presence of these characters crashes the app and should not be a valid input anyways
63
- // handleAddProp = (event: MouseEvent) => {
64
- // event.preventDefault();
65
-
66
- // // destructuring from local state
67
- // // if change here, make sure to change local state props to match
68
- // let { propVariable, propValue, propRequired, propType } = this.state;
69
- // propVariable = propVariable.replace(/[!@#$%^&*,./:;"]+\s/gi, '');
70
- // propValue = propValue.replace(/[!@#$%^&*,./:;'"]+\s/gi, '');
71
-
72
- // // check if prop exists with same key. CANNOT have duplicates
73
- // const savedVariableKeys = this.props.focusComponent.props.map(
74
- // prop => prop.key
75
- // );
76
- // if (savedVariableKeys.includes(propVariable)) {
77
- // window.alert(`A prop with the name: "${propVariable}" already exists.`);
78
- // return;
79
- // }
80
-
81
- // // check if prop starts with digits. Digits at string start breaks indexedDB
82
- // if (/^\d/.test(propVariable)) {
83
- // window.alert('Props are not allowed to begin with digits');
84
- // return;
85
- // }
86
-
87
- // this.props.addProp({
88
- // key: propVariable,
89
- // value: propValue,
90
- // required: propRequired,
91
- // type: propType
92
- // });
11
+ // JZ: created interface to define the props that are being passed into this component
12
+ interface ChildPropsTypes {
13
+ focusComponent : ComponentInt ;
14
+ // classes?: any; -- not possibly needed, also removed from prop deconstruction
15
+ }
93
16
94
- // this.setState({
95
- // propVariable: '',
96
- // propValue: '',
97
- // propRequired: true,
98
- // propType: ''
99
- // });
100
- // };
17
+ class AddChildProps extends Component < ChildPropsTypes > {
18
+ tableRef = React . createRef ( ) ;
101
19
render ( ) {
102
- const { focusComponent, classes , deleteProp , addProp } = this . props ;
20
+ const { focusComponent } = this . props ;
103
21
104
22
// Array to be used to populate HTML form elements
105
- const arrayPropsAvailable = [ ] ;
106
-
107
- // IIFE : so that it runs without needing to be invoked
108
- ( ( ) => {
109
- focusComponent . props . map ( prop => {
110
- // console.log('this is component Name from props array', prop.key);
111
- arrayPropsAvailable . push (
112
- < span >
113
- < input
114
- type = 'checkbox'
115
- id = { `${ prop } checkbox-${ prop . key } ` }
116
- name = { `${ prop } checkbox-${ prop . key } ` }
117
- />
118
- < label
119
- className = { `labelForPropsToAddToChild` }
120
- for = { `${ prop } checkbox-${ prop . key } ` }
121
- >
122
- { prop . key }
123
- </ label >
124
- </ span >
125
- ) ;
126
- } ) ;
127
- } ) ( ) ;
128
-
129
- console . log ( 'this is the array of props available' , arrayPropsAvailable ) ;
23
+ // JZ: refactored this code to the above to be all done within one map function
24
+ const arrayPropsAvailable = focusComponent . props . map ( ( prop , idx ) => {
25
+ return (
26
+ < span key = { `span-${ idx } ` } >
27
+ < input
28
+ type = 'checkbox'
29
+ id = { `${ prop } checkbox-${ prop . key } ` }
30
+ name = { `${ prop } checkbox-${ prop . key } ` }
31
+ key = { `checkbox-${ idx } ` }
32
+ />
33
+ < label
34
+ className = { `labelForPropsToAddToChild` }
35
+ htmlFor = { `${ prop } checkbox-${ prop . key } ` }
36
+ key = { `label-${ idx } ` }
37
+ >
38
+ { prop . key }
39
+ </ label >
40
+ </ span >
41
+ ) ;
42
+ } ) ;
43
+
44
+ // const arrayPropsAvailable = [];
45
+ // // IIFE : so that it runs without needing to be invoked
46
+ // (() => {
47
+ // focusComponent.props.map(prop => {
48
+ // // console.log('this is component Name from props array', prop.key);
49
+ // arrayPropsAvailable.push(
50
+ // <span>
51
+ // <input
52
+ // type='checkbox'
53
+ // id={`${prop}checkbox-${prop.key}`}
54
+ // name={`${prop}checkbox-${prop.key}`}
55
+ // />
56
+ // <label
57
+ // className={`labelForPropsToAddToChild`}
58
+ // for={`${prop}checkbox-${prop.key}`}
59
+ // >
60
+ // {prop.key}
61
+ // </label>
62
+ // </span>
63
+ // );
64
+ // });
65
+ // })();
66
+ // console.log('this is the array of props available', arrayPropsAvailable);
130
67
131
68
return (
132
69
< div >
@@ -152,16 +89,17 @@ class AddChildProps extends Component {
152
89
title = 'Add Your Child Props Here!'
153
90
/>
154
91
92
+ { /* BUTTON FUNCTIONALITY PENDING
155
93
<button
156
94
onClick={() => {
157
95
this.tableRef.current.onQueryChange();
158
96
}}
159
97
>
160
98
Sean Sucks
161
- </ button >
99
+ </button> */ }
162
100
</ div >
163
101
) ;
164
102
}
165
103
}
166
104
167
- export default connect ( mapStateToProps , mapDispatchToProps ) ( AddChildProps ) ;
105
+ export default connect ( mapStateToProps ) ( AddChildProps ) ;
0 commit comments