Skip to content

Commit fae7feb

Browse files
committed
Updating prop-types on all components
1 parent 9cbe0e9 commit fae7feb

File tree

10 files changed

+198
-60
lines changed

10 files changed

+198
-60
lines changed

app/CLAgg/ReadConfig.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public function getFieldsArray()
110110

111111
unset($array['argId']);
112112
unset($array['argKey']);
113-
unset($array['argName']);
114113
unset($array['argTitle']);
115114

116115
$array['checkbox'] = array(

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"devDependencies": {
1414
"axios": "^0.18",
1515
"babel-core": "^6.26.3",
16-
"babel-preset-react": "^6.23.0",
17-
"babel-preset-react-app": "^3.1.2",
1816
"babel-loader": "^7.1.5",
1917
"babel-plugin-dynamic-import-webpack": "^1.0.2",
18+
"babel-preset-react": "^6.23.0",
19+
"babel-preset-react-app": "^3.1.2",
2020
"babel-runtime": "^6.26.0",
2121
"bootstrap": "^4.0.0",
2222
"classnames": "^2.2.6",
@@ -37,6 +37,7 @@
3737
"styled-components": "^3.3.3"
3838
},
3939
"dependencies": {
40+
"prop-types": "^15.6.2"
4041
},
4142
"babel": {
4243
"presets": [

resources/assets/js/components/navigation/Areas/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,30 @@ class Areas extends Component {
3333
};
3434

3535
getSelectedAreas = () => {
36-
return filter(this.props.area_list, (area)=>area.selected === true);
36+
return Object.entries(this.props.area_list)
37+
.filter(([key, area])=>{
38+
return area.selected === true;
39+
})
40+
.reduce((collector, [key, area])=>{
41+
collector[area.partial] = area;
42+
return collector;
43+
},{});
3744
};
3845

3946
getTotalSelectedAreas = () => {
40-
let selected = filter(this.props.area_list, (area)=>area.selected === true);
41-
return Object.keys(selected).length;
47+
return Object.entries(this.props.area_list)
48+
.filter(([key, area])=>area.selected === true).length;
4249
};
4350

4451
getUnselectedAreas = () => {
45-
return filter(this.props.area_list, (area)=>area.selected !== true);
52+
return Object.entries(this.props.area_list)
53+
.filter(([key, area])=>{
54+
return area.selected !== true;
55+
})
56+
.reduce((collector, [key, area])=>{
57+
collector[area.partial] = area;
58+
return collector;
59+
},{});
4660
};
4761

4862
areaListStyles = () => {
@@ -73,7 +87,7 @@ class Areas extends Component {
7387
</a>
7488
<div className={this.areaListStyles()} id="areas_list">
7589
<label>Selected selected: {this.getTotalSelectedAreas()}</label>
76-
{map(this.getSelectedAreas(), (area, idx)=>{
90+
{Object.entries(this.getSelectedAreas()).map(([idx, area])=>{
7791
return (
7892
<AreaPartial
7993
key={`areaSelected:${idx}:${area.selected?1:0}`}
@@ -82,7 +96,7 @@ class Areas extends Component {
8296
);
8397
})}
8498
<label>Un-Selected</label>
85-
{map(this.getUnselectedAreas(), (area, idx)=>{
99+
{Object.entries(this.getUnselectedAreas()).map(([idx, area])=>{
86100
return (
87101
<AreaPartial
88102
key={`areaUnSelected:${idx}:${area.selected?1:0}`}
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23

3-
export const CheckBoxField = ({field, cb}) =>{
4+
const CheckBoxField = ({checkbox, cb}) =>{
45
return (
56
<div className="checkbox-field">
6-
<label className="fields" htmlFor={field.checkbox.arg_name}>{field.checkbox.title}</label>
7-
<input id={field.checkbox.arg_name}
7+
<label className="fields" htmlFor={checkbox.arg_name}>{checkbox.title}</label>
8+
<input id={checkbox.arg_name}
89
className="fields"
910
type="checkbox"
10-
onChange={(e)=>cb({elm:e, key:field.checkbox.arg_name})}
11-
value={field.checkbox.value}
11+
onChange={(e)=>cb({elm:e, key:checkbox.arg_name})}
12+
value={checkbox.value}
1213
/>
13-
<br />
1414
</div>
1515
);
1616
};
17+
18+
CheckBoxField.propTypes = {
19+
checkbox:PropTypes.shape({
20+
title:PropTypes.string.isRequired,
21+
arg_name:PropTypes.string.isRequired,
22+
value:PropTypes.string.isRequired,
23+
}),
24+
cb: PropTypes.func.isRequired,
25+
};
26+
27+
CheckBoxField.defaultProps = {
28+
checkbox:{
29+
title:'',
30+
arg_name:'',
31+
value:''
32+
},
33+
cb:()=>{console.log('checkbox-un-bound')}
34+
};
35+
36+
export default CheckBoxField;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
import TextField from '../TextField';
3+
import RadioFields from '../RadioFields';
4+
import CheckBoxField from '../CheckBoxField';
5+
import PropTypes from "prop-types";
6+
7+
const FormField = ({field, onTextChange, onRadioChange, onCheckBoxChange}) =>{
8+
switch(field.argType)
9+
{
10+
case 'text':
11+
return (
12+
<TextField
13+
field={field}
14+
cb={onTextChange}
15+
/>
16+
);
17+
18+
case 'radio':
19+
return (
20+
<RadioFields
21+
fieldName={field.argName}
22+
cb={onRadioChange}
23+
radios={field.radios} />
24+
);
25+
26+
case 'checkbox':
27+
return (
28+
<CheckBoxField
29+
checkbox={field.checkbox}
30+
cb={onCheckBoxChange} />
31+
);
32+
}
33+
};
34+
35+
FormField.propTypes = {
36+
field: PropTypes.object.isRequired,
37+
onTextChange: PropTypes.func.isRequired,
38+
onRadioChange: PropTypes.func.isRequired,
39+
onCheckBoxChange: PropTypes.func.isRequired
40+
};
41+
42+
FormField.defaultProps = {
43+
field:{},
44+
onTextChange:()=>{console.log('onTextChange:unbound')},
45+
onRadioChange:()=>{console.log('onRadioChange:unbound')},
46+
onCheckBoxChange:()=>{console.log('onCheckBoxChange:unbound')}
47+
};
48+
49+
export default FormField;
Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,64 @@
11
import React from 'react';
2+
import PropTypes from "prop-types";
23

3-
const RadioField = ({field, radio, cb})=>{
4+
const RadioField = ({fieldName, radio, cb})=>{
45
return (
56
<div className="radio-box-field">
67
<label className="fields"
78
htmlFor={radio.arg_name_id}>{radio.arg_name}</label>
89
<input className="fields"
910
id={radio.arg_name_id}
1011
type="radio"
11-
name={field.argName}
12-
onChange={(e)=>cb({elm:e, key:field.argName})}
12+
name={fieldName}
13+
onChange={(e)=>cb({elm:e, key:fieldName})}
1314
value={radio.arg} />
1415
<br />
1516
</div>
1617
);
1718
};
1819

19-
export const RadioFields = ({field, radios, cb})=>{
20+
RadioField.propTypes = {
21+
radio: PropTypes.shape({
22+
arg_name_id:PropTypes.string.isRequired,
23+
arg_name:PropTypes.string.isRequired,
24+
arg:PropTypes.string.isRequired,
25+
}),
26+
fieldName: PropTypes.string.isRequired,
27+
cb: PropTypes.func.isRequired,
28+
};
29+
30+
RadioField.defaultProps = {
31+
radio: {
32+
arg_name_id:'',
33+
arg_name:'',
34+
arg:''
35+
},
36+
fieldName:'',
37+
cb:()=>{}
38+
};
39+
40+
const RadioFields = ({fieldName, radios, cb})=>{
2041
return (
2142
<div className="radio-box-fields">
2243
{radios.map(radio=>{
2344
return (
24-
<RadioField key={radio.arg_name_id} field={field} radio={radio} cb={cb} />
45+
<RadioField key={radio.arg_name_id} fieldName={fieldName} radio={radio} cb={cb} />
2546
);
2647
})}
2748
</div>
2849
);
29-
};
50+
};
51+
52+
RadioFields.propTypes = {
53+
field: PropTypes.object.isRequired,
54+
radios: PropTypes.array.isRequired,
55+
cb: PropTypes.func.isRequired,
56+
};
57+
58+
RadioFields.defaultProps = {
59+
field: {},
60+
radios: [],
61+
cb:()=>{}
62+
};
63+
64+
export default RadioFields;

resources/assets/js/components/navigation/Regions/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ class Regions extends Component {
6060
}
6161
</a>
6262
<div className={this.regionListStyles()} id="region_list">
63-
{map(this.props.region_list, (region, idx)=>{
63+
{Object.entries(this.props.region_list).map(([key, region])=>{
6464
return (
6565
<RegionPartial
66-
key={`idx${idx}:${region.selected?1:0}`}
66+
key={`idx${key}:${region.selected?1:0}`}
6767
region={region}
6868
callback={(e)=>this.updateRegionSelection({elm:e, region})} />
6969
);
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
import React from 'react';
2+
import PropTypes from "prop-types";
23

3-
export const TextField = ({field, value, cb})=>{
4+
const TextField = ({field, value, cb})=>{
45
return (
56
<div className="text-field">
67
<label className="fields" htmlFor={field.argId}>{field.argTitle}</label>
7-
<input className="fields" onChange={(e)=>cb({elm:e, key:field.argName})} type="text" value={value} id={field.argId} />
8+
<input className="fields" onChange={(e)=>cb({elm:e, key:field.argName})} type="text" id={field.argId} />
89
<br />
910
</div>
1011
);
11-
};
12+
};
13+
14+
TextField.propTypes = {
15+
field: PropTypes.shape({
16+
argId:PropTypes.string.isRequired,
17+
argTitle:PropTypes.string.isRequired,
18+
argName:PropTypes.string.isRequired,
19+
}),
20+
value: PropTypes.string.isRequired,
21+
cb: PropTypes.func.isRequired
22+
};
23+
24+
TextField.defaultProps = {
25+
field: {
26+
argId:'',
27+
argTitle:'',
28+
argName:'',
29+
},
30+
value :'',
31+
cb: ()=>{}
32+
};
33+
34+
export default TextField;

resources/assets/js/components/navigation/index.js

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { connect } from 'react-redux';
33
import actions from '../../actions/index';
44
import { withRouter } from 'react-router-dom';
55
import debounce from 'lodash/debounce';
6-
import {TextField} from './TextField';
7-
import {RadioFields} from './RadioFields';
8-
import {CheckBoxField} from './CheckBoxField';
96
import Regions from './Regions';
107
import Areas from './Areas';
8+
import PropTypes from "prop-types";
9+
import FormField from './FormField';
10+
1111
class Navigation extends Component {
1212

1313
state = {
@@ -100,36 +100,17 @@ class Navigation extends Component {
100100
<form onSubmit={this.submitForm} id="find_items">
101101
<div id="change_size_container">
102102
<div>{this.props.page_title}</div>
103-
{Object.keys(this.props.fields).map(fieldKey=>{
104-
let field = this.props.fields[fieldKey];
105-
switch(field.argType)
106-
{
107-
case 'text':
108-
return (
109-
<TextField
110-
key={field.argName}
111-
cb={this.onTextChange}
112-
field={field}
113-
state={this.state} />
114-
);
115-
116-
case 'radio':
117-
return (
118-
<RadioFields
119-
key={field.argName}
120-
field={field}
121-
cb={this.onRadioChange}
122-
radios={field.radios} />
123-
);
124-
125-
case 'checkbox':
126-
return (
127-
<CheckBoxField
128-
key={field.checkbox.arg_name}
129-
field={field}
130-
cb={this.onCheckBoxChange} />
131-
);
132-
}
103+
{Object.entries(this.props.fields).map(([key, field])=>{
104+
return (
105+
<FormField
106+
key={field.argName}
107+
field={field}
108+
state={this.state}
109+
onTextChange={this.onTextChange}
110+
onRadioChange={this.onRadioChange}
111+
onCheckBoxChange={this.onCheckBoxChange}
112+
/>
113+
);
133114
})}
134115
</div>
135116
<cite>{this.props.page_search_example}</cite>
@@ -143,5 +124,21 @@ class Navigation extends Component {
143124
}
144125
}
145126

127+
Navigation.propTypes = {
128+
page_title: PropTypes.string.isRequired,
129+
site: PropTypes.string.isRequired,
130+
page_search_example: PropTypes.string.isRequired,
131+
area_list: PropTypes.object.isRequired,
132+
region_list: PropTypes.object.isRequired,
133+
};
134+
135+
Navigation.defaultProps = {
136+
page_title:'',
137+
site:'',
138+
page_search_example:'',
139+
area_list:{},
140+
region_list:{}
141+
};
142+
146143
const mapStateToProps = state => state.search_settings;
147144
export default withRouter(connect(mapStateToProps)(Navigation));

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5880,7 +5880,7 @@ promise@^7.1.1:
58805880
dependencies:
58815881
asap "~2.0.3"
58825882

5883-
prop-types@^15.5.4, prop-types@^15.6.0, prop-types@^15.6.1:
5883+
prop-types@^15.5.4, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
58845884
version "15.6.2"
58855885
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
58865886
dependencies:

0 commit comments

Comments
 (0)