From 3660f8ce34948f5023be40164fa875de19562ee9 Mon Sep 17 00:00:00 2001
From: Jochen Klar
Date: Thu, 1 Aug 2024 13:10:25 +0200
Subject: [PATCH 1/8] Refactor Template to Html component and add
page/questionset/question help templates
---
rdmo/core/assets/js/components/Html.js | 20 +++++++++++++++++++
rdmo/core/assets/js/components/Template.js | 15 --------------
rdmo/core/settings.py | 3 +++
.../js/interview/components/main/Done.js | 4 ++--
.../js/interview/components/main/Errors.js | 4 ++--
.../js/interview/components/main/page/Page.js | 7 ++++---
.../components/main/page/PageHead.js | 9 +++++----
.../components/main/page/PageHelp.js | 15 --------------
.../components/main/question/Question.js | 2 ++
.../main/question/QuestionAddValueHelp.js | 4 ++--
.../components/main/question/QuestionHelp.js | 7 +++----
.../main/question/QuestionHelpTemplate.js | 14 +++++++++++++
.../main/question/QuestionWarning.js | 4 ++--
.../main/questionset/QuestionSet.js | 6 +++++-
.../main/questionset/QuestionSetAddSetHelp.js | 4 ++--
.../main/questionset/QuestionSetHelp.js | 4 +++-
.../questionset/QuestionSetHelpTemplate.js | 14 +++++++++++++
.../main/widget/common/OptionHelp.js | 4 +++-
.../main/widget/common/OptionText.js | 4 +++-
.../interview/components/sidebar/Buttons.js | 4 ++--
.../components/sidebar/Navigation.js | 4 ++--
.../interview/components/sidebar/Overview.js | 4 ++--
.../interview/components/sidebar/Progress.js | 4 ++--
rdmo/projects/assets/scss/interview.scss | 10 ++++++++++
.../projects/project_interview_page_help.html | 0
.../project_interview_question_help.html | 0
.../project_interview_questionset_help.html | 0
27 files changed, 107 insertions(+), 63 deletions(-)
create mode 100644 rdmo/core/assets/js/components/Html.js
delete mode 100644 rdmo/core/assets/js/components/Template.js
delete mode 100644 rdmo/projects/assets/js/interview/components/main/page/PageHelp.js
create mode 100644 rdmo/projects/assets/js/interview/components/main/question/QuestionHelpTemplate.js
create mode 100644 rdmo/projects/assets/js/interview/components/main/questionset/QuestionSetHelpTemplate.js
create mode 100644 rdmo/projects/templates/projects/project_interview_page_help.html
create mode 100644 rdmo/projects/templates/projects/project_interview_question_help.html
create mode 100644 rdmo/projects/templates/projects/project_interview_questionset_help.html
diff --git a/rdmo/core/assets/js/components/Html.js b/rdmo/core/assets/js/components/Html.js
new file mode 100644
index 0000000000..d0f18d4fe0
--- /dev/null
+++ b/rdmo/core/assets/js/components/Html.js
@@ -0,0 +1,20 @@
+import React from 'react'
+import PropTypes from 'prop-types'
+import { isEmpty } from 'lodash'
+
+const Html = ({ html }) => {
+ return !isEmpty(html) && (
+
+ )
+}
+
+Html.defaultProps = {
+ className: ''
+}
+
+Html.propTypes = {
+ className: PropTypes.string,
+ html: PropTypes.string
+}
+
+export default Html
diff --git a/rdmo/core/assets/js/components/Template.js b/rdmo/core/assets/js/components/Template.js
deleted file mode 100644
index 75aaaf90d6..0000000000
--- a/rdmo/core/assets/js/components/Template.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-
-const Template = ({ template }) => {
-
- return (
-
- )
-}
-
-Template.propTypes = {
- template: PropTypes.string.isRequired
-}
-
-export default Template
diff --git a/rdmo/core/settings.py b/rdmo/core/settings.py
index 1ff40524cb..9b1c482ad0 100644
--- a/rdmo/core/settings.py
+++ b/rdmo/core/settings.py
@@ -225,8 +225,11 @@
'projects/project_interview_multiple_values_warning.html',
'projects/project_interview_navigation_help.html',
'projects/project_interview_overview_help.html',
+ 'projects/project_interview_page_help.html',
'projects/project_interview_page_tabs_help.html',
'projects/project_interview_progress_help.html',
+ 'projects/project_interview_question_help.html',
+ 'projects/project_interview_questionset_help.html',
]
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
diff --git a/rdmo/projects/assets/js/interview/components/main/Done.js b/rdmo/projects/assets/js/interview/components/main/Done.js
index 3bd277e28c..7ffe6095bb 100644
--- a/rdmo/projects/assets/js/interview/components/main/Done.js
+++ b/rdmo/projects/assets/js/interview/components/main/Done.js
@@ -5,7 +5,7 @@ import baseUrl from 'rdmo/core/assets/js/utils/baseUrl'
import projectId from '../../utils/projectId'
-import Template from 'rdmo/core/assets/js/components/Template'
+import Html from 'rdmo/core/assets/js/components/Html'
const Done = ({ templates }) => {
@@ -14,7 +14,7 @@ const Done = ({ templates }) => {
return (
<>
-
+
{gettext('View answers')}
diff --git a/rdmo/projects/assets/js/interview/components/main/Errors.js b/rdmo/projects/assets/js/interview/components/main/Errors.js
index d10ac5c776..3b34bc57e7 100644
--- a/rdmo/projects/assets/js/interview/components/main/Errors.js
+++ b/rdmo/projects/assets/js/interview/components/main/Errors.js
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import baseUrl from 'rdmo/core/assets/js/utils/baseUrl'
-import Template from 'rdmo/core/assets/js/components/Template'
+import Html from 'rdmo/core/assets/js/components/Html'
import projectId from '../../utils/projectId'
@@ -12,7 +12,7 @@ const Errors = ({ templates, errors }) => {
return (
<>
-
+
{
diff --git a/rdmo/projects/assets/js/interview/components/main/page/Page.js b/rdmo/projects/assets/js/interview/components/main/page/Page.js
index f8c87e8fe7..8a6155c8cf 100644
--- a/rdmo/projects/assets/js/interview/components/main/page/Page.js
+++ b/rdmo/projects/assets/js/interview/components/main/page/Page.js
@@ -3,12 +3,13 @@ import PropTypes from 'prop-types'
import get from 'lodash/get'
import { isNil } from 'lodash'
+import Html from 'rdmo/core/assets/js/components/Html'
+
import Question from '../question/Question'
import QuestionSet from '../questionset/QuestionSet'
import PageButtons from './PageButtons'
import PageHead from './PageHead'
-import PageHelp from './PageHelp'
const Page = ({ config, templates, overview, page, sets, values, fetchPage,
createValue, updateValue, deleteValue,
@@ -24,10 +25,10 @@ const Page = ({ config, templates, overview, page, sets, values, fetchPage,
return (
(set.set_prefix == currentSetPrefix))}
values={isNil(page.attribute) ? [] : values.filter((value) => (value.attribute == page.attribute))}
currentSet={currentSet}
diff --git a/rdmo/projects/assets/js/interview/components/main/page/PageHead.js b/rdmo/projects/assets/js/interview/components/main/page/PageHead.js
index 29776e8340..abd1f336f8 100644
--- a/rdmo/projects/assets/js/interview/components/main/page/PageHead.js
+++ b/rdmo/projects/assets/js/interview/components/main/page/PageHead.js
@@ -3,13 +3,13 @@ import PropTypes from 'prop-types'
import classNames from 'classnames'
import { capitalize, isNil, last } from 'lodash'
-import Template from 'rdmo/core/assets/js/components/Template'
+import Html from 'rdmo/core/assets/js/components/Html'
import useModal from 'rdmo/core/assets/js/hooks/useModal'
import PageHeadDeleteModal from './PageHeadDeleteModal'
import PageHeadFormModal from './PageHeadFormModal'
-const PageHead = ({ page, help, sets, values, currentSet, activateSet, createSet, updateSet, deleteSet }) => {
+const PageHead = ({ templates, page, sets, values, currentSet, activateSet, createSet, updateSet, deleteSet }) => {
const currentSetValue = isNil(currentSet) ? null : (
values.find((value) => (
@@ -50,7 +50,8 @@ const PageHead = ({ page, help, sets, values, currentSet, activateSet, createSet
return page.is_collection && (
-
+
+
{
currentSet ? (
<>
@@ -120,8 +121,8 @@ const PageHead = ({ page, help, sets, values, currentSet, activateSet, createSet
}
PageHead.propTypes = {
+ templates: PropTypes.object.isRequired,
page: PropTypes.object.isRequired,
- help: PropTypes.string.isRequired,
sets: PropTypes.array.isRequired,
values: PropTypes.array.isRequired,
currentSet: PropTypes.object,
diff --git a/rdmo/projects/assets/js/interview/components/main/page/PageHelp.js b/rdmo/projects/assets/js/interview/components/main/page/PageHelp.js
deleted file mode 100644
index b6f197d5f2..0000000000
--- a/rdmo/projects/assets/js/interview/components/main/page/PageHelp.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import { isEmpty } from 'lodash'
-
-const PageHelp = ({ page }) => {
- return !isEmpty(page.help) && (
-
- )
-}
-
-PageHelp.propTypes = {
- page: PropTypes.object.isRequired
-}
-
-export default PageHelp
diff --git a/rdmo/projects/assets/js/interview/components/main/question/Question.js b/rdmo/projects/assets/js/interview/components/main/question/Question.js
index 651cb4e262..cea3c70ff4 100644
--- a/rdmo/projects/assets/js/interview/components/main/question/Question.js
+++ b/rdmo/projects/assets/js/interview/components/main/question/Question.js
@@ -5,6 +5,7 @@ import { checkQuestion } from '../../../utils/page'
import QuestionAddValueHelp from './QuestionAddValueHelp'
import QuestionHelp from './QuestionHelp'
+import QuestionHelpTemplate from './QuestionHelpTemplate'
import QuestionManagement from './QuestionManagement'
import QuestionOptional from './QuestionOptional'
import QuestionText from './QuestionText'
@@ -18,6 +19,7 @@ const Question = ({ templates, question, values, disabled, isManager,
+
diff --git a/rdmo/projects/assets/js/interview/components/main/question/QuestionAddValueHelp.js b/rdmo/projects/assets/js/interview/components/main/question/QuestionAddValueHelp.js
index 47912e57bf..8a6428ee32 100644
--- a/rdmo/projects/assets/js/interview/components/main/question/QuestionAddValueHelp.js
+++ b/rdmo/projects/assets/js/interview/components/main/question/QuestionAddValueHelp.js
@@ -1,11 +1,11 @@
import React from 'react'
import PropTypes from 'prop-types'
-import Template from 'rdmo/core/assets/js/components/Template'
+import Html from 'rdmo/core/assets/js/components/Html'
const QuestionAddValueHelp = ({ templates, question }) => {
return question.is_collection && (
-
+
)
}
diff --git a/rdmo/projects/assets/js/interview/components/main/question/QuestionHelp.js b/rdmo/projects/assets/js/interview/components/main/question/QuestionHelp.js
index 620e560b6a..eec017251a 100644
--- a/rdmo/projects/assets/js/interview/components/main/question/QuestionHelp.js
+++ b/rdmo/projects/assets/js/interview/components/main/question/QuestionHelp.js
@@ -1,7 +1,8 @@
import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
-import { isEmpty } from 'lodash'
+
+import Html from 'rdmo/core/assets/js/components/Html'
const QuestionHelp = ({ question }) => {
const classnames = classNames({
@@ -9,9 +10,7 @@ const QuestionHelp = ({ question }) => {
'text-muted': question.is_optional
})
- return !isEmpty(question.help) && (
-
- )
+ return