-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1125 from rdmorganiser/interview-apply-to-all
feat(interview): apply to all [2]
- Loading branch information
Showing
23 changed files
with
376 additions
and
63 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
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
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
27 changes: 27 additions & 0 deletions
27
rdmo/projects/assets/js/interview/components/main/question/QuestionCopyValue.js
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { isEmptyValue } from '../../../utils/value' | ||
|
||
const QuestionCopyValue = ({ question, value, siblings, copyValue }) => { | ||
return ( | ||
question.set_collection && | ||
!question.is_collection && | ||
!isEmptyValue(value) && | ||
siblings.some((value) => isEmptyValue(value)) && ( | ||
<button className="btn btn-link btn-apply-to-all" onClick={() => copyValue(value, siblings)} | ||
title={gettext('Apply this answer to all tabs where this question is empty')}> | ||
<i className="fa fa-arrow-circle-right fa-btn"></i> | ||
</button> | ||
) | ||
) | ||
} | ||
|
||
QuestionCopyValue.propTypes = { | ||
question: PropTypes.object.isRequired, | ||
value: PropTypes.object.isRequired, | ||
siblings: PropTypes.array.isRequired, | ||
copyValue: PropTypes.func.isRequired | ||
} | ||
|
||
export default QuestionCopyValue |
57 changes: 57 additions & 0 deletions
57
rdmo/projects/assets/js/interview/components/main/question/QuestionCopyValues.js
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { isEmpty } from 'lodash' | ||
|
||
import { isEmptyValue } from '../../../utils/value' | ||
|
||
const QuestionCopyValues = ({ question, sets, values, siblings, currentSet, copyValue }) => { | ||
const handleCopyValues = () => { | ||
values.forEach((value) => copyValue(value)) | ||
} | ||
|
||
const button = question.widget_type == 'checkbox' ? ( | ||
<button className="btn btn-link btn-apply-to-all" onClick={handleCopyValues} | ||
title={gettext('Apply this answer to all tabs where this question is empty')}> | ||
<i className="fa fa-arrow-circle-right fa-btn"></i> | ||
</button> | ||
) : ( | ||
<button type="button" className="btn btn-primary btn-xs copy-value-button ml-10" onClick={handleCopyValues}> | ||
<i className="fa fa-arrow-circle-right fa-btn"></i> {gettext('Apply to all')} | ||
</button> | ||
) | ||
|
||
const hasValues = values.some((value) => !isEmptyValue(value)) | ||
|
||
const hasEmptySiblings = sets.filter((set) => ( | ||
(set.set_prefix == currentSet.set_prefix) && | ||
(set.set_index != currentSet.set_index) | ||
)).some((set) => { | ||
// loop over all other sets and filter siblings accordingly | ||
const setSiblings = siblings.filter((value) => ( | ||
(value.set_prefix == set.set_prefix) && | ||
(value.set_index == set.set_index) | ||
)) | ||
|
||
// check if this set has no sibling at all (for checkboxes) or if they are empty | ||
return isEmpty(setSiblings) || setSiblings.some((value) => isEmptyValue(value)) | ||
}) | ||
|
||
return ( | ||
question.is_collection && | ||
question.set_collection && | ||
hasValues && | ||
hasEmptySiblings && | ||
button | ||
) | ||
} | ||
|
||
QuestionCopyValues.propTypes = { | ||
question: PropTypes.object.isRequired, | ||
sets: PropTypes.array.isRequired, | ||
values: PropTypes.array.isRequired, | ||
siblings: PropTypes.array, | ||
currentSet: PropTypes.object.isRequired, | ||
copyValue: PropTypes.func.isRequired | ||
} | ||
|
||
export default QuestionCopyValues |
23 changes: 23 additions & 0 deletions
23
rdmo/projects/assets/js/interview/components/main/question/QuestionEraseValues.js
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
const QuestionEraseValues = ({ values, disabled, deleteValue }) => { | ||
const handleEraseValue = () => { | ||
values.forEach((value) => deleteValue(value)) | ||
} | ||
|
||
return !disabled && ( | ||
<button type="button" className="btn btn-link btn-erase-value" onClick={handleEraseValue} | ||
title={gettext('Erase input')}> | ||
<i className="fa fa-eraser fa-btn"></i> | ||
</button> | ||
) | ||
} | ||
|
||
QuestionEraseValues.propTypes = { | ||
values: PropTypes.array.isRequired, | ||
disabled: PropTypes.bool.isRequired, | ||
deleteValue: PropTypes.func.isRequired | ||
} | ||
|
||
export default QuestionEraseValues |
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.