Last active
July 28, 2017 16:38
-
-
Save davelnewton/3f32d33e38ccc5fa5a4f7aa9ebf10334 to your computer and use it in GitHub Desktop.
Very Rough Refactoring
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
const TextForm = ({ value, onChange }) => | |
<Form> | |
<TextArea | |
autoHeight | |
onChange={onChange} | |
placeholder="Description" | |
value={value} | |
/> | |
</Form> | |
const baseCellStyles = { | |
maxWidth: '100px', | |
overflow: 'hidden', | |
textOverflow: 'ellipsis', | |
verticalAlign: 'middle', | |
whiteSpace: 'nowrap' | |
} | |
const cellStyles = (negative = null) => | |
negative === null ? cellStyles : { ...baseCellStyles, negative: element.description.length === 0} | |
const showDescription = (editProject, editProjectIndexm, index) => | |
(editProject === false) || ((editProject === true) && (editProjectIndex !== index)) | |
const showTextForm = (editProject, editProjectIndex, index) => | |
(editProject === true) && (editProjectIndex === index) | |
const ElementCell = ({ editProject, editProjectIndex, index, onTextChange, newProjectDescription, negative=null}) => { | |
<Table.Cell style={cellStyles(negative)}> | |
{ | |
showDescription(editProject, editProjectIndex, index) | |
? element.description | |
: null | |
} | |
{ | |
showTextForm(editProject, editProjectIndex, index) | |
? <TextForm value={this.state.newProjectDescription} onChange={onTextChange} /> | |
: null | |
} | |
</Table.Cell> | |
class CellComponent extends React.Component { | |
render() { | |
if (element.description.length > 0) { | |
<Popup | |
basic | |
content={element.description} | |
trigger={ | |
<ElementCell | |
editProject={editProject} | |
editProjectIndex={editProjectIndex} | |
element={element} | |
index={index} | |
newProjectDescription={this.state.newProjectDescription} | |
onTextChange={this.handleChangeNewProjectDescription} | |
/> | |
} | |
/> | |
} | |
return ( | |
<ElementCell | |
editProject={editProject} | |
editProjectIndex={editProjectIndex} | |
element={element} | |
index={index} | |
newProjectDescription={this.state.newProjectDescription} | |
onTextChange={this.handleChangeNewProjectDescription} | |
/> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment