@openmrs/esm-form-engine-lib 3.1.5-pre.1998 → 3.1.5-pre.2004
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/openmrs-esm-form-engine-lib.js +1 -1
- package/package.json +1 -1
- package/src/components/renderer/field/fieldRenderUtils.test.ts +39 -0
- package/src/components/renderer/field/fieldRenderUtils.ts +10 -0
- package/src/components/renderer/field/form-field-renderer.component.tsx +8 -0
- package/src/types/schema.ts +8 -1
- package/src/utils/forms-loader.ts +9 -9
@@ -1 +1 @@
|
|
1
|
-
var _openmrs_esm_form_engine_lib;(()=>{"use strict";var e,r,t,n,o,i,a,l,s,u,f,p,d,c,h,m,v,g,b,y,w,_={78008:(e,r,t)=>{var n={"./start":()=>Promise.all([t.e(177),t.e(381),t.e(58),t.e(72),t.e(985),t.e(
|
1
|
+
var _openmrs_esm_form_engine_lib;(()=>{"use strict";var e,r,t,n,o,i,a,l,s,u,f,p,d,c,h,m,v,g,b,y,w,_={78008:(e,r,t)=>{var n={"./start":()=>Promise.all([t.e(177),t.e(381),t.e(58),t.e(72),t.e(985),t.e(141)]).then((()=>()=>t(99141)))},o=(e,r)=>(t.R=r,r=t.o(n,e)?n[e]():Promise.resolve().then((()=>{throw new Error('Module "'+e+'" does not exist in container.')})),t.R=void 0,r),i=(e,r)=>{if(t.S){var n="default",o=t.S[n];if(o&&o!==e)throw new Error("Container initialization failed as it has already been initialized with a different share scope");return t.S[n]=e,t.I(n,r)}};t.d(r,{get:()=>o,init:()=>i})}},P={};function j(e){var r=P[e];if(void 0!==r)return r.exports;var t=P[e]={id:e,loaded:!1,exports:{}};return _[e].call(t.exports,t,t.exports,j),t.loaded=!0,t.exports}j.m=_,j.c=P,j.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return j.d(r,{a:r}),r},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,j.t=function(t,n){if(1&n&&(t=this(t)),8&n)return t;if("object"==typeof t&&t){if(4&n&&t.__esModule)return t;if(16&n&&"function"==typeof t.then)return t}var o=Object.create(null);j.r(o);var i={};e=e||[null,r({}),r([]),r(r)];for(var a=2&n&&t;"object"==typeof a&&!~e.indexOf(a);a=r(a))Object.getOwnPropertyNames(a).forEach((e=>i[e]=()=>t[e]));return i.default=()=>t,j.d(o,i),o},j.d=(e,r)=>{for(var t in r)j.o(r,t)&&!j.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},j.f={},j.e=e=>Promise.all(Object.keys(j.f).reduce(((r,t)=>(j.f[t](e,r),r)),[])),j.u=e=>e+".js",j.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),j.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t={},n="@openmrs/esm-form-engine-lib:",j.l=(e,r,o,i)=>{if(t[e])t[e].push(r);else{var a,l;if(void 0!==o)for(var s=document.getElementsByTagName("script"),u=0;u<s.length;u++){var f=s[u];if(f.getAttribute("src")==e||f.getAttribute("data-webpack")==n+o){a=f;break}}a||(l=!0,(a=document.createElement("script")).charset="utf-8",a.timeout=120,j.nc&&a.setAttribute("nonce",j.nc),a.setAttribute("data-webpack",n+o),a.src=e),t[e]=[r];var p=(r,n)=>{a.onerror=a.onload=null,clearTimeout(d);var o=t[e];if(delete t[e],a.parentNode&&a.parentNode.removeChild(a),o&&o.forEach((e=>e(n))),r)return r(n)},d=setTimeout(p.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=p.bind(null,a.onerror),a.onload=p.bind(null,a.onload),l&&document.head.appendChild(a)}},j.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},j.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),j.j=719,(()=>{j.S={};var e={},r={};j.I=(t,n)=>{n||(n=[]);var o=r[t];if(o||(o=r[t]={}),!(n.indexOf(o)>=0)){if(n.push(o),e[t])return e[t];j.o(j.S,t)||(j.S[t]={});var i=j.S[t],a="@openmrs/esm-form-engine-lib",l=(e,r,t,n)=>{var o=i[e]=i[e]||{},l=o[r];(!l||!l.loaded&&(!n!=!l.eager?n:a>l.from))&&(o[r]={get:t,from:a,eager:!!n})},s=[];return"default"===t&&(l("@openmrs/esm-framework","6.3.1-pre.3218",(()=>Promise.all([j.e(177),j.e(657),j.e(381),j.e(43),j.e(72),j.e(766),j.e(985),j.e(561),j.e(942)]).then((()=>()=>j(68043))))),l("@openmrs/esm-patient-common-lib","10.2.1-pre.8354",(()=>Promise.all([j.e(177),j.e(657),j.e(381),j.e(356),j.e(72),j.e(766),j.e(985),j.e(561),j.e(704)]).then((()=>()=>j(5356))))),l("dayjs","1.11.13",(()=>j.e(353).then((()=>()=>j(74353))))),l("i18next","23.16.0",(()=>j.e(635).then((()=>()=>j(72635))))),l("react-i18next","11.18.6",(()=>Promise.all([j.e(72),j.e(414)]).then((()=>()=>j(93414))))),l("react","18.3.1",(()=>j.e(540).then((()=>()=>j(96540))))),l("swr/immutable","2.3.3",(()=>Promise.all([j.e(177),j.e(72),j.e(606)]).then((()=>()=>j(54225))))),l("swr/infinite","2.3.3",(()=>Promise.all([j.e(177),j.e(72),j.e(422)]).then((()=>()=>j(23041)))))),e[t]=s.length?Promise.all(s).then((()=>e[t]=1)):1}}})(),(()=>{var e;j.g.importScripts&&(e=j.g.location+"");var r=j.g.document;if(!e&&r&&(r.currentScript&&"SCRIPT"===r.currentScript.tagName.toUpperCase()&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");if(t.length)for(var n=t.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=t[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),j.p=e})(),o=e=>{var r=e=>e.split(".").map((e=>+e==e?+e:e)),t=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(e),n=t[1]?r(t[1]):[];return t[2]&&(n.length++,n.push.apply(n,r(t[2]))),t[3]&&(n.push([]),n.push.apply(n,r(t[3]))),n},i=(e,r)=>{e=o(e),r=o(r);for(var t=0;;){if(t>=e.length)return t<r.length&&"u"!=(typeof r[t])[0];var n=e[t],i=(typeof n)[0];if(t>=r.length)return"u"==i;var a=r[t],l=(typeof a)[0];if(i!=l)return"o"==i&&"n"==l||"s"==l||"u"==i;if("o"!=i&&"u"!=i&&n!=a)return n<a;t++}},a=e=>{var r=e[0],t="";if(1===e.length)return"*";if(r+.5){t+=0==r?">=":-1==r?"<":1==r?"^":2==r?"~":r>0?"=":"!=";for(var n=1,o=1;o<e.length;o++)n--,t+="u"==(typeof(l=e[o]))[0]?"-":(n>0?".":"")+(n=2,l);return t}var i=[];for(o=1;o<e.length;o++){var l=e[o];i.push(0===l?"not("+s()+")":1===l?"("+s()+" || "+s()+")":2===l?i.pop()+" "+i.pop():a(l))}return s();function s(){return i.pop().replace(/^\((.+)\)$/,"$1")}},l=(e,r)=>{if(0 in e){r=o(r);var t=e[0],n=t<0;n&&(t=-t-1);for(var i=0,a=1,s=!0;;a++,i++){var u,f,p=a<e.length?(typeof e[a])[0]:"";if(i>=r.length||"o"==(f=(typeof(u=r[i]))[0]))return!s||("u"==p?a>t&&!n:""==p!=n);if("u"==f){if(!s||"u"!=p)return!1}else if(s)if(p==f)if(a<=t){if(u!=e[a])return!1}else{if(n?u>e[a]:u<e[a])return!1;u!=e[a]&&(s=!1)}else if("s"!=p&&"n"!=p){if(n||a<=t)return!1;s=!1,a--}else{if(a<=t||f<p!=n)return!1;s=!1}else"s"!=p&&"n"!=p&&(s=!1,a--)}}var d=[],c=d.pop.bind(d);for(i=1;i<e.length;i++){var h=e[i];d.push(1==h?c()|c():2==h?c()&c():h?l(h,r):!c())}return!!c()},s=(e,r)=>e&&j.o(e,r),u=e=>(e.loaded=1,e.get()),f=e=>Object.keys(e).reduce(((r,t)=>(e[t].eager&&(r[t]=e[t]),r)),{}),p=(e,r,t)=>{var n=t?f(e[r]):e[r];return Object.keys(n).reduce(((e,r)=>!e||!n[e].loaded&&i(e,r)?r:e),0)},d=(e,r,t,n)=>"Unsatisfied version "+t+" from "+(t&&e[r][t].from)+" of shared singleton module "+r+" (required "+a(n)+")",c=e=>{throw new Error(e)},h=e=>{"undefined"!=typeof console&&console.warn&&console.warn(e)},m=(e,r,t)=>t?t():((e,r)=>c("Shared module "+r+" doesn't exist in shared scope "+e))(e,r),v=(e=>function(r,t,n,o,i){var a=j.I(r);return a&&a.then&&!n?a.then(e.bind(e,r,j.S[r],t,!1,o,i)):e(r,j.S[r],t,n,o,i)})(((e,r,t,n,o,i)=>{if(!s(r,t))return m(e,t,i);var a=p(r,t,n);return l(o,a)||h(d(r,t,a,o)),u(r[t][a])})),g={},b={16072:()=>v("default","react",!1,[1,18],(()=>j.e(540).then((()=>()=>j(96540))))),76766:()=>v("default","i18next",!1,[1,23],(()=>j.e(635).then((()=>()=>j(72635))))),29197:()=>v("default","@openmrs/esm-framework",!1,[1,6],(()=>Promise.all([j.e(177),j.e(657),j.e(43),j.e(766)]).then((()=>()=>j(68043))))),53941:()=>v("default","react-i18next",!1,[1,11],(()=>j.e(33).then((()=>()=>j(93414))))),44209:()=>v("default","swr/immutable",!1,[1,2],(()=>Promise.all([j.e(177),j.e(225)]).then((()=>()=>j(54225))))),56339:()=>v("default","swr/infinite",!1,[1,2],(()=>Promise.all([j.e(177),j.e(41)]).then((()=>()=>j(23041))))),70231:()=>v("default","dayjs",!1,[1,1],(()=>j.e(353).then((()=>()=>j(74353))))),80879:()=>v("default","@openmrs/esm-patient-common-lib",!1,[1,10],(()=>Promise.all([j.e(177),j.e(657),j.e(356),j.e(766)]).then((()=>()=>j(5356)))))},y={72:[16072],141:[44209,56339,70231,80879],561:[44209,56339,70231],766:[76766],985:[29197,53941]},w={},j.f.consumes=(e,r)=>{j.o(y,e)&&y[e].forEach((e=>{if(j.o(g,e))return r.push(g[e]);if(!w[e]){var t=r=>{g[e]=0,j.m[e]=t=>{delete j.c[e],t.exports=r()}};w[e]=!0;var n=r=>{delete g[e],j.m[e]=t=>{throw delete j.c[e],r}};try{var o=b[e]();o.then?r.push(g[e]=o.then(t).catch(n)):t(o)}catch(e){n(e)}}}))},(()=>{var e={719:0};j.f.j=(r,t)=>{var n=j.o(e,r)?e[r]:void 0;if(0!==n)if(n)t.push(n[2]);else if(/^(561|72|766|985)$/.test(r))e[r]=0;else{var o=new Promise(((t,o)=>n=e[r]=[t,o]));t.push(n[2]=o);var i=j.p+j.u(r),a=new Error;j.l(i,(t=>{if(j.o(e,r)&&(0!==(n=e[r])&&(e[r]=void 0),n)){var o=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;a.message="Loading chunk "+r+" failed.\n("+o+": "+i+")",a.name="ChunkLoadError",a.type=o,a.request=i,n[1](a)}}),"chunk-"+r,r)}};var r=(r,t)=>{var n,o,[i,a,l]=t,s=0;if(i.some((r=>0!==e[r]))){for(n in a)j.o(a,n)&&(j.m[n]=a[n]);l&&l(j)}for(r&&r(t);s<i.length;s++)o=i[s],j.o(e,o)&&e[o]&&e[o][0](),e[o]=0},t=globalThis.webpackChunk_openmrs_esm_form_engine_lib=globalThis.webpackChunk_openmrs_esm_form_engine_lib||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})(),j.nc=void 0;var S=j(78008);_openmrs_esm_form_engine_lib=S})();
|
package/package.json
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
import { shouldRenderField } from './fieldRenderUtils';
|
2
|
+
|
3
|
+
describe('shouldRenderField', () => {
|
4
|
+
it('should return false for transient fields with no value in embedded-view mode', () => {
|
5
|
+
const sessionMode = 'embedded-view';
|
6
|
+
const isTransient = true;
|
7
|
+
const isEmpty = true;
|
8
|
+
|
9
|
+
const result = shouldRenderField(sessionMode, isTransient, isEmpty);
|
10
|
+
expect(result).toBe(false);
|
11
|
+
});
|
12
|
+
|
13
|
+
it('should return true for transient fields with a value in embedded-view mode', () => {
|
14
|
+
const sessionMode = 'embedded-view';
|
15
|
+
const isTransient = true;
|
16
|
+
const isEmpty = false;
|
17
|
+
|
18
|
+
const result = shouldRenderField(sessionMode, isTransient, isEmpty);
|
19
|
+
expect(result).toBe(true);
|
20
|
+
});
|
21
|
+
|
22
|
+
it('should return true for non-transient fields in embedded-view mode', () => {
|
23
|
+
const sessionMode = 'embedded-view';
|
24
|
+
const isTransient = false;
|
25
|
+
const isEmpty = true;
|
26
|
+
|
27
|
+
const result = shouldRenderField(sessionMode, isTransient, isEmpty);
|
28
|
+
expect(result).toBe(true);
|
29
|
+
});
|
30
|
+
|
31
|
+
it('should return true for any field in non-embedded modes', () => {
|
32
|
+
const sessionMode = 'edit';
|
33
|
+
const isTransient = true;
|
34
|
+
const isEmpty = true;
|
35
|
+
|
36
|
+
const result = shouldRenderField(sessionMode, isTransient, isEmpty);
|
37
|
+
expect(result).toBe(true);
|
38
|
+
});
|
39
|
+
});
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { type SessionMode } from '../../../types';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @name shouldRenderField
|
5
|
+
* @description Determines if a field should be rendered based on the session mode, whether it is transient, and if it is empty.
|
6
|
+
* - A field will not be rendered in 'embedded-view' mode if it is transient and has no value.
|
7
|
+
*/
|
8
|
+
export function shouldRenderField(sessionMode: SessionMode, isTransient: boolean, isEmpty: boolean): boolean {
|
9
|
+
return !(sessionMode === 'embedded-view' && isTransient && isEmpty);
|
10
|
+
}
|
@@ -19,6 +19,7 @@ import { isTrue } from '../../../utils/boolean-utils';
|
|
19
19
|
import { useFormProviderContext } from '../../../provider/form-provider';
|
20
20
|
import PreviousValueReview from '../../previous-value-review/previous-value-review.component';
|
21
21
|
import UnspecifiedField from '../../inputs/unspecified/unspecified.component';
|
22
|
+
import { shouldRenderField } from './fieldRenderUtils';
|
22
23
|
import styles from './form-field-renderer.scss';
|
23
24
|
|
24
25
|
export interface FormFieldRendererProps {
|
@@ -172,6 +173,13 @@ export const FormFieldRenderer = ({ fieldId, valueAdapter, repeatOptions }: Form
|
|
172
173
|
/>
|
173
174
|
);
|
174
175
|
}
|
176
|
+
|
177
|
+
// If the field is transient and has no value, we do not render it in embedded view mode.
|
178
|
+
// This is to prevent transient fields from being displayed in the form when they are not necessarily needed.
|
179
|
+
if (!shouldRenderField(sessionMode, !!field.questionOptions.isTransient, isEmpty(fieldValue))) {
|
180
|
+
return null;
|
181
|
+
}
|
182
|
+
|
175
183
|
return (
|
176
184
|
<ErrorBoundary FallbackComponent={ErrorFallback} onReset={noop}>
|
177
185
|
<Controller
|
package/src/types/schema.ts
CHANGED
@@ -149,9 +149,16 @@ export interface FormQuestionOptions {
|
|
149
149
|
*/
|
150
150
|
step?: number;
|
151
151
|
/**
|
152
|
-
*
|
152
|
+
* @description
|
153
|
+
* Indicates whether the field is transient.
|
154
|
+
* - Transient fields are ignored on form submission.
|
155
|
+
* - If set to __true__, the field is omitted from the O3 Form in `embedded-view` mode.
|
156
|
+
* @default false
|
153
157
|
*/
|
154
158
|
isTransient?: boolean;
|
159
|
+
/**
|
160
|
+
* maxLength and maxLength are used to validate text field length
|
161
|
+
*/
|
155
162
|
maxLength?: string;
|
156
163
|
minLength?: string;
|
157
164
|
showDate?: string;
|
@@ -18,7 +18,7 @@ interface BehaviourProperty {
|
|
18
18
|
}
|
19
19
|
|
20
20
|
/**
|
21
|
-
*
|
21
|
+
* Convenience function for loading form(s) associated to a given package or form version.
|
22
22
|
*
|
23
23
|
* @param packageName The package associated with the form
|
24
24
|
* @param formNamespace The form namespace
|
@@ -145,15 +145,16 @@ export function applyFormIntent(intent, originalJson, parentOverrides?: Array<Be
|
|
145
145
|
behaviourOverrides,
|
146
146
|
);
|
147
147
|
}
|
148
|
-
// TODO: Apply parentOverrides to pages if applicable
|
149
148
|
const pageBehaviour = page.behaviours?.find((behaviour) => behaviour.intent === (intent?.intent || intent));
|
150
149
|
if (pageBehaviour) {
|
151
|
-
page.hide = pageBehaviour
|
152
|
-
page.readonly = pageBehaviour
|
150
|
+
page.hide = pageBehaviour.hide ?? page.hide;
|
151
|
+
page.readonly = pageBehaviour.readonly ?? page.readonly;
|
153
152
|
} else {
|
154
153
|
const fallBackBehaviour = page.behaviours?.find((behaviour) => behaviour.intent === '*');
|
155
|
-
|
156
|
-
|
154
|
+
if (fallBackBehaviour) {
|
155
|
+
page.hide = fallBackBehaviour.hide ?? page.hide;
|
156
|
+
page.readonly = fallBackBehaviour.readonly ?? page.readonly;
|
157
|
+
}
|
157
158
|
}
|
158
159
|
|
159
160
|
// filter page-level markdown behaviour
|
@@ -164,10 +165,9 @@ export function applyFormIntent(intent, originalJson, parentOverrides?: Array<Be
|
|
164
165
|
page.sections = page.sections || [];
|
165
166
|
|
166
167
|
page.sections.forEach((section) => {
|
167
|
-
// TODO: Apply parentOverrides to sections if applicable
|
168
168
|
const secBehaviour = section.behaviours?.find((behaviour) => behaviour.intent === intent?.intent || intent);
|
169
169
|
if (secBehaviour) {
|
170
|
-
section.hide = secBehaviour
|
170
|
+
section.hide = secBehaviour.hide ?? section.hide;
|
171
171
|
} else {
|
172
172
|
const fallBackBehaviour = section.behaviours?.find((behaviour) => behaviour.intent === '*');
|
173
173
|
section.hide = fallBackBehaviour?.hide ?? section.hide;
|
@@ -213,7 +213,7 @@ export function applyFormIntent(intent, originalJson, parentOverrides?: Array<Be
|
|
213
213
|
function updateQuestionRequiredBehaviour(question, intent: string) {
|
214
214
|
const requiredIntentBehaviour = question.behaviours?.find((behaviour) => behaviour.intent === intent);
|
215
215
|
|
216
|
-
const defaultIntentBehaviour = question.behaviours?.find((
|
216
|
+
const defaultIntentBehaviour = question.behaviours?.find((behaviour) => behaviour.intent === '*');
|
217
217
|
// If both required and default intents exist, combine them and update to question
|
218
218
|
if (requiredIntentBehaviour || defaultIntentBehaviour) {
|
219
219
|
// Remove the intent name props from each object
|