Skip to content

Instantly share code, notes, and snippets.

@davelnewton
Last active July 28, 2017 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davelnewton/3f32d33e38ccc5fa5a4f7aa9ebf10334 to your computer and use it in GitHub Desktop.
Save davelnewton/3f32d33e38ccc5fa5a4f7aa9ebf10334 to your computer and use it in GitHub Desktop.
Very Rough Refactoring
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