Skip to content

Commit

Permalink
Check siblings for copyValues and use copyValues for all is_collectio…
Browse files Browse the repository at this point in the history
…n questions
  • Loading branch information
jochenklar committed Aug 20, 2024
1 parent 1152302 commit 5c65410
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const Page = ({ config, templates, overview, page, sets, values, fetchPage,
value.set_prefix == currentSetPrefix &&
value.set_index == currentSetIndex
))}
siblings={values.filter((value) => (
value.attribute == element.attribute &&
value.set_prefix == currentSetPrefix &&
value.set_index != currentSetIndex
))}
disabled={overview.read_only}
isManager={isManager}
currentSet={currentSet}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import QuestionText from './QuestionText'
import QuestionWarning from './QuestionWarning'
import QuestionWidget from './QuestionWidget'

const Question = ({ templates, question, values, disabled, isManager,
const Question = ({ templates, question, values, siblings, disabled, isManager,
currentSet, createValue, updateValue, deleteValue, copyValue }) => {
return checkQuestion(question, currentSet) && (
<div className={`interview-question col-md-${question.width || '12'}`}>
Expand All @@ -26,6 +26,7 @@ const Question = ({ templates, question, values, disabled, isManager,
<QuestionWidget
question={question}
values={values}
siblings={siblings}
disabled={disabled}
currentSet={currentSet}
createValue={createValue}
Expand All @@ -41,6 +42,7 @@ Question.propTypes = {
templates: PropTypes.object.isRequired,
question: PropTypes.object.isRequired,
values: PropTypes.array.isRequired,
siblings: PropTypes.array,
disabled: PropTypes.bool.isRequired,
isManager: PropTypes.bool.isRequired,
currentSet: PropTypes.object.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AddValue = ({ question, values, currentSet, disabled, createValue }) => {
}

return !disabled && question.is_collection && (
<button type="button" className="btn btn-success add-value-button" onClick={handleClick}>
<button type="button" className="btn btn-success btn-xs add-value-button" onClick={handleClick}>
<i className="fa fa-plus fa-btn"></i> {capitalize(question.verbose_name)}
</button>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import PropTypes from 'prop-types'

import { isEmptyValue } from '../../../utils/value'

const QuestionCopyValue = ({ question, value, copyValue }) => {
const QuestionCopyValue = ({ question, value, siblings, copyValue }) => {
return (
question.set_collection && !isEmptyValue(value) && (
<button className="btn btn-link btn-apply-to-all" onClick={() => copyValue(value)}
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>
Expand All @@ -17,6 +20,7 @@ const QuestionCopyValue = ({ question, value, copyValue }) => {
QuestionCopyValue.propTypes = {
question: PropTypes.object.isRequired,
value: PropTypes.object.isRequired,
siblings: PropTypes.object.isRequired,
copyValue: PropTypes.func.isRequired
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@ import PropTypes from 'prop-types'

import { isEmptyValue } from '../../../utils/value'

const QuestionCopyValues = ({ question, values, copyValue }) => {
const QuestionCopyValues = ({ question, values, siblings, copyValue }) => {
const handleCopyValues = () => {
values.forEach((value) => copyValue(value))
}

console.log(values)
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>
)

return (
question.set_collection && values.some((v) => !isEmptyValue(v)) && (
<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>
)
question.is_collection &&
question.set_collection &&
values.some((v) => !isEmptyValue(v)) &&
siblings.some((value) => isEmptyValue(value)) &&
button
)
}

QuestionCopyValues.propTypes = {
question: PropTypes.object.isRequired,
values: PropTypes.array.isRequired,
siblings: PropTypes.array,
copyValue: PropTypes.func.isRequired
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const QuestionSet = ({ templates, questionset, sets, values, disabled, isManager
value.set_prefix == set.set_prefix &&
value.set_index == set.set_index
))}
siblings={values.filter((value) => (
value.attribute == element.attribute &&
value.set_prefix == set.set_prefix &&
value.set_index != set.set_index
))}
disabled={disabled}
isManager={isManager}
currentSet={set}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import QuestionSuccess from '../question/QuestionSuccess'

import CheckboxInput from './CheckboxInput'

const CheckboxWidget = ({ question, values, currentSet, disabled,
const CheckboxWidget = ({ question, values, siblings, currentSet, disabled,
createValue, updateValue, deleteValue, copyValue }) => {

const handleCreateValue = (option, additionalInput) => {
Expand Down Expand Up @@ -71,7 +71,7 @@ const CheckboxWidget = ({ question, values, currentSet, disabled,
</div>
<div className="buttons">
<QuestionSuccess value={{ success }} />
<QuestionCopyValues question={question} values={values} copyValue={copyValue} />
<QuestionCopyValues question={question} values={values} siblings={siblings} copyValue={copyValue} />
</div>
</div>
</div>
Expand All @@ -83,6 +83,7 @@ const CheckboxWidget = ({ question, values, currentSet, disabled,
CheckboxWidget.propTypes = {
question: PropTypes.object.isRequired,
values: PropTypes.array.isRequired,
siblings: PropTypes.array,
disabled: PropTypes.bool,
currentSet: PropTypes.object.isRequired,
createValue: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'

import QuestionAddValue from '../question/QuestionAddValue'
import QuestionCopyValue from '../question/QuestionCopyValue'
import QuestionCopyValues from '../question/QuestionCopyValues'
import QuestionDefault from '../question/QuestionDefault'
import QuestionError from '../question/QuestionError'
import QuestionEraseValue from '../question/QuestionEraseValue'
Expand All @@ -11,7 +12,7 @@ import QuestionRemoveValue from '../question/QuestionRemoveValue'

import DateInput from './DateInput'

const DateWidget = ({ question, values, currentSet, disabled, createValue, updateValue, deleteValue, copyValue }) => {
const DateWidget = ({ question, values, siblings, currentSet, disabled, createValue, updateValue, deleteValue, copyValue }) => {
return (
<div className="interview-widgets">
{
Expand All @@ -34,7 +35,7 @@ const DateWidget = ({ question, values, currentSet, disabled, createValue, updat
disabled={disabled}
deleteValue={deleteValue}
/>
<QuestionCopyValue question={question} value={value} copyValue={copyValue} />
<QuestionCopyValue question={question} value={value} siblings={siblings} copyValue={copyValue} />
<QuestionDefault question={question} value={value} />
</div>
}
Expand All @@ -52,13 +53,20 @@ const DateWidget = ({ question, values, currentSet, disabled, createValue, updat
createValue={createValue}
copyValue={copyValue}
/>
<QuestionCopyValues
question={question}
values={values}
siblings={siblings}
copyValue={copyValue}
/>
</div>
)
}

DateWidget.propTypes = {
question: PropTypes.object.isRequired,
values: PropTypes.array.isRequired,
siblings: PropTypes.array,
disabled: PropTypes.bool,
currentSet: PropTypes.object.isRequired,
createValue: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { gatherOptions } from '../../../utils/options'

import QuestionAddValue from '../question/QuestionAddValue'
import QuestionCopyValue from '../question/QuestionCopyValue'
import QuestionCopyValues from '../question/QuestionCopyValues'
import QuestionDefault from '../question/QuestionDefault'
import QuestionError from '../question/QuestionError'
import QuestionSuccess from '../question/QuestionSuccess'
Expand All @@ -13,7 +14,8 @@ import QuestionRemoveValue from '../question/QuestionRemoveValue'

import RadioInput from './RadioInput'

const RadioWidget = ({ question, values, currentSet, disabled, createValue, updateValue, deleteValue, copyValue }) => {
const RadioWidget = ({ question, values, siblings, currentSet, disabled,
createValue, updateValue, deleteValue, copyValue }) => {
return (
<div className="interview-widgets">
{
Expand All @@ -37,7 +39,7 @@ const RadioWidget = ({ question, values, currentSet, disabled, createValue, upda
disabled={disabled}
deleteValue={deleteValue}
/>
<QuestionCopyValue question={question} value={value} copyValue={copyValue} />
<QuestionCopyValue question={question} value={value} siblings={siblings} copyValue={copyValue} />
<QuestionDefault question={question} value={value} />
</div>
}
Expand All @@ -55,13 +57,20 @@ const RadioWidget = ({ question, values, currentSet, disabled, createValue, upda
createValue={createValue}
copyValue={copyValue}
/>
<QuestionCopyValues
question={question}
values={values}
siblings={siblings}
copyValue={copyValue}
/>
</div>
)
}

RadioWidget.propTypes = {
question: PropTypes.object.isRequired,
values: PropTypes.array.isRequired,
siblings: PropTypes.array,
disabled: PropTypes.bool,
currentSet: PropTypes.object.isRequired,
createValue: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { initRange } from '../../../utils/value'

import QuestionAddValue from '../question/QuestionAddValue'
import QuestionCopyValue from '../question/QuestionCopyValue'
import QuestionCopyValues from '../question/QuestionCopyValues'
import QuestionDefault from '../question/QuestionDefault'
import QuestionError from '../question/QuestionError'
import QuestionSuccess from '../question/QuestionSuccess'
Expand All @@ -13,7 +14,8 @@ import QuestionRemoveValue from '../question/QuestionRemoveValue'

import RangeInput from './RangeInput'

const RangeWidget = ({ question, values, currentSet, disabled, createValue, updateValue, deleteValue, copyValue }) => {
const RangeWidget = ({ question, values, siblings, currentSet, disabled,
createValue, updateValue, deleteValue, copyValue }) => {

const handleCreateValue = (value) => {
initRange(question, value)
Expand Down Expand Up @@ -47,7 +49,7 @@ const RangeWidget = ({ question, values, currentSet, disabled, createValue, upda
disabled={disabled}
deleteValue={deleteValue}
/>
<QuestionCopyValue question={question} value={value} copyValue={copyValue} />
<QuestionCopyValue question={question} value={value} siblings={siblings} copyValue={copyValue} />
<QuestionDefault question={question} value={value} />
</div>
}
Expand All @@ -65,13 +67,20 @@ const RangeWidget = ({ question, values, currentSet, disabled, createValue, upda
createValue={handleCreateValue}
copyValue={copyValue}
/>
<QuestionCopyValues
question={question}
values={values}
siblings={siblings}
copyValue={copyValue}
/>
</div>
)
}

RangeWidget.propTypes = {
question: PropTypes.object.isRequired,
values: PropTypes.array.isRequired,
siblings: PropTypes.array,
disabled: PropTypes.bool,
currentSet: PropTypes.object.isRequired,
createValue: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { gatherOptions } from '../../../utils/options'

import QuestionAddValue from '../question/QuestionAddValue'
import QuestionCopyValue from '../question/QuestionCopyValue'
import QuestionCopyValues from '../question/QuestionCopyValues'
import QuestionDefault from '../question/QuestionDefault'
import QuestionEraseValue from '../question/QuestionEraseValue'
import QuestionError from '../question/QuestionError'
Expand All @@ -13,7 +14,7 @@ import QuestionRemoveValue from '../question/QuestionRemoveValue'

import SelectInput from './SelectInput'

const SelectWidget = ({ question, values, currentSet, disabled, creatable,
const SelectWidget = ({ question, values, siblings, currentSet, disabled, creatable,
createValue, updateValue, deleteValue, copyValue }) => {
return (
<div className="interview-widgets">
Expand All @@ -39,7 +40,7 @@ const SelectWidget = ({ question, values, currentSet, disabled, creatable,
disabled={disabled}
deleteValue={deleteValue}
/>
<QuestionCopyValue question={question} value={value} copyValue={copyValue} />
<QuestionCopyValue question={question} value={value} siblings={siblings} copyValue={copyValue} />
<QuestionDefault question={question} value={value} />
</div>
}
Expand All @@ -56,13 +57,20 @@ const SelectWidget = ({ question, values, currentSet, disabled, creatable,
disabled={disabled}
createValue={createValue}
/>
<QuestionCopyValues
question={question}
values={values}
siblings={siblings}
copyValue={copyValue}
/>
</div>
)
}

SelectWidget.propTypes = {
question: PropTypes.object.isRequired,
values: PropTypes.array.isRequired,
siblings: PropTypes.array,
disabled: PropTypes.bool,
creatable: PropTypes.bool,
currentSet: PropTypes.object.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import PropTypes from 'prop-types'

import QuestionAddValue from '../question/QuestionAddValue'
import QuestionCopyValue from '../question/QuestionCopyValue'
import QuestionCopyValues from '../question/QuestionCopyValues'
import QuestionDefault from '../question/QuestionDefault'
import QuestionError from '../question/QuestionError'
import QuestionRemoveValue from '../question/QuestionRemoveValue'
import QuestionSuccess from '../question/QuestionSuccess'

import TextInput from './TextInput'

const TextWidget = ({ question, values, currentSet, disabled,
const TextWidget = ({ question, values, siblings, currentSet, disabled,
createValue, updateValue, deleteValue, copyValue }) => {
return (
<div className="interview-widgets">
Expand All @@ -33,7 +34,7 @@ const TextWidget = ({ question, values, currentSet, disabled,
disabled={disabled}
deleteValue={deleteValue}
/>
<QuestionCopyValue question={question} value={value} copyValue={copyValue} />
<QuestionCopyValue question={question} value={value} siblings={siblings} copyValue={copyValue} />
<QuestionDefault question={question} value={value} />
</div>
}
Expand All @@ -50,13 +51,20 @@ const TextWidget = ({ question, values, currentSet, disabled,
disabled={disabled}
createValue={createValue}
/>
<QuestionCopyValues
question={question}
values={values}
siblings={siblings}
copyValue={copyValue}
/>
</div>
)
}

TextWidget.propTypes = {
question: PropTypes.object.isRequired,
values: PropTypes.array.isRequired,
siblings: PropTypes.array,
disabled: PropTypes.bool,
currentSet: PropTypes.object.isRequired,
createValue: PropTypes.func.isRequired,
Expand Down
Loading

0 comments on commit 5c65410

Please sign in to comment.