From 7d1b84c038a1ab998cdf9cb9032a22538a171dce Mon Sep 17 00:00:00 2001 From: rinrub <99617143+rinrub@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:18:51 +0100 Subject: [PATCH 001/342] fix selectors --- src/components/__tests__/enableWhen-spec.tsx | 2 +- src/components/with-common-functions.tsx | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/components/__tests__/enableWhen-spec.tsx b/src/components/__tests__/enableWhen-spec.tsx index b4b5ddf2..3fa9595b 100644 --- a/src/components/__tests__/enableWhen-spec.tsx +++ b/src/components/__tests__/enableWhen-spec.tsx @@ -5,7 +5,7 @@ import thunk from 'redux-thunk'; import { mount } from 'enzyme'; import '../../util/defineFetch'; -import rootReducer from '../../reducers'; +import rootReducer from '../../store/reducers'; import { Questionnaire } from 'fhir/r4'; import { ReferoContainer } from '..'; import { Resources } from '../../util/resources'; diff --git a/src/components/with-common-functions.tsx b/src/components/with-common-functions.tsx index e7c29fce..5c292722 100644 --- a/src/components/with-common-functions.tsx +++ b/src/components/with-common-functions.tsx @@ -22,7 +22,6 @@ import Icon from '@helsenorge/designsystem-react/components/Icons'; import HelpSign from '@helsenorge/designsystem-react/components/Icons/HelpSign'; import { UploadedFile } from '@helsenorge/file-upload/components/dropzone'; -import { FormChild } from '@helsenorge/form/components/form'; import { ValidationProps } from '@helsenorge/form/components/form/validation'; import DeleteButton from './formcomponents/repeat/delete-button'; @@ -61,9 +60,6 @@ export interface Props { enable?: boolean; id?: string; answer?: QuestionnaireResponseItemAnswer | Array; - addFormComponent?: (component: FormChild) => void; - removeFormComponent?: (component: FormChild) => void; - onValidated?: (valid: boolean | undefined) => void; optionalLabel?: string; requiredLabel?: string; validateScriptInjection?: boolean; @@ -295,10 +291,7 @@ export default function withCommonFunctions(WrappedComponent: React.Component containedResources={containedResources} path={createPathForItem(path, item, responseItem, index)} headerTag={getChildHeaderTag(this.props.item, headerTag)} - onValidated={this.props.onValidated} validateScriptInjection={this.props.validateScriptInjection} - addFormComponent={this.props.addFormComponent} - removeFormComponent={this.props.removeFormComponent} optionalLabel={this.props.optionalLabel} requiredLabel={this.props.requiredLabel} showOptionalLabel={this.props.showOptionalLabel} From 66156dc7dbe56ae922c21d70c8d0d616a83d525e Mon Sep 17 00:00:00 2001 From: rinrub <99617143+rinrub@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:21:41 +0200 Subject: [PATCH 002/342] removed validation from components --- package-lock.json | 22 +++++ package.json | 7 +- .../formcomponents/attachment/attachment.tsx | 6 +- .../attachment/attachmenthtml.tsx | 60 ++++++------ .../formcomponents/boolean/boolean.tsx | 63 ++++++------ .../choice-common/autosuggest-view.tsx | 95 +++++++++---------- .../formcomponents/choice/checkbox-view.tsx | 66 ++++++------- .../formcomponents/choice/choice.tsx | 8 +- .../formcomponents/choice/dropdown-view.tsx | 80 ++++++++-------- .../formcomponents/choice/radio-view.tsx | 65 +++++++------ .../formcomponents/choice/slider-view.tsx | 25 +++-- .../formcomponents/date/date-day-input.tsx | 43 ++++----- .../formcomponents/date/date-month-input.tsx | 35 ++++--- .../formcomponents/date/date-time.tsx | 61 ++++++------ .../formcomponents/date/date-year-input.tsx | 33 +++---- src/components/formcomponents/date/date.tsx | 4 +- src/components/formcomponents/date/time.tsx | 59 ++++++------ .../formcomponents/decimal/decimal.tsx | 53 +++++------ .../formcomponents/display/display.tsx | 27 +++--- .../formcomponents/integer/integer.tsx | 86 ++++++++--------- .../open-choice/dropdown-view.tsx | 4 +- .../string/__tests__/string-spec.tsx | 1 - .../formcomponents/string/string.tsx | 10 +- src/components/renderForm.tsx | 17 ---- src/preview/FormFillerPreview.tsx | 2 +- .../skjema/NHN_Testskjema_Bool-nb-NO.json | 1 + .../NHN_Testskjema_Tall-nb-NO-v0.1.json | 1 + src/types/formTypes/commonFormElementProps.ts | 72 ++++++++++++++ src/types/formTypes/formButton.ts | 22 +++++ src/types/formTypes/formInputs.ts | 8 ++ src/types/formTypes/radioGroupOptions.ts | 8 ++ .../formTypes/validationSummaryPlacement.ts | 4 + 32 files changed, 566 insertions(+), 482 deletions(-) create mode 100644 src/preview/skjema/NHN_Testskjema_Bool-nb-NO.json create mode 100644 src/preview/skjema/NHN_Testskjema_Tall-nb-NO-v0.1.json create mode 100644 src/types/formTypes/commonFormElementProps.ts create mode 100644 src/types/formTypes/formButton.ts create mode 100644 src/types/formTypes/formInputs.ts create mode 100644 src/types/formTypes/radioGroupOptions.ts create mode 100644 src/types/formTypes/validationSummaryPlacement.ts diff --git a/package-lock.json b/package-lock.json index b1135cfd..0e0592fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "isomorphic-fetch": "^3.0.0", "marked": "^3.0.8", "react-collapse": "^5.1.1", + "react-hook-form": "^7.51.2", "uuid": "^9.0.0" }, "devDependencies": { @@ -12966,6 +12967,21 @@ "react": ">= 16.8 || 18.0.0" } }, + "node_modules/react-hook-form": { + "version": "7.51.2", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.51.2.tgz", + "integrity": "sha512-y++lwaWjtzDt/XNnyGDQy6goHskFualmDlf+jzEZvjvz6KWDf7EboL7pUvRCzPTJd0EOPpdekYaQLEvvG6m6HA==", + "engines": { + "node": ">=12.22.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/react-hook-form" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17 || ^18" + } + }, "node_modules/react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", @@ -24895,6 +24911,12 @@ "prop-types": "^15.8.1" } }, + "react-hook-form": { + "version": "7.51.2", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.51.2.tgz", + "integrity": "sha512-y++lwaWjtzDt/XNnyGDQy6goHskFualmDlf+jzEZvjvz6KWDf7EboL7pUvRCzPTJd0EOPpdekYaQLEvvG6m6HA==", + "requires": {} + }, "react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", diff --git a/package.json b/package.json index a554e08f..5ee831cd 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "@typescript-eslint/eslint-plugin": "^5.12.0", "@typescript-eslint/parser": "^5.12.0", "@ungap/structured-clone": "^1.2.0", + "@vitejs/plugin-react": "^4.2.1", "@wojtekmaj/enzyme-adapter-react-17": "^0.8.0", "babel-jest": "^27.4.2", "babel-loader": "^8.2.3", @@ -117,6 +118,7 @@ "redux-thunk": "^2.4.2", "resolve": "^1.22.2", "rimraf": "^3.0.2", + "sass": "^1.69.0", "tabbable": "^6.2.0", "typescript": "^4.8.3", "vite": "^4.4.5", @@ -124,9 +126,7 @@ "vite-tsconfig-paths": "^4.2.1", "whatwg-fetch": "^2.0.4", "xml2js": "^0.6.2", - "yargs": "^17.7.2", - "@vitejs/plugin-react": "^4.2.1", - "sass": "^1.69.0" + "yargs": "^17.7.2" }, "dependencies": { "@types/react-collapse": "^5.0.1", @@ -136,6 +136,7 @@ "isomorphic-fetch": "^3.0.0", "marked": "^3.0.8", "react-collapse": "^5.1.1", + "react-hook-form": "^7.51.2", "uuid": "^9.0.0" }, "browserslist": [ diff --git a/src/components/formcomponents/attachment/attachment.tsx b/src/components/formcomponents/attachment/attachment.tsx index 9f489f03..fc485121 100644 --- a/src/components/formcomponents/attachment/attachment.tsx +++ b/src/components/formcomponents/attachment/attachment.tsx @@ -7,7 +7,6 @@ import { ThunkDispatch } from 'redux-thunk'; import { TextMessage } from '../../../types/text-message'; import { UploadedFile } from '@helsenorge/file-upload/components/dropzone'; -import { ValidationProps } from '@helsenorge/form/components/form/validation'; import AttachmentHtml from './attachmenthtml'; import { NewValueAction, newAttachmentAsync, removeAttachmentAsync } from '../../../actions/newValue'; @@ -52,7 +51,7 @@ export interface Props { onRenderMarkdown?: (item: QuestionnaireItem, markdown: string) => string; } -export class AttachmentComponent extends React.Component { +export class AttachmentComponent extends React.Component { onUpload = (files: File[], cb: (success: boolean, errormessage: TextMessage | null, uploadedFile?: UploadedFile) => void): void => { const { uploadAttachment, path, item, onAnswerChange } = this.props; if (uploadAttachment) { @@ -193,7 +192,6 @@ export class AttachmentComponent extends React.Component ); @@ -203,4 +201,4 @@ export class AttachmentComponent extends React.Component = ({ +const attachmentHtml: React.SFC = ({ id, onUpload, onDelete, @@ -65,7 +64,6 @@ const attachmentHtml: React.SFC = ({ minFiles, item, children, - ...other }) => { const getMaxValueBytes = getAttachmentMaxSizeBytesToUse(attachmentMaxFileSize, item); const getMaxValueMBToReplace = convertBytesToMBString(getMaxValueBytes); @@ -74,35 +72,33 @@ const attachmentHtml: React.SFC = ({ return (
- - { - return getErrorMessage(validFileTypes, getMaxValueBytes, getMaxValueMBToReplace, item, errorText, file, resources); - }} - isRequired={isRequired} - wrapperClasses="page_refero__input" - onRequestLink={onRequestAttachmentLink} - helpButton={helpButton} - helpElement={helpElement} - shouldUploadMultiple={multiple} - maxFiles={maxFiles} - minFiles={minFiles} - chooseFilesText={resources?.chooseFilesText} - /> - + { + return getErrorMessage(validFileTypes, getMaxValueBytes, getMaxValueMBToReplace, item, errorText, file, resources); + }} + isRequired={isRequired} + wrapperClasses="page_refero__input" + onRequestLink={onRequestAttachmentLink} + helpButton={helpButton} + helpElement={helpElement} + shouldUploadMultiple={multiple} + maxFiles={maxFiles} + minFiles={minFiles} + chooseFilesText={resources?.chooseFilesText} + /> {attachmentErrorMessage && {attachmentErrorMessage}} {children ?
{children}
: null}
diff --git a/src/components/formcomponents/boolean/boolean.tsx b/src/components/formcomponents/boolean/boolean.tsx index ef954053..2217e037 100644 --- a/src/components/formcomponents/boolean/boolean.tsx +++ b/src/components/formcomponents/boolean/boolean.tsx @@ -1,24 +1,27 @@ import * as React from 'react'; -import { QuestionnaireItem, QuestionnaireResponseItemAnswer, QuestionnaireResponseItem, Questionnaire } from 'fhir/r4'; +import { Questionnaire, QuestionnaireItem, QuestionnaireResponseItem, QuestionnaireResponseItemAnswer } from 'fhir/r4'; import { connect } from 'react-redux'; import { ThunkDispatch } from 'redux-thunk'; +import { CommonFormElementProps } from '../../../types/formTypes/commonFormElementProps'; + +import Checkbox from '@helsenorge/designsystem-react/components/Checkbox'; +import FormGroup from '@helsenorge/designsystem-react/components/FormGroup'; +import Label from '@helsenorge/designsystem-react/components/Label'; + import layoutChange from '@helsenorge/core-utils/hoc/layout-change'; import { CheckBox } from '@helsenorge/form/components/checkbox'; -import Validation from '@helsenorge/form/components/form/validation'; -import { ValidationProps } from '@helsenorge/form/components/form/validation'; import Pdf from './pdf'; import { NewValueAction, newBooleanValueAsync } from '../../../actions/newValue'; import { GlobalState } from '../../../reducers'; import { getValidationTextExtension } from '../../../util/extension'; -import { isReadOnly, isRequired, getId } from '../../../util/index'; +import { isReadOnly, isRequired, getId, getText, renderPrefix } from '../../../util/index'; import { mapStateToProps, mergeProps, mapDispatchToProps } from '../../../util/map-props'; import { Path } from '../../../util/refero-core'; import { Resources } from '../../../util/resources'; import withCommonFunctions from '../../with-common-functions'; -import Label from '../label'; export interface Props { item: QuestionnaireItem; @@ -42,7 +45,7 @@ export interface Props { onRenderMarkdown?: (item: QuestionnaireItem, markdown: string) => string; } -class Boolean extends React.Component { +class Boolean extends React.Component { getValue(): boolean { const { item, answer } = this.props; if (answer && answer.valueBoolean !== undefined) { @@ -58,9 +61,10 @@ class Boolean extends React.Component { const { dispatch, promptLoginMessage, onAnswerChange, path, item } = this.props; const newValue = !this.getValue(); if (dispatch) { - dispatch(newBooleanValueAsync(this.props.path, newValue, this.props.item))?.then(newState => - onAnswerChange(newState, path, item, { valueBoolean: newValue } as QuestionnaireResponseItemAnswer) - ); + path && + dispatch(newBooleanValueAsync(path, newValue, this.props.item))?.then( + newState => onAnswerChange && onAnswerChange(newState, path, item, { valueBoolean: newValue } as QuestionnaireResponseItemAnswer) + ); } if (promptLoginMessage) { @@ -68,15 +72,13 @@ class Boolean extends React.Component { } }; - getLabel = (): JSX.Element => { - return ( -