-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove unnecessary states from react components
fix other linting issues
- Loading branch information
Showing
14 changed files
with
404 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 69 additions & 60 deletions
129
src/app/components/main/components/group/components/fields/checkbox/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,96 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
import React from 'react'; | ||
import {newGuid} from "../../../../../../../utils/newGuid"; | ||
import React from 'react' | ||
import { newGuid } from '../../../../../../../utils/newGuid' | ||
|
||
class CheckboxField extends React.Component { | ||
|
||
state = {}; | ||
render() { | ||
|
||
render() { | ||
|
||
const fieldID = `checkbox_${newGuid()}`; | ||
|
||
const options = this.options.map((option, idx) => { | ||
const id = `${fieldID}_${idx}`; | ||
return ( | ||
<label htmlFor={ id } className="checkbox-option"> | ||
{ option.label } | ||
<input type="checkbox" id={ id } onChange={ this.onChange.bind(this) } checked={ this.value.indexOf(option.value) >= 0 } /> | ||
<span className="check-square" /> | ||
</label> | ||
); | ||
}); | ||
const fieldID = `checkbox_${newGuid()}` | ||
|
||
return ( | ||
<div className="field field-checkbox"> | ||
<div className="field-label">{ this.label }</div> | ||
{ options } | ||
{ this.help && <span className="help">{ this.help }</span> } | ||
</div> | ||
); | ||
const options = this.options.map((option, idx) => { | ||
|
||
} | ||
const id = `${fieldID}_${idx}` | ||
|
||
get field() { | ||
return ( | ||
<label htmlFor={ id } className="checkbox-option"> | ||
{ option.label } | ||
<input type="checkbox" id={ id } onChange={ this.onChange.bind(this) } checked={ this.value.indexOf(option.value) >= 0 } /> | ||
<span className="check-square" /> | ||
</label> | ||
) | ||
|
||
return this.props.field; | ||
}) | ||
|
||
} | ||
return ( | ||
<div className="field field-checkbox"> | ||
<div className="field-label">{ this.label }</div> | ||
{ options } | ||
{ this.help && <span className="help">{ this.help }</span> } | ||
</div> | ||
) | ||
|
||
get value() { | ||
} | ||
|
||
return this.props.value || []; | ||
get field() { | ||
|
||
} | ||
return this.props.field | ||
|
||
get label() { | ||
} | ||
|
||
return this.field.label; | ||
get value() { | ||
|
||
} | ||
|
||
get options() { | ||
return this.props.value || [] | ||
|
||
return this.field.options || []; | ||
} | ||
|
||
} | ||
get label() { | ||
|
||
get help() { | ||
return this.field.label | ||
|
||
return this.field.help; | ||
} | ||
|
||
} | ||
get options() { | ||
|
||
onChange(e) { | ||
|
||
const idx = e.target.id.split('_')[2]; | ||
const option = this.options[idx]; | ||
|
||
if (e.target.checked) { | ||
if (this.value.indexOf(option.value) === -1) { | ||
this.value.push(option.value); | ||
} | ||
} else { | ||
const valIdx = this.value.indexOf(option.value); | ||
if (valIdx > -1) { | ||
this.value.splice(valIdx, 1); | ||
} | ||
} | ||
return this.field.options || [] | ||
|
||
return this.props.onChange(this.value); | ||
} | ||
|
||
} | ||
get help() { | ||
|
||
return this.field.help | ||
|
||
} | ||
|
||
onChange(e) { | ||
|
||
const idx = e.target.id.split('_')[2] | ||
const option = this.options[idx] | ||
|
||
if (e.target.checked) { | ||
|
||
if (this.value.indexOf(option.value) === -1) { | ||
|
||
this.value.push(option.value) | ||
|
||
} | ||
|
||
} else { | ||
|
||
const valIdx = this.value.indexOf(option.value) | ||
if (valIdx > -1) { | ||
|
||
this.value.splice(valIdx, 1) | ||
|
||
} | ||
|
||
} | ||
|
||
return this.props.onChange(this.value) | ||
|
||
} | ||
|
||
} | ||
|
||
export default CheckboxField; | ||
export default CheckboxField |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 36 additions & 40 deletions
76
src/app/components/main/components/group/components/fields/dropdown/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,64 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
import React from 'react'; | ||
import React from 'react' | ||
|
||
class DropdownField extends React.Component { | ||
|
||
state = {}; | ||
render() { | ||
|
||
render() { | ||
const options = this.options.map((option, idx) => ( | ||
<option value={option.value} key={idx}>{option.label}</option> | ||
)) | ||
|
||
const options = this.options.map((option, idx) => { | ||
return ( | ||
<option value={option.value} key={idx}>{option.label}</option> | ||
); | ||
}); | ||
return ( | ||
<div className="field field-dropdown"> | ||
<div className="field-label">{ this.label }</div> | ||
<select onChange={ this.onChange.bind(this) } value={ this.value }> | ||
<option value="">-- Select One --</option> | ||
{ options } | ||
</select> | ||
{ this.help && <span className="help">{ this.help }</span> } | ||
</div> | ||
) | ||
|
||
return ( | ||
<div className="field field-dropdown"> | ||
<div className="field-label">{ this.label }</div> | ||
<select onChange={ this.onChange.bind(this) } value={ this.value }> | ||
<option value="">-- Select One --</option> | ||
{ options } | ||
</select> | ||
{ this.help && <span className="help">{ this.help }</span> } | ||
</div> | ||
); | ||
} | ||
|
||
} | ||
get field() { | ||
|
||
get field() { | ||
return this.props.field | ||
|
||
return this.props.field; | ||
} | ||
|
||
} | ||
get value() { | ||
|
||
get value() { | ||
return this.props.value || '' | ||
|
||
return this.props.value || ''; | ||
} | ||
|
||
} | ||
get label() { | ||
|
||
get label() { | ||
return this.field.label | ||
|
||
return this.field.label; | ||
} | ||
|
||
} | ||
get options() { | ||
|
||
get options() { | ||
return this.field.options || [] | ||
|
||
return this.field.options || []; | ||
} | ||
|
||
} | ||
get help() { | ||
|
||
get help() { | ||
return this.field.help | ||
|
||
return this.field.help; | ||
} | ||
|
||
} | ||
onChange(e) { | ||
|
||
onChange(e) { | ||
return this.props.onChange(e.target.value) | ||
|
||
return this.props.onChange(e.target.value); | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
export default DropdownField; | ||
export default DropdownField |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.