@openmrs/esm-form-engine-lib 2.1.0-pre.1393 → 2.1.0-pre.1401

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-form-engine-lib",
3
- "version": "2.1.0-pre.1393",
3
+ "version": "2.1.0-pre.1401",
4
4
  "description": "React Form Engine for O3",
5
5
  "browser": "dist/openmrs-esm-form-engine-lib.js",
6
6
  "main": "src/index.ts",
@@ -16,7 +16,7 @@ export const ObsGroup: React.FC<FormFieldInputProps> = ({ field }) => {
16
16
  return (
17
17
  <div className={classNames(styles.flexColumn)} key={keyId}>
18
18
  <div className={styles.groupContainer}>
19
- <FormFieldRenderer field={child} valueAdapter={formFieldAdapters[child.type]} />
19
+ <FormFieldRenderer fieldId={child.id} valueAdapter={formFieldAdapters[child.type]} />
20
20
  </div>
21
21
  </div>
22
22
  );
@@ -23,12 +23,14 @@ const WorkspaceLauncher: React.FC<FormFieldInputProps> = ({ field }) => {
23
23
  };
24
24
 
25
25
  return (
26
- <div>
27
- <div className={styles.label}>{t(field.label)}</div>
28
- <div className={styles.workspaceButton}>
29
- <Button onClick={handleLaunchWorkspace}>{field.questionOptions?.buttonLabel ?? t('launchWorkspace')}</Button>
26
+ !field.isHidden && (
27
+ <div>
28
+ <div className={styles.label}>{t(field.label)}</div>
29
+ <div className={styles.workspaceButton}>
30
+ <Button onClick={handleLaunchWorkspace}>{field.questionOptions?.buttonLabel ?? t('launchWorkspace')}</Button>
31
+ </div>
30
32
  </div>
31
- </div>
33
+ )
32
34
  );
33
35
  };
34
36
 
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useMemo, useState } from 'react';
2
2
  import {
3
3
  type FormField,
4
4
  type RenderType,
@@ -24,14 +24,14 @@ import { getFieldControlWithFallback } from '../../../utils/form-helper';
24
24
  import { handleFieldLogic } from './fieldLogic';
25
25
 
26
26
  export interface FormFieldRendererProps {
27
- field: FormField;
27
+ fieldId: string;
28
28
  valueAdapter: FormFieldValueAdapter;
29
29
  repeatOptions?: {
30
30
  targetRendering: RenderType;
31
31
  };
32
32
  }
33
33
 
34
- export const FormFieldRenderer = ({ field, valueAdapter, repeatOptions }: FormFieldRendererProps) => {
34
+ export const FormFieldRenderer = ({ fieldId, valueAdapter, repeatOptions }: FormFieldRendererProps) => {
35
35
  const [inputComponentWrapper, setInputComponentWrapper] = useState<{
36
36
  value: React.ComponentType<FormFieldInputProps>;
37
37
  }>(null);
@@ -50,9 +50,11 @@ export const FormFieldRenderer = ({ field, valueAdapter, repeatOptions }: FormFi
50
50
  removeInvalidField,
51
51
  } = context;
52
52
 
53
- const fieldValue = useWatch({ control, name: field.id, exact: true });
53
+ const fieldValue = useWatch({ control, name: fieldId, exact: true });
54
54
  const noop = () => {};
55
55
 
56
+ const field = useMemo(() => formFields.find((field) => field.id === fieldId), [fieldId, formFields]);
57
+
56
58
  useEffect(() => {
57
59
  if (hasRendering(field, 'repeating') && repeatOptions?.targetRendering) {
58
60
  getRegisteredControl(repeatOptions.targetRendering).then((component) => {
@@ -12,7 +12,11 @@ export const SectionRenderer = ({ section }: { section: FormSection }) => {
12
12
  {section.questions.map((question) =>
13
13
  formFieldAdapters[question.type] ? (
14
14
  <div key={`${sectionId}-${question.id}`} className={styles.sectionBody}>
15
- <FormFieldRenderer key={question.id} field={question} valueAdapter={formFieldAdapters[question.type]} />
15
+ <FormFieldRenderer
16
+ key={question.id}
17
+ fieldId={question.id}
18
+ valueAdapter={formFieldAdapters[question.type]}
19
+ />
16
20
  </div>
17
21
  ) : null,
18
22
  )}
@@ -129,7 +129,7 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
129
129
  return rows.map((field, index) => {
130
130
  const component = (
131
131
  <FormFieldRenderer
132
- field={field}
132
+ fieldId={field.id}
133
133
  valueAdapter={formFieldAdapters[field.type]}
134
134
  repeatOptions={{ targetRendering: getQuestionWithSupportedRendering(field).questionOptions.rendering }}
135
135
  />
@@ -7,7 +7,7 @@ export function useFormStateHelpers(dispatch: Dispatch<Action>, formFields: Form
7
7
  dispatch({ type: 'ADD_FORM_FIELD', value: field });
8
8
  }, []);
9
9
  const updateFormField = useCallback((field: FormField) => {
10
- dispatch({ type: 'UPDATE_FORM_FIELD', value: field });
10
+ dispatch({ type: 'UPDATE_FORM_FIELD', value: structuredClone(field) });
11
11
  }, []);
12
12
 
13
13
  const getFormField = useCallback(