Skip to content

Commit

Permalink
Add copy_set function to question sets
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Aug 20, 2024
1 parent 5a241cc commit cdb35a2
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 19 deletions.
10 changes: 7 additions & 3 deletions rdmo/core/assets/js/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ const Modal = ({ title, show, bsSize, submitText, submitColor, disableSubmit,
<BootstrapModal.Header closeButton>
<h2 className="modal-title">{title}</h2>
</BootstrapModal.Header>
<BootstrapModal.Body>
{ children }
</BootstrapModal.Body>
{
children && (
<BootstrapModal.Body>
{ children }
</BootstrapModal.Body>
)
}
<BootstrapModal.Footer>
<button type="button" className="btn btn-default" onClick={onClose}>
{gettext('Close')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const Page = ({ config, templates, overview, page, sets, values, fetchPage,
createSet={createSet}
updateSet={updateSet}
deleteSet={deleteSet}
copySet={copySet}
createValue={createValue}
updateValue={updateValue}
deleteValue={deleteValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import Question from '../question/Question'

import QuestionSetAddSet from './QuestionSetAddSet'
import QuestionSetAddSetHelp from './QuestionSetAddSetHelp'
import QuestionSetCopySet from './QuestionSetCopySet'
import QuestionSetHelp from './QuestionSetHelp'
import QuestionSetHelpTemplate from './QuestionSetHelpTemplate'
import QuestionSetRemoveSet from './QuestionSetRemoveSet'

const QuestionSet = ({ templates, questionset, sets, values, disabled, isManager,
parentSet, createSet, updateSet, deleteSet,
parentSet, createSet, updateSet, deleteSet, copySet,
createValue, updateValue, deleteValue, copyValue }) => {

const setPrefix = getChildPrefix(parentSet)
Expand All @@ -35,7 +36,8 @@ const QuestionSet = ({ templates, questionset, sets, values, disabled, isManager
currentSets.map((set, setIndex) => (
<div key={setIndex} className="interview-block">
<div className="interview-block-options">
<QuestionSetRemoveSet questionset={questionset} set={set} deleteSet={deleteSet} />
<QuestionSetCopySet questionset={questionset} sets={sets} currentSet={set} copySet={copySet} />
<QuestionSetRemoveSet questionset={questionset} currentSet={set} deleteSet={deleteSet} />
</div>
<div className="row">
{
Expand All @@ -55,6 +57,7 @@ const QuestionSet = ({ templates, questionset, sets, values, disabled, isManager
createSet={createSet}
updateSet={updateSet}
deleteSet={deleteSet}
copySet={copySet}
createValue={createValue}
updateValue={updateValue}
deleteValue={deleteValue}
Expand Down Expand Up @@ -107,6 +110,7 @@ QuestionSet.propTypes = {
createSet: PropTypes.func.isRequired,
updateSet: PropTypes.func.isRequired,
deleteSet: PropTypes.func.isRequired,
copySet: PropTypes.func.isRequired,
createValue: PropTypes.func.isRequired,
updateValue: PropTypes.func.isRequired,
deleteValue: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import PropTypes from 'prop-types'

import Modal from 'rdmo/core/assets/js/components/Modal'

const QuestionSetCopyModal = ({ title, show, onClose, onSubmit }) => {
return (
<Modal title={title} show={show} submitText={gettext('Copy')} submitColor="info"
onClose={onClose} onSubmit={onSubmit}>
</Modal>
)
}

QuestionSetCopyModal.propTypes = {
title: PropTypes.string.isRequired,
show: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
onSubmit: PropTypes.func.isRequired,
}

export default QuestionSetCopyModal
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'
import PropTypes from 'prop-types'
import { capitalize, last } from 'lodash'

import useModal from 'rdmo/core/assets/js/hooks/useModal'

import QuestionSetCopyModal from './QuestionSetCopyModal'

const QuestionCopySet = ({ questionset, sets, currentSet, copySet }) => {

const [showCopyModal, openCopyModal, closeCopyModal] = useModal()

const handleCopySet = () => {
copySet(currentSet, null, {
set_prefix: currentSet.set_prefix,
set_index: last(sets) ? last(sets).set_index + 1 : 0,
})
closeCopyModal()
}

return questionset.is_collection && (
<>
<button type="button" className="btn btn-link btn-copy-set" onClick={openCopyModal}>
<i className="fa fa-copy fa-btn"></i>
</button>

<QuestionSetCopyModal
title={capitalize(questionset.verbose_name)}
show={showCopyModal}
onClose={closeCopyModal}
onSubmit={handleCopySet}
/>
</>
)
}

QuestionCopySet.propTypes = {
questionset: PropTypes.object.isRequired,
sets: PropTypes.array.isRequired,
currentSet: PropTypes.object.isRequired,
copySet: PropTypes.func.isRequired
}

export default QuestionCopySet
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import useModal from 'rdmo/core/assets/js/hooks/useModal'

import QuestionSetDeleteModal from './QuestionSetDeleteModal'

const QuestionAddSet = ({ questionset, set, deleteSet }) => {
const QuestionRemoveSet = ({ questionset, currentSet, deleteSet }) => {

const [showDeleteModal, openDeleteModal, closeDeleteModal] = useModal()

const handleDeleteSet = () => {
deleteSet(set)
deleteSet(currentSet)
closeDeleteModal()
}

Expand All @@ -31,10 +31,10 @@ const QuestionAddSet = ({ questionset, set, deleteSet }) => {
)
}

QuestionAddSet.propTypes = {
QuestionRemoveSet.propTypes = {
questionset: PropTypes.object.isRequired,
set: PropTypes.object.isRequired,
currentSet: PropTypes.object.isRequired,
deleteSet: PropTypes.func.isRequired
}

export default QuestionAddSet
export default QuestionRemoveSet
16 changes: 7 additions & 9 deletions rdmo/projects/assets/scss/interview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,20 @@

.interview-block-options {
position: absolute;
top: 0;
right: 0;
top: 6px;
right: 8px;
z-index: 5;

display: flex;
gap: 4px;

.btn-copy-set,
.btn-remove-set {
opacity: 0.8;
line-height: 20px;
font-size: 14px;

position: absolute;
z-index: 5;
top: 0;
right: 0;

padding-left: 8px;
padding-right: 8px;
padding: 0;

&:hover {
opacity: 1;
Expand Down

0 comments on commit cdb35a2

Please sign in to comment.