Skip to content

Commit

Permalink
fix(qna): don't allow deleting the only question
Browse files Browse the repository at this point in the history
  • Loading branch information
emirotin committed Jun 1, 2018
1 parent 6518bdc commit b16f3a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/functionals/botpress-qna/src/views/ArrayEditor.js
Expand Up @@ -92,12 +92,13 @@ export default class ArrayEditor extends Component {

isDirty = index => this.state.originals[index == null ? NEW_INDEX : index] !== undefined

renderItemForm = (value, index) => {
renderItemForm = (value, index, values) => {
const { renderItem } = this.props

return (
<Fragment key={index != null ? index : 'new'}>
{renderItem(value, index, {
values,
isDirty: this.isDirty(index),
onCreate: this.onCreate,
onEdit: this.onEdit,
Expand All @@ -114,7 +115,7 @@ export default class ArrayEditor extends Component {

return (
<Fragment>
{this.renderItemForm(newItem, null)}
{this.renderItemForm(newItem, null, null)}
{items && items.map(this.renderItemForm)}
</Fragment>
)
Expand Down
10 changes: 7 additions & 3 deletions packages/functionals/botpress-qna/src/views/QuestionsEditor.js
Expand Up @@ -22,7 +22,7 @@ export default class QuestionsEditor extends Component {
this.props.onChange([''].concat(this.props.items))
}

renderForm = (data, index, { onDelete, onChange }) => {
renderForm = (data, index, { values, onDelete, onChange }) => {
if (index == null) {
return (
<div className={classnames(style.paddedRow, style.questionToolbar)}>
Expand All @@ -39,9 +39,13 @@ export default class QuestionsEditor extends Component {
<FormGroup>
<InputGroup>
<FormControl placeholder="Question" value={data} onChange={this.onQuestionChange(index, onChange)} />

<InputGroup.Button>
<Button type="button" bsStyle="danger" onClick={() => onDelete(index)}>
<Button
type="button"
bsStyle="danger"
onClick={() => onDelete(index)}
disabled={!values || values.length <= 1}
>
<Glyphicon glyph="remove-circle" />
</Button>
</InputGroup.Button>
Expand Down

0 comments on commit b16f3a8

Please sign in to comment.