@openmrs/esm-form-engine-lib 4.1.1-pre.2348 → 4.1.1-pre.2357
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/dist/components/repeat/helpers.d.ts.map +1 -1
- package/dist/components/repeat/helpers.js +8 -7
- package/dist/components/repeat/repeat.component.d.ts.map +1 -1
- package/dist/components/repeat/repeat.component.js +5 -6
- package/package.json +1 -1
- package/src/components/repeat/helpers.ts +12 -7
- package/src/components/repeat/repeat.component.tsx +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/components/repeat/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAoD7F;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/components/repeat/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAoD7F;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAajG;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,WAM7E"}
|
|
@@ -45,15 +45,16 @@ export function cloneRepeatField(srcField, value, idSuffix) {
|
|
|
45
45
|
return clonedField;
|
|
46
46
|
}
|
|
47
47
|
export function updateFieldIdInExpression(expression, index, questionIds) {
|
|
48
|
-
|
|
48
|
+
const uniqueQuestionIds = [
|
|
49
49
|
...new Set(questionIds)
|
|
50
50
|
];
|
|
51
|
-
uniqueQuestionIds.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
if (!uniqueQuestionIds.length) {
|
|
52
|
+
return expression;
|
|
53
|
+
}
|
|
54
|
+
// Sort by length desc so longer ids are tried before their shorter prefixes (e.g. `status_code` before `status`).
|
|
55
|
+
// Word boundaries keep the match from landing inside a longer identifier; regex metachars in ids are escaped.
|
|
56
|
+
const pattern = uniqueQuestionIds.slice().sort((a, b)=>b.length - a.length).map((id)=>id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
|
|
57
|
+
return expression.replace(new RegExp(`\\b(?:${pattern})\\b`, 'g'), (match)=>`${match}_${index}`);
|
|
57
58
|
}
|
|
58
59
|
export function disableRepeatAddButton(limit, counter) {
|
|
59
60
|
const repeatLimit = Number(limit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeat.component.d.ts","sourceRoot":"","sources":["../../../src/components/repeat/repeat.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"repeat.component.d.ts","sourceRoot":"","sources":["../../../src/components/repeat/repeat.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAa,mBAAmB,EAAc,MAAM,aAAa,CAAC;AAkB9E,QAAA,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAwKzC,CAAC;AAmBF,eAAe,MAAM,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { useTranslation } from "react-i18next";
|
|
3
2
|
import { evaluateAsyncExpression, evaluateExpression } from "../../utils/expression-runner.js";
|
|
4
3
|
import { isEmpty } from "../../validators/form-validator.js";
|
|
5
4
|
import styles from "./repeat.scss";
|
|
@@ -16,15 +15,11 @@ const renderingByTypeMap = {
|
|
|
16
15
|
diagnosis: 'ui-select-extended'
|
|
17
16
|
};
|
|
18
17
|
const Repeat = ({ field })=>{
|
|
19
|
-
const { t } = useTranslation();
|
|
20
|
-
const isGrouped = useMemo(()=>field.questions?.length > 1, [
|
|
21
|
-
field
|
|
22
|
-
]);
|
|
23
18
|
const [counter, setCounter] = useState(0);
|
|
24
19
|
const [rows, setRows] = useState([]);
|
|
25
20
|
const context = useFormProviderContext();
|
|
26
21
|
const { handleConfirmQuestionDeletion } = useFormFactory();
|
|
27
|
-
const { patient, sessionMode, formFieldAdapters, formFields, methods: { getValues, setValue }, addFormField, removeFormField, deletedFields, setDeletedFields, visit } = context;
|
|
22
|
+
const { patient, sessionMode, formFieldAdapters, formFields, methods: { getValues, setValue, unregister }, addFormField, removeFormField, deletedFields, setDeletedFields, visit } = context;
|
|
28
23
|
useEffect(()=>{
|
|
29
24
|
const repeatedFields = formFields.filter((_field)=>_field.questionOptions.concept === field.questionOptions.concept && _field.id.startsWith(field.id) && !_field.meta?.repeat?.wasDeleted);
|
|
30
25
|
setCounter(repeatedFields.length - 1);
|
|
@@ -108,6 +103,10 @@ const Repeat = ({ field })=>{
|
|
|
108
103
|
}
|
|
109
104
|
} else {
|
|
110
105
|
clearSubmission(field);
|
|
106
|
+
// Unregister from react-hook-form so a re-added row with the same id
|
|
107
|
+
// starts empty instead of rehydrating the deleted row's value.
|
|
108
|
+
unregister(field.id);
|
|
109
|
+
field.questions?.forEach((child)=>unregister(child.id));
|
|
111
110
|
}
|
|
112
111
|
setRows(rows.filter((q)=>q.id !== field.id));
|
|
113
112
|
setDeletedFields([
|
package/package.json
CHANGED
|
@@ -59,13 +59,18 @@ export function cloneRepeatField(srcField: FormField, value: OpenmrsResource, id
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export function updateFieldIdInExpression(expression: string, index: number, questionIds: string[]) {
|
|
62
|
-
|
|
63
|
-
uniqueQuestionIds.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const uniqueQuestionIds = [...new Set(questionIds)];
|
|
63
|
+
if (!uniqueQuestionIds.length) {
|
|
64
|
+
return expression;
|
|
65
|
+
}
|
|
66
|
+
// Sort by length desc so longer ids are tried before their shorter prefixes (e.g. `status_code` before `status`).
|
|
67
|
+
// Word boundaries keep the match from landing inside a longer identifier; regex metachars in ids are escaped.
|
|
68
|
+
const pattern = uniqueQuestionIds
|
|
69
|
+
.slice()
|
|
70
|
+
.sort((a, b) => b.length - a.length)
|
|
71
|
+
.map((id) => id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
|
|
72
|
+
.join('|');
|
|
73
|
+
return expression.replace(new RegExp(`\\b(?:${pattern})\\b`, 'g'), (match) => `${match}_${index}`);
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
export function disableRepeatAddButton(limit: string | number, counter: number) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { useTranslation } from 'react-i18next';
|
|
3
2
|
import type { FormField, FormFieldInputProps, RenderType } from '../../types';
|
|
4
3
|
import { evaluateAsyncExpression, evaluateExpression } from '../../utils/expression-runner';
|
|
5
4
|
import { isEmpty } from '../../validators/form-validator';
|
|
@@ -19,8 +18,6 @@ const renderingByTypeMap: Record<string, RenderType> = {
|
|
|
19
18
|
};
|
|
20
19
|
|
|
21
20
|
const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
22
|
-
const { t } = useTranslation();
|
|
23
|
-
const isGrouped = useMemo(() => field.questions?.length > 1, [field]);
|
|
24
21
|
const [counter, setCounter] = useState(0);
|
|
25
22
|
const [rows, setRows] = useState([]);
|
|
26
23
|
const context = useFormProviderContext();
|
|
@@ -30,7 +27,7 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
|
30
27
|
sessionMode,
|
|
31
28
|
formFieldAdapters,
|
|
32
29
|
formFields,
|
|
33
|
-
methods: { getValues, setValue },
|
|
30
|
+
methods: { getValues, setValue, unregister },
|
|
34
31
|
addFormField,
|
|
35
32
|
removeFormField,
|
|
36
33
|
deletedFields,
|
|
@@ -117,6 +114,10 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
|
117
114
|
}
|
|
118
115
|
} else {
|
|
119
116
|
clearSubmission(field);
|
|
117
|
+
// Unregister from react-hook-form so a re-added row with the same id
|
|
118
|
+
// starts empty instead of rehydrating the deleted row's value.
|
|
119
|
+
unregister(field.id);
|
|
120
|
+
field.questions?.forEach((child) => unregister(child.id));
|
|
120
121
|
}
|
|
121
122
|
setRows(rows.filter((q) => q.id !== field.id));
|
|
122
123
|
setDeletedFields([...deletedFields, field]);
|