diff --git a/.eslintignore b/.eslintignore index 70f565b8..2b80a521 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,4 @@ **/dist/* **/node_modules/* **/*.d.tsx -__mocks__/* +__mocks__/* \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 5e5f95b8..8cee2aff 100644 --- a/.eslintrc +++ b/.eslintrc @@ -20,6 +20,7 @@ "rules": { "react-hooks/exhaustive-deps": "warn", "react-hooks/rules-of-hooks": "error", + "@typescript-eslint/no-explicit-any": "off", // not hugely concerned about accidental implicit type coercions for now https://typescript-eslint.io/rules/no-base-to-string "@typescript-eslint/no-base-to-string": "off", // The following rules need `noImplicitAny` to be set to `true` in our tsconfig. They are too restrictive for now, but should be reconsidered in future diff --git a/__mocks__/react-markdown.tsx b/__mocks__/react-markdown.tsx new file mode 100644 index 00000000..430fb008 --- /dev/null +++ b/__mocks__/react-markdown.tsx @@ -0,0 +1,5 @@ +import React from 'react'; + +export default function ({ children }) { + return <>{children}; +} diff --git a/jest.config.js b/jest.config.js index 2aeb643a..bba5829e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -14,6 +14,7 @@ module.exports = { 'lodash-es': 'lodash', '^dexie$': '/node_modules/dexie', '^react-i18next$': '/__mocks__/react-i18next.js', + 'react-markdown': '/__mocks__/react-markdown.tsx', }, setupFilesAfterEnv: ['/src/setup-tests.ts'], testEnvironment: 'jsdom', diff --git a/package.json b/package.json index cdd374f5..ccc65e51 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,8 @@ "fuzzy": "^0.1.3", "lodash-es": "^4.17.21", "react-ace": "^11.0.1", + "react-markdown": "^9.0.1", + "react-mde": "^11.5.0", "sass": "^1.67.0" }, "peerDependencies": { diff --git a/src/components/interactive-builder/add-question.modal.tsx b/src/components/interactive-builder/add-question.modal.tsx index 031a64a1..8a9fae65 100644 --- a/src/components/interactive-builder/add-question.modal.tsx +++ b/src/components/interactive-builder/add-question.modal.tsx @@ -47,6 +47,7 @@ import { useConceptLookup } from '../../hooks/useConceptLookup'; import { usePatientIdentifierTypes } from '../../hooks/usePatientIdentifierTypes'; import { usePersonAttributeTypes } from '../../hooks/usePersonAttributeTypes'; import { useProgramWorkStates, usePrograms } from '../../hooks/useProgramStates'; +import MarkdownQuestion from './markdown-question.component'; import styles from './question-modal.scss'; interface AddQuestionModalProps { @@ -108,6 +109,7 @@ const AddQuestionModal: React.FC = ({ const [min, setMin] = useState(''); const [questionId, setQuestionId] = useState(''); const [questionLabel, setQuestionLabel] = useState(''); + const [questionValue, setQuestionValue] = useState(''); const [questionType, setQuestionType] = useState(null); const [rows, setRows] = useState(''); const [selectedAnswers, setSelectedAnswers] = useState< @@ -136,7 +138,6 @@ const AddQuestionModal: React.FC = ({ const [toggleLabelFalse, setToggleLabelFalse] = useState(''); const renderTypeOptions = { - control: ['text'], encounterDatetime: ['date'], encounterLocation: ['ui-select-extended'], encounterProvider: ['ui-select-extended'], @@ -211,8 +212,9 @@ const AddQuestionModal: React.FC = ({ const computedQuestionId = `question${questionIndex + 1}Section${sectionIndex + 1}Page-${pageIndex + 1}`; const newQuestion = { - label: questionLabel, - type: questionType, + ...(questionLabel && {label: questionLabel}), + ...((renderingType === 'markdown') && {value: questionValue}), + type: questionType ? questionType : 'control', required: isQuestionRequired, id: questionId ?? computedQuestionId, ...((renderingType === 'date' || renderingType === 'datetime') && @@ -322,14 +324,15 @@ const AddQuestionModal: React.FC = ({ - : ( + } placeholder={t('labelPlaceholder', 'e.g. Type of Anaesthesia')} value={questionLabel} onChange={(event: React.ChangeEvent) => setQuestionLabel(event.target.value)} - required /> + )} = ({ required /> - - setIsQuestionRequired(false)} - value="optional" - /> - setIsQuestionRequired(true)} - value="required" - /> - - - + {renderingType !== 'markdown' && ( + <> + + setIsQuestionRequired(false)} + value="optional" + /> + setIsQuestionRequired(true)} + value="required" + /> + + + + )} {questionType === 'personAttribute' && ( @@ -860,7 +867,6 @@ const AddQuestionModal: React.FC = ({