-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert ExpandedStoryTask to be a functional component (#886)
* Convert ExpandedStoryTask to be a functional component * test: Remove WrapperInstance --------- Co-authored-by: Talysson de Oliveira Cassiano <[email protected]>
- Loading branch information
1 parent
dc9af32
commit 8e0c0b1
Showing
2 changed files
with
38 additions
and
79 deletions.
There are no files selected for viewing
106 changes: 37 additions & 69 deletions
106
app/assets/javascripts/components/story/ExpandedStory/ExpandedStoryTask.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,88 +1,56 @@ | ||
import React, { Component } from 'react'; | ||
import React, { useState } from 'react'; | ||
import TasksList from '../task/TasksList'; | ||
import PropTypes from 'prop-types'; | ||
import { editingStoryPropTypesShape } from '../../../models/beta/story'; | ||
import ExpandedStorySection from './ExpandedStorySection'; | ||
|
||
class ExpandedStoryTask extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
task: '' | ||
}; | ||
this.onInputChange = this.onInputChange.bind(this); | ||
this.onHandleSubmit = this.onHandleSubmit.bind(this); | ||
} | ||
const ExpandedStoryTask = ({ story, onToggle, onDelete, onSave, disabled }) => { | ||
const [task, setTask] = useState(''); | ||
|
||
onInputChange(e) { | ||
this.setState({ | ||
task: e.target.value | ||
}); | ||
} | ||
const onInputChange = (e) => { | ||
setTask(e.target.value); | ||
}; | ||
|
||
onHandleSubmit() { | ||
const { onSave } = this.props; | ||
|
||
const task = this.state.task; | ||
const onHandleSubmit = () => { | ||
onSave(task); | ||
this.setState({ | ||
task: '' | ||
}); | ||
} | ||
|
||
hasAnEmptyValue() { | ||
return !this.state.task.trim() | ||
} | ||
|
||
render() { | ||
const { story, onToggle, onDelete, disabled } = this.props; | ||
|
||
if (disabled && !story.tasks.length) return null; | ||
|
||
return ( | ||
<ExpandedStorySection | ||
title={I18n.t('story.tasks')} | ||
identifier="tasks" | ||
> | ||
<div className="list-task" > | ||
<TasksList | ||
tasks={story.tasks} | ||
onDelete={onDelete} | ||
onToggle={onToggle} | ||
disabled={disabled} | ||
/> | ||
setTask(''); | ||
}; | ||
|
||
const hasAnEmptyValue = () => { | ||
return !task.trim(); | ||
}; | ||
|
||
if (disabled && !story.tasks.length) return null; | ||
|
||
return ( | ||
<ExpandedStorySection title={I18n.t('story.tasks')} identifier="tasks"> | ||
<div className="list-task"> | ||
<TasksList tasks={story.tasks} onDelete={onDelete} onToggle={onToggle} disabled={disabled} /> | ||
</div> | ||
|
||
{!disabled && ( | ||
<div className="task-form"> | ||
<input value={task} className="form-control input-sm" onChange={onInputChange} /> | ||
<button | ||
type="submit" | ||
className="add-task-button" | ||
onClick={onHandleSubmit} | ||
disabled={hasAnEmptyValue()} | ||
> | ||
{I18n.t('add task')} | ||
</button> | ||
</div> | ||
|
||
{ | ||
!disabled && ( | ||
<div className="task-form"> | ||
<input | ||
value={this.state.task} | ||
className="form-control input-sm" | ||
onChange={this.onInputChange} | ||
/> | ||
<button | ||
type='submit' | ||
className='add-task-button' | ||
onClick={this.onHandleSubmit} | ||
disabled={this.hasAnEmptyValue()} | ||
> | ||
{I18n.t('add task')} | ||
</button> | ||
</div> | ||
) | ||
} | ||
</ExpandedStorySection> | ||
); | ||
} | ||
)} | ||
</ExpandedStorySection> | ||
); | ||
}; | ||
|
||
ExpandedStoryTask.propTypes = { | ||
story: editingStoryPropTypesShape.isRequired, | ||
onToggle: PropTypes.func.isRequired, | ||
onDelete: PropTypes.func.isRequired, | ||
onSave: PropTypes.func.isRequired, | ||
disabled: PropTypes.bool.isRequired | ||
disabled: PropTypes.bool.isRequired, | ||
}; | ||
|
||
export default ExpandedStoryTask; |
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