@oneblink/apps-react 13.0.0-beta.3 → 13.0.0-beta.5

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.
Files changed (81) hide show
  1. package/dist/OneBlinkFormBase.d.ts +23 -3
  2. package/dist/OneBlinkFormBase.js +164 -145
  3. package/dist/OneBlinkFormBase.js.map +1 -1
  4. package/dist/OneBlinkReadOnlyForm.d.ts +17 -7
  5. package/dist/OneBlinkReadOnlyForm.js +24 -8
  6. package/dist/OneBlinkReadOnlyForm.js.map +1 -1
  7. package/dist/components/renderer/LookupNotification.js +15 -16
  8. package/dist/components/renderer/LookupNotification.js.map +1 -1
  9. package/dist/components/renderer/OneBlinkFormElements.d.ts +5 -7
  10. package/dist/components/renderer/OneBlinkFormElements.js +10 -35
  11. package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
  12. package/dist/components/renderer/PageFormElements.js +8 -3
  13. package/dist/components/renderer/PageFormElements.js.map +1 -1
  14. package/dist/components/renderer/ReverseGeocode.js +6 -11
  15. package/dist/components/renderer/ReverseGeocode.js.map +1 -1
  16. package/dist/form-elements/FormElementCalculation.js +1 -0
  17. package/dist/form-elements/FormElementCalculation.js.map +1 -1
  18. package/dist/form-elements/FormElementForm.d.ts +8 -9
  19. package/dist/form-elements/FormElementForm.js +4 -3
  20. package/dist/form-elements/FormElementForm.js.map +1 -1
  21. package/dist/form-elements/FormElementLookupButton.js +3 -2
  22. package/dist/form-elements/FormElementLookupButton.js.map +1 -1
  23. package/dist/form-elements/FormElementRepeatableSet.d.ts +4 -4
  24. package/dist/form-elements/FormElementRepeatableSet.js +6 -4
  25. package/dist/form-elements/FormElementRepeatableSet.js.map +1 -1
  26. package/dist/form-elements/FormElementSection.d.ts +3 -3
  27. package/dist/form-elements/FormElementSection.js +2 -2
  28. package/dist/form-elements/FormElementSection.js.map +1 -1
  29. package/dist/form-elements/FormElementSummary.js +2 -0
  30. package/dist/form-elements/FormElementSummary.js.map +1 -1
  31. package/dist/hooks/useAreLookupsDisallowed.d.ts +2 -0
  32. package/dist/hooks/useAreLookupsDisallowed.js +12 -0
  33. package/dist/hooks/useAreLookupsDisallowed.js.map +1 -0
  34. package/dist/hooks/useEditableFormElementIds.d.ts +3 -0
  35. package/dist/hooks/useEditableFormElementIds.js +6 -0
  36. package/dist/hooks/useEditableFormElementIds.js.map +1 -0
  37. package/dist/hooks/useFormElementOptions.js +2 -0
  38. package/dist/hooks/useFormElementOptions.js.map +1 -1
  39. package/dist/hooks/useFormIsDirty.d.ts +38 -0
  40. package/dist/hooks/useFormIsDirty.js +78 -0
  41. package/dist/hooks/useFormIsDirty.js.map +1 -0
  42. package/dist/hooks/useFormSubmissionAttempt.d.ts +88 -0
  43. package/dist/hooks/useFormSubmissionAttempt.js +103 -0
  44. package/dist/hooks/useFormSubmissionAttempt.js.map +1 -0
  45. package/dist/hooks/useFormSubmissionAutoSaveState.d.ts +2 -9
  46. package/dist/hooks/useFormSubmissionAutoSaveState.js +4 -2
  47. package/dist/hooks/useFormSubmissionAutoSaveState.js.map +1 -1
  48. package/dist/hooks/useFormValidation.d.ts +1 -1
  49. package/dist/hooks/useFormValidation.js +2 -1
  50. package/dist/hooks/useFormValidation.js.map +1 -1
  51. package/dist/hooks/useInjectPages.d.ts +2 -1
  52. package/dist/hooks/useInjectPages.js.map +1 -1
  53. package/dist/hooks/useIsFormElementReadOnly.d.ts +2 -0
  54. package/dist/hooks/useIsFormElementReadOnly.js +13 -0
  55. package/dist/hooks/useIsFormElementReadOnly.js.map +1 -0
  56. package/dist/hooks/useLookupNotification.d.ts +1 -0
  57. package/dist/hooks/useLookupNotification.js.map +1 -1
  58. package/dist/hooks/useLookups.d.ts +3 -3
  59. package/dist/hooks/useLookups.js +7 -4
  60. package/dist/hooks/useLookups.js.map +1 -1
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.js +2 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/services/form-validation/extensions.d.ts +2 -1
  65. package/dist/services/form-validation/extensions.js +2 -1
  66. package/dist/services/form-validation/extensions.js.map +1 -1
  67. package/dist/services/form-validation/validateSubmission.d.ts +2 -1
  68. package/dist/services/form-validation/validateSubmission.js +14 -9
  69. package/dist/services/form-validation/validateSubmission.js.map +1 -1
  70. package/dist/types/form.d.ts +17 -3
  71. package/dist/types/form.js.map +1 -1
  72. package/dist/utils/read-only-form-elements.d.ts +37 -0
  73. package/dist/utils/read-only-form-elements.js +63 -0
  74. package/dist/utils/read-only-form-elements.js.map +1 -0
  75. package/package.json +2 -1
  76. package/dist/services/isElementReadOnlyForAudience.d.ts +0 -20
  77. package/dist/services/isElementReadOnlyForAudience.js +0 -46
  78. package/dist/services/isElementReadOnlyForAudience.js.map +0 -1
  79. package/dist/services/resolveFormElementReadOnly.d.ts +0 -10
  80. package/dist/services/resolveFormElementReadOnly.js +0 -17
  81. package/dist/services/resolveFormElementReadOnly.js.map +0 -1
@@ -2,15 +2,23 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
3
  import OneBlinkFormBase from './OneBlinkFormBase';
4
4
  import useFormSubmissionState from './hooks/useFormSubmissionState';
5
- function OneBlinkReadOnlyForm({ form, initialSubmission, ...rest }) {
5
+ const noop = () => { };
6
+ function UncontrolledOneBlinkReadOnlyForm({ form, initialSubmission, ...rest }) {
6
7
  const [{ submission, definition, executedLookups }, setFormSubmission] = useFormSubmissionState(form, initialSubmission);
7
- const noop = React.useCallback(() => { }, []);
8
- return (_jsx(OneBlinkFormBase, { definition: definition, submission: submission, disabled: true, isReadOnly: true, onCancel: noop, onSubmit: noop, setFormSubmission: setFormSubmission, isPendingQueueEnabled: false, executedLookups: executedLookups, sectionState: [], ...rest }));
8
+ return (_jsx(OneBlinkFormBase, { ...rest, definition: definition, submission: submission, disabled: true, isReadOnly: true, onCancel: noop, onSubmit: noop, setFormSubmission: setFormSubmission, isPendingQueueEnabled: false, executedLookups: executedLookups, sectionState: [] }));
9
+ }
10
+ function OneBlinkReadOnlyForm(props) {
11
+ if (props.editableFormElementIds) {
12
+ return (_jsx(OneBlinkFormBase, { ...props, disabled: false, isReadOnly: true, onCancel: noop, onSubmit: noop, isPendingQueueEnabled: false }));
13
+ }
14
+ return _jsx(UncontrolledOneBlinkReadOnlyForm, { ...props });
9
15
  }
10
16
  /**
11
- * Component for rendering a OneBlink Form in read-only mode. This component
12
- * will render the form with all inputs disabled but will **not** render the
13
- * submit, cancel and save draft buttons.
17
+ * Component for rendering a OneBlink Form in read-only mode. By default, all
18
+ * inputs are read-only. Pass `editableFormElementIds` with controlled
19
+ * submission props (`definition`, `submission`, `setFormSubmission`,
20
+ * `executedLookups`) to keep selected inputs editable. This component does
21
+ * **not** render the submit, cancel or save draft buttons.
14
22
  *
15
23
  * It is also recommended to import the `css` from this library as well.
16
24
  *
@@ -28,6 +36,7 @@ function OneBlinkReadOnlyForm({ form, initialSubmission, ...rest }) {
28
36
  * FormTypes
29
37
  * IsOfflineContextProvider,
30
38
  * OneBlinkReadOnlyForm,
39
+ * useFormSubmissionState,
31
40
  * useIsMounted,
32
41
  * } from '@oneblink/apps-react'
33
42
  * import '@oneblink/apps-react/dist/styles.css'
@@ -54,6 +63,10 @@ function OneBlinkReadOnlyForm({ form, initialSubmission, ...rest }) {
54
63
  *
55
64
  * function FormContainer() {
56
65
  * const isMounted = useIsMounted()
66
+ * const [
67
+ * { definition, submission, executedLookups },
68
+ * setFormSubmission,
69
+ * ] = useFormSubmissionState(form)
57
70
  *
58
71
  * const handleFormError = React.useCallback(() => {
59
72
  * // handle form rendering error caused by a misconfigured form here...
@@ -62,9 +75,12 @@ function OneBlinkReadOnlyForm({ form, initialSubmission, ...rest }) {
62
75
  * return (
63
76
  * <OneBlinkReadOnlyForm
64
77
  * googleMapsApiKey={googleMapsApiKey}
65
- * initialSubmission={null}
66
- * form={form}
78
+ * definition={definition}
79
+ * submission={submission}
80
+ * setFormSubmission={setFormSubmission}
81
+ * executedLookups={executedLookups}
67
82
  * audience="APPROVER"
83
+ * editableFormElementIds={['element-id']}
68
84
  * />
69
85
  * )
70
86
  * }
@@ -1 +1 @@
1
- {"version":3,"file":"OneBlinkReadOnlyForm.js","sourceRoot":"","sources":["../src/OneBlinkReadOnlyForm.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,gBAGN,MAAM,oBAAoB,CAAA;AAC3B,OAAO,sBAAsB,MAAM,gCAAgC,CAAA;AAEnE,SAAS,oBAAoB,CAAC,EAC5B,IAAI,EACJ,iBAAiB,EACjB,GAAG,IAAI,EACmD;IAC1D,MAAM,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,EAAE,iBAAiB,CAAC,GACpE,sBAAsB,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;IAEjD,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,EAAE,CAAC,CAAA;IAE5C,OAAO,CACL,KAAC,gBAAgB,IACf,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,IAAI,EACd,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,QAAQ,EAAE,IAAI,EACd,iBAAiB,EAAE,iBAAiB,EACpC,qBAAqB,EAAE,KAAK,EAC5B,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,EAAE,KACZ,IAAI,GACR,CACH,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport OneBlinkFormBase, {\n OneBlinkFormUncontrolledProps,\n OneBlinkReadOnlyFormProps,\n} from './OneBlinkFormBase'\nimport useFormSubmissionState from './hooks/useFormSubmissionState'\n\nfunction OneBlinkReadOnlyForm({\n form,\n initialSubmission,\n ...rest\n}: OneBlinkReadOnlyFormProps & OneBlinkFormUncontrolledProps) {\n const [{ submission, definition, executedLookups }, setFormSubmission] =\n useFormSubmissionState(form, initialSubmission)\n\n const noop = React.useCallback(() => {}, [])\n\n return (\n <OneBlinkFormBase\n definition={definition}\n submission={submission}\n disabled={true}\n isReadOnly={true}\n onCancel={noop}\n onSubmit={noop}\n setFormSubmission={setFormSubmission}\n isPendingQueueEnabled={false}\n executedLookups={executedLookups}\n sectionState={[]}\n {...rest}\n />\n )\n}\n\n/**\n * Component for rendering a OneBlink Form in read-only mode. This component\n * will render the form with all inputs disabled but will **not** render the\n * submit, cancel and save draft buttons.\n *\n * It is also recommended to import the `css` from this library as well.\n *\n * ```js\n * import { OneBlinkReadOnlyForm } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n * ```\n *\n * #### Example\n *\n * ```tsx\n * import React from 'react'\n * import ReactDOM from 'react-dom'\n * import {\n * FormTypes\n * IsOfflineContextProvider,\n * OneBlinkReadOnlyForm,\n * useIsMounted,\n * } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n *\n * const googleMapsApiKey = 'ENTER_YOUR_MAPS_API_KEY_HERE'\n * const formsAppId = 1\n * const form: FormTypes.Form = {\n * id: 1,\n * name: 'Name of Form',\n * description: '',\n * organisationId: 'abc123',\n * formsAppEnvironmentId: 1,\n * formsAppIds: [],\n * elements: [],\n * isAuthenticated: false,\n * isMultiPage: false,\n * isInfoPage: false,\n * publishStartDate: null,\n * publishEndDate: null,\n * postSubmissionAction: 'FORMS_LIBRARY',\n * submissionEvents: [],\n * tags: [],\n * }\n *\n * function FormContainer() {\n * const isMounted = useIsMounted()\n *\n * const handleFormError = React.useCallback(() => {\n * // handle form rendering error caused by a misconfigured form here...\n * }, [isMounted])\n *\n * return (\n * <OneBlinkReadOnlyForm\n * googleMapsApiKey={googleMapsApiKey}\n * initialSubmission={null}\n * form={form}\n * audience=\"APPROVER\"\n * />\n * )\n * }\n *\n * function App() {\n * return (\n * <IsOfflineContextProvider>\n * <FormContainer />\n * </IsOfflineContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport default React.memo(OneBlinkReadOnlyForm)\n"]}
1
+ {"version":3,"file":"OneBlinkReadOnlyForm.js","sourceRoot":"","sources":["../src/OneBlinkReadOnlyForm.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,gBAEN,MAAM,oBAAoB,CAAA;AAC3B,OAAO,sBAAsB,MAAM,gCAAgC,CAAA;AAGnE,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAErB,SAAS,gCAAgC,CAAC,EACxC,IAAI,EACJ,iBAAiB,EACjB,GAAG,IAAI,EACsD;IAC7D,MAAM,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,EAAE,iBAAiB,CAAC,GACpE,sBAAsB,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;IAEjD,OAAO,CACL,KAAC,gBAAgB,OACX,IAAI,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,IAAI,EACd,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,QAAQ,EAAE,IAAI,EACd,iBAAiB,EAAE,iBAAiB,EACpC,qBAAqB,EAAE,KAAK,EAC5B,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,EAAE,GAChB,CACH,CAAA;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAgC;IAC5D,IAAI,KAAK,CAAC,sBAAsB,EAAE,CAAC;QACjC,OAAO,CACL,KAAC,gBAAgB,OACX,KAAK,EACT,QAAQ,EAAE,KAAK,EACf,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,QAAQ,EAAE,IAAI,EACd,qBAAqB,EAAE,KAAK,GAC5B,CACH,CAAA;IACH,CAAC;IAED,OAAO,KAAC,gCAAgC,OAAK,KAAK,GAAI,CAAA;AACxD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport OneBlinkFormBase, {\n OneBlinkReadOnlyFormProps,\n} from './OneBlinkFormBase'\nimport useFormSubmissionState from './hooks/useFormSubmissionState'\nimport { FormTypes } from '@oneblink/types'\n\nconst noop = () => {}\n\nfunction UncontrolledOneBlinkReadOnlyForm({\n form,\n initialSubmission,\n ...rest\n}: Extract<OneBlinkReadOnlyFormProps, { form: FormTypes.Form }>) {\n const [{ submission, definition, executedLookups }, setFormSubmission] =\n useFormSubmissionState(form, initialSubmission)\n\n return (\n <OneBlinkFormBase\n {...rest}\n definition={definition}\n submission={submission}\n disabled={true}\n isReadOnly={true}\n onCancel={noop}\n onSubmit={noop}\n setFormSubmission={setFormSubmission}\n isPendingQueueEnabled={false}\n executedLookups={executedLookups}\n sectionState={[]}\n />\n )\n}\n\nfunction OneBlinkReadOnlyForm(props: OneBlinkReadOnlyFormProps) {\n if (props.editableFormElementIds) {\n return (\n <OneBlinkFormBase\n {...props}\n disabled={false}\n isReadOnly={true}\n onCancel={noop}\n onSubmit={noop}\n isPendingQueueEnabled={false}\n />\n )\n }\n\n return <UncontrolledOneBlinkReadOnlyForm {...props} />\n}\n\n/**\n * Component for rendering a OneBlink Form in read-only mode. By default, all\n * inputs are read-only. Pass `editableFormElementIds` with controlled\n * submission props (`definition`, `submission`, `setFormSubmission`,\n * `executedLookups`) to keep selected inputs editable. This component does\n * **not** render the submit, cancel or save draft buttons.\n *\n * It is also recommended to import the `css` from this library as well.\n *\n * ```js\n * import { OneBlinkReadOnlyForm } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n * ```\n *\n * #### Example\n *\n * ```tsx\n * import React from 'react'\n * import ReactDOM from 'react-dom'\n * import {\n * FormTypes\n * IsOfflineContextProvider,\n * OneBlinkReadOnlyForm,\n * useFormSubmissionState,\n * useIsMounted,\n * } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n *\n * const googleMapsApiKey = 'ENTER_YOUR_MAPS_API_KEY_HERE'\n * const formsAppId = 1\n * const form: FormTypes.Form = {\n * id: 1,\n * name: 'Name of Form',\n * description: '',\n * organisationId: 'abc123',\n * formsAppEnvironmentId: 1,\n * formsAppIds: [],\n * elements: [],\n * isAuthenticated: false,\n * isMultiPage: false,\n * isInfoPage: false,\n * publishStartDate: null,\n * publishEndDate: null,\n * postSubmissionAction: 'FORMS_LIBRARY',\n * submissionEvents: [],\n * tags: [],\n * }\n *\n * function FormContainer() {\n * const isMounted = useIsMounted()\n * const [\n * { definition, submission, executedLookups },\n * setFormSubmission,\n * ] = useFormSubmissionState(form)\n *\n * const handleFormError = React.useCallback(() => {\n * // handle form rendering error caused by a misconfigured form here...\n * }, [isMounted])\n *\n * return (\n * <OneBlinkReadOnlyForm\n * googleMapsApiKey={googleMapsApiKey}\n * definition={definition}\n * submission={submission}\n * setFormSubmission={setFormSubmission}\n * executedLookups={executedLookups}\n * audience=\"APPROVER\"\n * editableFormElementIds={['element-id']}\n * />\n * )\n * }\n *\n * function App() {\n * return (\n * <IsOfflineContextProvider>\n * <FormContainer />\n * </IsOfflineContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport default React.memo(OneBlinkReadOnlyForm)\n"]}
@@ -10,12 +10,10 @@ import { LookupNotificationContext, } from '../../hooks/useLookupNotification';
10
10
  import useFormDefinition from '../../hooks/useFormDefinition';
11
11
  import useInjectPages from '../../hooks/useInjectPages';
12
12
  import useFormSubmissionModel from '../../hooks/useFormSubmissionModelContext';
13
- import useFormIsReadOnly from '../../hooks/useFormIsReadOnly';
14
13
  import useIsMounted from '../../hooks/useIsMounted';
15
14
  import useFormElementLookups from '../../hooks/useFormElementLookups';
16
15
  import mergeExecutedLookups from '../../utils/merge-executed-lookups';
17
- import useFormAudience from '../../hooks/useFormAudience';
18
- import isElementReadOnlyForAudience from '../../services/isElementReadOnlyForAudience';
16
+ import useAreLookupsDisallowed from '../../hooks/useAreLookupsDisallowed';
19
17
  import ErrorMessage from '../messages/ErrorMessage';
20
18
  import MaterialIcon from '../MaterialIcon';
21
19
  function LookupNotificationComponent({ autoLookupValue, stringifyAutoLookupValue, element, onLookup, children, }) {
@@ -32,8 +30,13 @@ function LookupNotificationComponent({ autoLookupValue, stringifyAutoLookupValue
32
30
  const [isLookupRequestInFlight, setIsLookupRequestInFlight] = React.useState(false);
33
31
  const [lookupErrorHTML, setLookupErrorHTML] = React.useState(null);
34
32
  const { formSubmissionModel: model } = useFormSubmissionModel();
35
- const formIsReadOnly = useFormIsReadOnly();
36
- const audience = useFormAudience();
33
+ // Definition-level `readOnly` must not suppress lookups for a submitter:
34
+ // prefills and defaults still need to populate related fields, and a locked
35
+ // field can still be the input to a chained lookup. Approver locks and a
36
+ // fully read-only form are different: re-running a lookup from an existing
37
+ // submitted value could overwrite persisted answers merely by opening the
38
+ // review.
39
+ const areLookupsDisallowed = useAreLookupsDisallowed(element);
37
40
  const formElementElementLookup = React.useMemo(() => {
38
41
  return formElementLookups.find(({ id }) => element.isElementLookup && id === element.elementLookupId);
39
42
  }, [element.elementLookupId, element.isElementLookup, formElementLookups]);
@@ -53,11 +56,11 @@ function LookupNotificationComponent({ autoLookupValue, stringifyAutoLookupValue
53
56
  ((formElementElementLookup === null || formElementElementLookup === void 0 ? void 0 : formElementElementLookup.type) !== 'STATIC_DATA' &&
54
57
  (formElementElementLookup === null || formElementElementLookup === void 0 ? void 0 : formElementElementLookup.excludeDefinition)));
55
58
  }, [formElementDataLookup, formElementElementLookup]);
56
- const mergeLookupData = React.useCallback(({ newValue, dataLookupResult, elementLookupResult, executedLookup, }) => {
59
+ const mergeLookupData = React.useCallback(({ newValue, dataLookupResult, elementLookupResult, executedLookup, isDerivedChange, }) => {
57
60
  const executedLookupResult = executedLookup === null || executedLookup === void 0 ? void 0 : executedLookup[element.name];
58
61
  if (elementLookupResult && executedLookupResult !== false) {
59
62
  if (elementLookupResult[0] && elementLookupResult[0].type === 'page') {
60
- injectPagesAfter(element, elementLookupResult, dataLookupResult);
63
+ injectPagesAfter(element, elementLookupResult, dataLookupResult, { isDerivedChange });
61
64
  return;
62
65
  }
63
66
  }
@@ -97,21 +100,14 @@ function LookupNotificationComponent({ autoLookupValue, stringifyAutoLookupValue
97
100
  },
98
101
  }),
99
102
  };
100
- });
103
+ }, { isDerivedChange });
101
104
  }, [element, injectPagesAfter, onLookup]);
102
- // Definition-level `readOnly` must not suppress lookups for a submitter:
103
- // prefills and defaults still need to populate related fields, and a locked
104
- // field can still be the input to a chained lookup. Approver locks are
105
- // different. Re-running a lookup from an existing submitted value could
106
- // overwrite persisted answers merely by opening the review, so only approver
107
- // editable elements may run one.
108
- const areLookupsDisallowed = formIsReadOnly || isElementReadOnlyForAudience(element, audience);
109
105
  const isNotStaticLookup = React.useMemo(() => {
110
106
  return ((formElementDataLookup && formElementDataLookup.type !== 'STATIC_DATA') ||
111
107
  (formElementElementLookup &&
112
108
  formElementElementLookup.type !== 'STATIC_DATA'));
113
109
  }, [formElementDataLookup, formElementElementLookup]);
114
- const triggerLookup = React.useCallback(async ({ newValue, abortController, continueLookupOnAbort }) => {
110
+ const triggerLookup = React.useCallback(async ({ newValue, abortController, continueLookupOnAbort, isDerivedChange, }) => {
115
111
  if (areLookupsDisallowed) {
116
112
  return;
117
113
  }
@@ -153,6 +149,7 @@ function LookupNotificationComponent({ autoLookupValue, stringifyAutoLookupValue
153
149
  dataLookupResult: dataLookupResult,
154
150
  elementLookupResult: elementLookupResult,
155
151
  executedLookup: { [element.name]: true },
152
+ isDerivedChange,
156
153
  });
157
154
  if (isMounted.current) {
158
155
  setHasLookupSucceeded(true);
@@ -181,6 +178,7 @@ function LookupNotificationComponent({ autoLookupValue, stringifyAutoLookupValue
181
178
  dataLookupResult: {},
182
179
  elementLookupResult: [],
183
180
  executedLookup: { [element.name]: false },
181
+ isDerivedChange,
184
182
  });
185
183
  setLookupErrorHTML(typeof error === 'string'
186
184
  ? error
@@ -237,6 +235,7 @@ function LookupNotificationComponent({ autoLookupValue, stringifyAutoLookupValue
237
235
  newValue: autoLookupValue,
238
236
  abortController,
239
237
  continueLookupOnAbort: true,
238
+ isDerivedChange: true,
240
239
  });
241
240
  return () => {
242
241
  abortController.abort();
@@ -1 +1 @@
1
- {"version":3,"file":"LookupNotification.js","sourceRoot":"","sources":["../../../src/components/renderer/LookupNotification.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAe,MAAM,YAAY,CAAA;AAGhD,OAAO,YAAY,MAAM,0BAA0B,CAAA;AACnD,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,mBAAmB,MAAM,sCAAsC,CAAA;AACtE,OAAO,EACL,yBAAyB,GAE1B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,iBAAiB,MAAM,+BAA+B,CAAA;AAC7D,OAAO,cAAc,MAAM,4BAA4B,CAAA;AACvD,OAAO,sBAAsB,MAAM,2CAA2C,CAAA;AAC9E,OAAO,iBAAiB,MAAM,+BAA+B,CAAA;AAC7D,OAAO,YAAY,MAAM,0BAA0B,CAAA;AACnD,OAAO,qBAAqB,MAAM,mCAAmC,CAAA;AACrE,OAAO,oBAAoB,MAAM,oCAAoC,CAAA;AACrE,OAAO,eA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C,GAAG,EACrB,QAAQ,CAAC,MAAM,EACf,IAAI,CACL,CAAA;IAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,CAAC,gBAAgB,CACrB,IAAI,KAAK,CAAC,YAAY,QAAQ,CAAC,MAAM,0BAA0B,CAAC,CACjE,CAAA;QACD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACpD,MAAM,IAAI,CAAC,OAAO,CAAA;QACpB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,OAAO,IAA+B,CAAA;AACxC,CAAC","sourcesContent":["import * as React from 'react'\nimport clsx from 'clsx'\nimport { generateHeaders } from '../../apps/services/fetch'\nimport { Sentry, formService } from '../../apps'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\n\nimport useIsOffline from '../../hooks/useIsOffline'\nimport OnLoading from './OnLoading'\nimport generateDefaultData from '../../services/generate-default-data'\nimport {\n LookupNotificationContext,\n LookupNotificationContextValue,\n} from '../../hooks/useLookupNotification'\nimport useFormDefinition from '../../hooks/useFormDefinition'\nimport useInjectPages from '../../hooks/useInjectPages'\nimport useFormSubmissionModel from '../../hooks/useFormSubmissionModelContext'\nimport useFormIsReadOnly from '../../hooks/useFormIsReadOnly'\nimport useIsMounted from '../../hooks/useIsMounted'\nimport useFormElementLookups from '../../hooks/useFormElementLookups'\nimport mergeExecutedLookups from '../../utils/merge-executed-lookups'\nimport useFormAudience from '../../hooks/useFormAudience'\nimport isElementReadOnlyForAudience from '../../services/isElementReadOnlyForAudience'\n\nimport { FormElementLookupHandler, ExecutedLookups } from '../../types/form'\nimport ErrorMessage from '../messages/ErrorMessage'\nimport MaterialIcon from '../MaterialIcon'\n\ntype FetchLookupPayload = {\n element: FormTypes.LookupFormElement\n definition?: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n}\ntype Props = {\n autoLookupValue?: unknown\n stringifyAutoLookupValue?: (autoLookupValue: unknown) => string\n element: FormTypes.LookupFormElement\n onLookup: FormElementLookupHandler\n children: React.ReactNode\n}\n\nfunction LookupNotificationComponent({\n autoLookupValue,\n stringifyAutoLookupValue,\n element,\n onLookup,\n children,\n}: Props) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n const definition = useFormDefinition()\n const injectPagesAfter = useInjectPages()\n const { isLoading, formElementLookups, loadError, onTryAgain } =\n useFormElementLookups()\n\n const [onCancelLookup, setOnCancelLookup] = React.useState<\n (() => void) | undefined\n >(undefined)\n const [isLookingUp, setIsLookingUp] = React.useState(false)\n const [hasLookupFailed, setHasLookupFailed] = React.useState(false)\n const [hasLookupSucceeded, setHasLookupSucceeded] = React.useState(false)\n const [isCancellable, setIsCancellable] = React.useState(false)\n const [isLookupRequestInFlight, setIsLookupRequestInFlight] =\n React.useState(false)\n const [lookupErrorHTML, setLookupErrorHTML] = React.useState<string | null>(\n null,\n )\n const { formSubmissionModel: model } = useFormSubmissionModel()\n const formIsReadOnly = useFormIsReadOnly()\n const audience = useFormAudience()\n\n const formElementElementLookup = React.useMemo(() => {\n return formElementLookups.find(\n ({ id }) => element.isElementLookup && id === element.elementLookupId,\n )\n }, [element.elementLookupId, element.isElementLookup, formElementLookups])\n\n const formElementDataLookup = React.useMemo(() => {\n return formElementLookups.find(\n ({ id }) => element.isDataLookup && id === element.dataLookupId,\n )\n }, [element.dataLookupId, element.isDataLookup, formElementLookups])\n\n const runLookupOnClear = React.useMemo<boolean>(() => {\n return !!(\n formElementDataLookup?.runLookupOnClear ||\n formElementElementLookup?.runLookupOnClear\n )\n }, [\n formElementDataLookup?.runLookupOnClear,\n formElementElementLookup?.runLookupOnClear,\n ])\n\n const excludeDefinition = React.useMemo(() => {\n return !!(\n (formElementDataLookup?.type !== 'STATIC_DATA' &&\n formElementDataLookup?.excludeDefinition) ||\n (formElementElementLookup?.type !== 'STATIC_DATA' &&\n formElementElementLookup?.excludeDefinition)\n )\n }, [formElementDataLookup, formElementElementLookup])\n\n const mergeLookupData = React.useCallback(\n ({\n newValue,\n dataLookupResult,\n elementLookupResult,\n executedLookup,\n }: {\n newValue: unknown\n dataLookupResult:\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined\n elementLookupResult: FormTypes.FormElement[] | undefined\n executedLookup: ExecutedLookups\n }) => {\n const executedLookupResult = executedLookup?.[element.name]\n if (elementLookupResult && executedLookupResult !== false) {\n if (elementLookupResult[0] && elementLookupResult[0].type === 'page') {\n injectPagesAfter(\n element,\n elementLookupResult as FormTypes.PageElement[],\n dataLookupResult,\n )\n return\n }\n }\n\n onLookup(({ submission, elements, executedLookups }) => {\n let allElements: FormTypes.FormElement[] = elements\n if (\n Array.isArray(elementLookupResult) &&\n executedLookupResult !== false\n ) {\n const indexOfElement = elements.findIndex(\n ({ id }) => id === element.id,\n )\n if (indexOfElement === -1) {\n console.log('Could not find element', element)\n } else {\n // Filter out already injected elements if lookup was successful\n allElements = elements.filter(\n // @ts-expect-error Sorry typescript, we need to check a property you don't approve of :(\n (e) => e.injectedByElementId !== element.id,\n )\n allElements.splice(\n indexOfElement + 1,\n 0,\n ...elementLookupResult.map((e) => {\n // @ts-expect-error Sorry typescript, we need to check a property you don't approve of :(\n e.injectedByElementId = element.id\n return e\n }),\n )\n }\n }\n\n return {\n elements: allElements,\n submission: generateDefaultData(allElements, {\n ...submission,\n [element.name]: newValue,\n ...dataLookupResult,\n }),\n executedLookups: mergeExecutedLookups({\n dataLookupResult,\n currentSubmission: submission,\n executedLookups: {\n ...executedLookups,\n ...executedLookup,\n },\n }),\n }\n })\n },\n [element, injectPagesAfter, onLookup],\n )\n\n // Definition-level `readOnly` must not suppress lookups for a submitter:\n // prefills and defaults still need to populate related fields, and a locked\n // field can still be the input to a chained lookup. Approver locks are\n // different. Re-running a lookup from an existing submitted value could\n // overwrite persisted answers merely by opening the review, so only approver\n // editable elements may run one.\n const areLookupsDisallowed =\n formIsReadOnly || isElementReadOnlyForAudience(element, audience)\n\n const isNotStaticLookup = React.useMemo(() => {\n return (\n (formElementDataLookup && formElementDataLookup.type !== 'STATIC_DATA') ||\n (formElementElementLookup &&\n formElementElementLookup.type !== 'STATIC_DATA')\n )\n }, [formElementDataLookup, formElementElementLookup])\n\n const triggerLookup = React.useCallback<\n LookupNotificationContextValue['onLookup']\n >(\n async ({ newValue, abortController, continueLookupOnAbort }) => {\n if (areLookupsDisallowed) {\n return\n }\n\n setIsLookingUp(true)\n\n if (isOffline && isNotStaticLookup) {\n setHasLookupFailed(true)\n return\n }\n\n setIsLookupRequestInFlight(true)\n setIsCancellable(false)\n setHasLookupFailed(false)\n setHasLookupSucceeded(false)\n setLookupErrorHTML(null)\n setOnCancelLookup(() => () => {\n if (isMounted.current) {\n setIsLookingUp(false)\n }\n abortController.abort()\n })\n\n // After certain amount of time, show the cancel button\n const isCancellableTimeout = setTimeout(() => {\n setIsCancellable(!abortController.signal.aborted)\n }, 5000)\n\n const payload: FetchLookupPayload = {\n element,\n definition: !excludeDefinition ? definition : undefined,\n submission: {\n ...model,\n [element.name]: newValue,\n },\n }\n\n try {\n const [dataLookupResult, elementLookupResult] = await Promise.all([\n fetchLookup(formElementDataLookup, payload, abortController.signal),\n fetchLookup(\n formElementElementLookup,\n payload,\n abortController.signal,\n ),\n ])\n\n mergeLookupData({\n newValue,\n dataLookupResult: dataLookupResult as\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined,\n elementLookupResult: elementLookupResult as\n | FormTypes.FormElement[]\n | undefined,\n executedLookup: { [element.name]: true },\n })\n\n if (isMounted.current) {\n setHasLookupSucceeded(true)\n }\n\n // After certain amount of time, hide the lookup succeeded message\n setTimeout(() => {\n if (isMounted.current) {\n setIsLookingUp(false)\n }\n }, 750)\n } catch (error) {\n if (!isMounted.current) {\n return\n }\n\n if (abortController.signal.aborted) {\n console.log('Fetch aborted')\n if (!continueLookupOnAbort) {\n setIsLookingUp(false)\n }\n return\n }\n\n setHasLookupFailed(true)\n mergeLookupData({\n newValue: newValue,\n dataLookupResult: {},\n elementLookupResult: [],\n executedLookup: { [element.name]: false },\n })\n setLookupErrorHTML(\n typeof error === 'string'\n ? error\n : 'It looks like something went wrong.<br/>Please try again.<br />If the issue continues, please contact support.',\n )\n } finally {\n clearTimeout(isCancellableTimeout)\n if (isMounted.current) {\n setIsLookupRequestInFlight(false)\n setOnCancelLookup(undefined)\n }\n }\n },\n [\n definition,\n element,\n excludeDefinition,\n formElementDataLookup,\n formElementElementLookup,\n areLookupsDisallowed,\n isMounted,\n isNotStaticLookup,\n isOffline,\n mergeLookupData,\n model,\n ],\n )\n\n // For certain elements, do not add click event\n // instead, watch model for changes and trigger lookup function.\n // We add this stringify function here to allow the value to be\n // an object which may have a reference change, but the values\n // have not changed. e.g. the 'location' element's value\n const autoLookupValueString = React.useMemo(() => {\n if (stringifyAutoLookupValue) {\n return stringifyAutoLookupValue(autoLookupValue)\n } else {\n return autoLookupValue\n }\n }, [autoLookupValue, stringifyAutoLookupValue])\n React.useEffect(() => {\n if (isLoading || loadError) {\n return\n }\n const hasLookupRan = hasLookupFailed || hasLookupSucceeded\n\n // For lookups configured with `runLookupOnClear` set to true, we want to\n // allow empty values for `autoLookupValue`, but only if the lookup has\n // been ran previously. This prevents the lookup running on load with an empty value.\n if (\n (autoLookupValue === undefined || autoLookupValue === null) &&\n (!runLookupOnClear || !hasLookupRan)\n ) {\n setIsLookingUp(false)\n return\n }\n const abortController = new AbortController()\n triggerLookup({\n newValue: autoLookupValue,\n abortController,\n continueLookupOnAbort: true,\n })\n return () => {\n abortController.abort()\n }\n // Wants to use \"triggerLookup\" as a dependency,\n // however, this will change on any change made on any\n // element. Checking if \"value\" has changed is enough\n // to trigger a lookup when the correct dependencies change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [autoLookupValueString, isLoading])\n\n const retryLookup = React.useCallback(() => {\n const abortController = new AbortController()\n triggerLookup({\n newValue: autoLookupValue,\n abortController,\n continueLookupOnAbort: true,\n })\n }, [autoLookupValue, triggerLookup])\n\n const contextValue = React.useMemo(\n () => ({\n isLookup: true,\n isLookupRequestInFlight,\n isLoading,\n onLookup: triggerLookup,\n allowLookupOnEmptyValue: runLookupOnClear,\n isLookingUp,\n areLookupsDisallowed,\n }),\n [\n isLookupRequestInFlight,\n isLoading,\n runLookupOnClear,\n triggerLookup,\n isLookingUp,\n areLookupsDisallowed,\n ],\n )\n\n return (\n <LookupNotificationContext.Provider value={contextValue}>\n {children}\n\n {loadError && (\n <ErrorMessage\n title=\"Error Loading Configuration\"\n onTryAgain={onTryAgain}\n >\n <span className=\"cypress-lookup-notification-loading-error\">\n {loadError.message}\n </span>\n </ErrorMessage>\n )}\n\n <div\n className={clsx('ob-lookup__notification', {\n 'is-looking-up': isLookingUp,\n 'is-extended':\n hasLookupFailed || (isCancellable && !hasLookupSucceeded),\n 'is-retryable':\n hasLookupFailed &&\n autoLookupValue !== undefined &&\n autoLookupValue !== null,\n })}\n >\n <div className=\"notification has-margin-top-7 has-text-centered\">\n {hasLookupFailed && (\n <>\n <button\n type=\"button\"\n className=\"delete fade-in\"\n onClick={() => setIsLookingUp(false)}\n aria-label=\"lookup-failure-close-button\"\n />\n\n <div>\n {isOffline && isNotStaticLookup ? (\n <div>\n <MaterialIcon className=\"fade-in has-text-warning\">\n wifi_off\n </MaterialIcon>\n <p className=\"fade-in\" role=\"alert\">\n It looks like you&apos;re offline. Please try again when\n connectivity is restored.\n </p>\n </div>\n ) : (\n <div>\n <MaterialIcon className=\"fade-in has-text-danger\">\n error_outline\n </MaterialIcon>\n <p\n role=\"alert\"\n className=\"fade-in\"\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{\n __html: lookupErrorHTML || '',\n }}\n />\n {autoLookupValue !== undefined &&\n autoLookupValue !== null && (\n <button\n type=\"button\"\n className={clsx(\n 'fade-in button is-primary ob-lookup__retry-button cypress-retry-lookup-button has-margin-top-8',\n )}\n onClick={() => retryLookup()}\n disabled={isLookupRequestInFlight || isLoading}\n aria-label=\"lookup-retry-button\"\n >\n <span></span>\n <span className=\"icon\">\n <MaterialIcon className=\"refresh\">\n refresh\n </MaterialIcon>\n </span>\n <span>&nbsp;Retry Lookup</span>\n </button>\n )}\n </div>\n )}\n </div>\n </>\n )}\n\n {hasLookupSucceeded && (\n <>\n <MaterialIcon\n className=\"has-text-success fade-in\"\n role=\"status\"\n aria-label=\"lookup successful\"\n >\n check_circle_outline\n </MaterialIcon>\n </>\n )}\n\n {!hasLookupSucceeded && !hasLookupFailed && <OnLoading small />}\n\n {isCancellable && !hasLookupSucceeded && !hasLookupFailed && (\n <div className=\"has-margin-top-5 fade-in\" role=\"alert\">\n <p>Taking longer than expected?</p>\n <button\n type=\"button\"\n className=\"button has-margin-top-8\"\n onClick={onCancelLookup}\n >\n Cancel\n </button>\n </div>\n )}\n </div>\n </div>\n </LookupNotificationContext.Provider>\n )\n}\n\nexport default function LookupNotification(props: Props) {\n if (props.element.isDataLookup || props.element.isElementLookup) {\n return <LookupNotificationComponent {...props} />\n }\n\n return <>{props.children}</>\n}\n\nasync function fetchLookup(\n formElementLookup: formService.FormElementLookupResult | undefined,\n payload: FetchLookupPayload,\n abortSignal: AbortSignal,\n): Promise<\n | SubmissionTypes.S3SubmissionData['submission']\n | FormTypes.FormElement[]\n | undefined\n> {\n if (!formElementLookup) {\n return\n }\n\n if (formElementLookup.records) {\n const elementName = payload.element.name\n const inputValue = payload.submission[elementName]\n\n const matchingRecord = formElementLookup.records.find(\n (r) =>\n (r.inputType === 'UNDEFINED' && !inputValue) ||\n (r.inputType !== 'UNDEFINED' && r.inputValue === inputValue),\n )\n\n // insert prefill values\n return matchingRecord?.preFills.reduce<\n SubmissionTypes.S3SubmissionData['submission']\n >((lookupResult, prefill) => {\n switch (prefill.type) {\n case 'TEXT':\n lookupResult[prefill.formElementName] = prefill.text\n break\n case 'NUMBER':\n lookupResult[prefill.formElementName] = prefill.number\n break\n case 'CLEAR':\n lookupResult[prefill.formElementName] = undefined\n break\n }\n return lookupResult\n }, {})\n }\n\n if (!formElementLookup.url) {\n console.log(\n 'Could not find dynamic URL or static records for form element lookup:',\n formElementLookup,\n )\n throw new Error('Could not find element lookup configuration')\n }\n\n const headers = await generateHeaders()\n console.log(\n `Attempting a ${formElementLookup.type} lookup request to:`,\n formElementLookup.url,\n )\n const response = await fetch(formElementLookup.url, {\n method: 'POST',\n headers,\n body: JSON.stringify(payload),\n signal: abortSignal,\n })\n\n const data = await response.json()\n console.log(\n 'Response from lookup to: POST',\n formElementLookup.url,\n response.status,\n data,\n )\n\n if (!response.ok) {\n Sentry.captureException(\n new Error(`Received ${response.status} status code from lookup`),\n )\n if (response.status === 400 && data && data.message) {\n throw data.message\n }\n throw new Error('Invalid response from lookup')\n }\n\n return data as FormTypes.FormElement[]\n}\n"]}
1
+ {"version":3,"file":"LookupNotification.js","sourceRoot":"","sources":["../../../src/components/renderer/LookupNotification.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAe,MAAM,YAAY,CAAA;AAGhD,OAAO,YAAY,MAAM,0BAA0B,CAAA;AACnD,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,mBAAmB,MAAM,sCAAsC,CAAA;AACtE,OAAO,EACL,yBAAyB,GAE1B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,iBAAiB,MAAM,+BAA+B,CAAA;AAC7D,OAAO,cAAc,MAAM,4BAA4B,CAAA;AACvD,OAAO,sBAAsB,MAAM,2CAA2C,CAAA;AAC9E,OAAO,YAAY,MAAM,0BAA0B,CAAA;AACnD,OAAO,qBAAqB,MAAM,mCAAmC,CAAA;AACrE,OAAO,oBAAoB,MAAM,oCAAoC,CAAA;AACrE,OAAO,uBAAuB,MAAM,qCAAqC,CAAA;AAGzE,OAAO,YAAY,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E,EAAE,CAAC;QACjB,MAAM,CAAC,gBAAgB,CACrB,IAAI,KAAK,CAAC,YAAY,QAAQ,CAAC,MAAM,0BAA0B,CAAC,CACjE,CAAA;QACD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACpD,MAAM,IAAI,CAAC,OAAO,CAAA;QACpB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,OAAO,IAA+B,CAAA;AACxC,CAAC","sourcesContent":["import * as React from 'react'\nimport clsx from 'clsx'\nimport { generateHeaders } from '../../apps/services/fetch'\nimport { Sentry, formService } from '../../apps'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\n\nimport useIsOffline from '../../hooks/useIsOffline'\nimport OnLoading from './OnLoading'\nimport generateDefaultData from '../../services/generate-default-data'\nimport {\n LookupNotificationContext,\n LookupNotificationContextValue,\n} from '../../hooks/useLookupNotification'\nimport useFormDefinition from '../../hooks/useFormDefinition'\nimport useInjectPages from '../../hooks/useInjectPages'\nimport useFormSubmissionModel from '../../hooks/useFormSubmissionModelContext'\nimport useIsMounted from '../../hooks/useIsMounted'\nimport useFormElementLookups from '../../hooks/useFormElementLookups'\nimport mergeExecutedLookups from '../../utils/merge-executed-lookups'\nimport useAreLookupsDisallowed from '../../hooks/useAreLookupsDisallowed'\n\nimport { FormElementLookupHandler, ExecutedLookups } from '../../types/form'\nimport ErrorMessage from '../messages/ErrorMessage'\nimport MaterialIcon from '../MaterialIcon'\n\ntype FetchLookupPayload = {\n element: FormTypes.LookupFormElement\n definition?: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n}\ntype Props = {\n autoLookupValue?: unknown\n stringifyAutoLookupValue?: (autoLookupValue: unknown) => string\n element: FormTypes.LookupFormElement\n onLookup: FormElementLookupHandler\n children: React.ReactNode\n}\n\nfunction LookupNotificationComponent({\n autoLookupValue,\n stringifyAutoLookupValue,\n element,\n onLookup,\n children,\n}: Props) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n const definition = useFormDefinition()\n const injectPagesAfter = useInjectPages()\n const { isLoading, formElementLookups, loadError, onTryAgain } =\n useFormElementLookups()\n\n const [onCancelLookup, setOnCancelLookup] = React.useState<\n (() => void) | undefined\n >(undefined)\n const [isLookingUp, setIsLookingUp] = React.useState(false)\n const [hasLookupFailed, setHasLookupFailed] = React.useState(false)\n const [hasLookupSucceeded, setHasLookupSucceeded] = React.useState(false)\n const [isCancellable, setIsCancellable] = React.useState(false)\n const [isLookupRequestInFlight, setIsLookupRequestInFlight] =\n React.useState(false)\n const [lookupErrorHTML, setLookupErrorHTML] = React.useState<string | null>(\n null,\n )\n const { formSubmissionModel: model } = useFormSubmissionModel()\n // Definition-level `readOnly` must not suppress lookups for a submitter:\n // prefills and defaults still need to populate related fields, and a locked\n // field can still be the input to a chained lookup. Approver locks and a\n // fully read-only form are different: re-running a lookup from an existing\n // submitted value could overwrite persisted answers merely by opening the\n // review.\n const areLookupsDisallowed = useAreLookupsDisallowed(element)\n\n const formElementElementLookup = React.useMemo(() => {\n return formElementLookups.find(\n ({ id }) => element.isElementLookup && id === element.elementLookupId,\n )\n }, [element.elementLookupId, element.isElementLookup, formElementLookups])\n\n const formElementDataLookup = React.useMemo(() => {\n return formElementLookups.find(\n ({ id }) => element.isDataLookup && id === element.dataLookupId,\n )\n }, [element.dataLookupId, element.isDataLookup, formElementLookups])\n\n const runLookupOnClear = React.useMemo<boolean>(() => {\n return !!(\n formElementDataLookup?.runLookupOnClear ||\n formElementElementLookup?.runLookupOnClear\n )\n }, [\n formElementDataLookup?.runLookupOnClear,\n formElementElementLookup?.runLookupOnClear,\n ])\n\n const excludeDefinition = React.useMemo(() => {\n return !!(\n (formElementDataLookup?.type !== 'STATIC_DATA' &&\n formElementDataLookup?.excludeDefinition) ||\n (formElementElementLookup?.type !== 'STATIC_DATA' &&\n formElementElementLookup?.excludeDefinition)\n )\n }, [formElementDataLookup, formElementElementLookup])\n\n const mergeLookupData = React.useCallback(\n ({\n newValue,\n dataLookupResult,\n elementLookupResult,\n executedLookup,\n isDerivedChange,\n }: {\n newValue: unknown\n dataLookupResult:\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined\n elementLookupResult: FormTypes.FormElement[] | undefined\n executedLookup: ExecutedLookups\n isDerivedChange?: boolean\n }) => {\n const executedLookupResult = executedLookup?.[element.name]\n if (elementLookupResult && executedLookupResult !== false) {\n if (elementLookupResult[0] && elementLookupResult[0].type === 'page') {\n injectPagesAfter(\n element,\n elementLookupResult as FormTypes.PageElement[],\n dataLookupResult,\n { isDerivedChange },\n )\n return\n }\n }\n\n onLookup(\n ({ submission, elements, executedLookups }) => {\n let allElements: FormTypes.FormElement[] = elements\n if (\n Array.isArray(elementLookupResult) &&\n executedLookupResult !== false\n ) {\n const indexOfElement = elements.findIndex(\n ({ id }) => id === element.id,\n )\n if (indexOfElement === -1) {\n console.log('Could not find element', element)\n } else {\n // Filter out already injected elements if lookup was successful\n allElements = elements.filter(\n // @ts-expect-error Sorry typescript, we need to check a property you don't approve of :(\n (e) => e.injectedByElementId !== element.id,\n )\n allElements.splice(\n indexOfElement + 1,\n 0,\n ...elementLookupResult.map((e) => {\n // @ts-expect-error Sorry typescript, we need to check a property you don't approve of :(\n e.injectedByElementId = element.id\n return e\n }),\n )\n }\n }\n\n return {\n elements: allElements,\n submission: generateDefaultData(allElements, {\n ...submission,\n [element.name]: newValue,\n ...dataLookupResult,\n }),\n executedLookups: mergeExecutedLookups({\n dataLookupResult,\n currentSubmission: submission,\n executedLookups: {\n ...executedLookups,\n ...executedLookup,\n },\n }),\n }\n },\n { isDerivedChange },\n )\n },\n [element, injectPagesAfter, onLookup],\n )\n\n const isNotStaticLookup = React.useMemo(() => {\n return (\n (formElementDataLookup && formElementDataLookup.type !== 'STATIC_DATA') ||\n (formElementElementLookup &&\n formElementElementLookup.type !== 'STATIC_DATA')\n )\n }, [formElementDataLookup, formElementElementLookup])\n\n const triggerLookup = React.useCallback<\n LookupNotificationContextValue['onLookup']\n >(\n async ({\n newValue,\n abortController,\n continueLookupOnAbort,\n isDerivedChange,\n }) => {\n if (areLookupsDisallowed) {\n return\n }\n\n setIsLookingUp(true)\n\n if (isOffline && isNotStaticLookup) {\n setHasLookupFailed(true)\n return\n }\n\n setIsLookupRequestInFlight(true)\n setIsCancellable(false)\n setHasLookupFailed(false)\n setHasLookupSucceeded(false)\n setLookupErrorHTML(null)\n setOnCancelLookup(() => () => {\n if (isMounted.current) {\n setIsLookingUp(false)\n }\n abortController.abort()\n })\n\n // After certain amount of time, show the cancel button\n const isCancellableTimeout = setTimeout(() => {\n setIsCancellable(!abortController.signal.aborted)\n }, 5000)\n\n const payload: FetchLookupPayload = {\n element,\n definition: !excludeDefinition ? definition : undefined,\n submission: {\n ...model,\n [element.name]: newValue,\n },\n }\n\n try {\n const [dataLookupResult, elementLookupResult] = await Promise.all([\n fetchLookup(formElementDataLookup, payload, abortController.signal),\n fetchLookup(\n formElementElementLookup,\n payload,\n abortController.signal,\n ),\n ])\n\n mergeLookupData({\n newValue,\n dataLookupResult: dataLookupResult as\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined,\n elementLookupResult: elementLookupResult as\n | FormTypes.FormElement[]\n | undefined,\n executedLookup: { [element.name]: true },\n isDerivedChange,\n })\n\n if (isMounted.current) {\n setHasLookupSucceeded(true)\n }\n\n // After certain amount of time, hide the lookup succeeded message\n setTimeout(() => {\n if (isMounted.current) {\n setIsLookingUp(false)\n }\n }, 750)\n } catch (error) {\n if (!isMounted.current) {\n return\n }\n\n if (abortController.signal.aborted) {\n console.log('Fetch aborted')\n if (!continueLookupOnAbort) {\n setIsLookingUp(false)\n }\n return\n }\n\n setHasLookupFailed(true)\n mergeLookupData({\n newValue: newValue,\n dataLookupResult: {},\n elementLookupResult: [],\n executedLookup: { [element.name]: false },\n isDerivedChange,\n })\n setLookupErrorHTML(\n typeof error === 'string'\n ? error\n : 'It looks like something went wrong.<br/>Please try again.<br />If the issue continues, please contact support.',\n )\n } finally {\n clearTimeout(isCancellableTimeout)\n if (isMounted.current) {\n setIsLookupRequestInFlight(false)\n setOnCancelLookup(undefined)\n }\n }\n },\n [\n definition,\n element,\n excludeDefinition,\n formElementDataLookup,\n formElementElementLookup,\n areLookupsDisallowed,\n isMounted,\n isNotStaticLookup,\n isOffline,\n mergeLookupData,\n model,\n ],\n )\n\n // For certain elements, do not add click event\n // instead, watch model for changes and trigger lookup function.\n // We add this stringify function here to allow the value to be\n // an object which may have a reference change, but the values\n // have not changed. e.g. the 'location' element's value\n const autoLookupValueString = React.useMemo(() => {\n if (stringifyAutoLookupValue) {\n return stringifyAutoLookupValue(autoLookupValue)\n } else {\n return autoLookupValue\n }\n }, [autoLookupValue, stringifyAutoLookupValue])\n React.useEffect(() => {\n if (isLoading || loadError) {\n return\n }\n const hasLookupRan = hasLookupFailed || hasLookupSucceeded\n\n // For lookups configured with `runLookupOnClear` set to true, we want to\n // allow empty values for `autoLookupValue`, but only if the lookup has\n // been ran previously. This prevents the lookup running on load with an empty value.\n if (\n (autoLookupValue === undefined || autoLookupValue === null) &&\n (!runLookupOnClear || !hasLookupRan)\n ) {\n setIsLookingUp(false)\n return\n }\n const abortController = new AbortController()\n triggerLookup({\n newValue: autoLookupValue,\n abortController,\n continueLookupOnAbort: true,\n isDerivedChange: true,\n })\n return () => {\n abortController.abort()\n }\n // Wants to use \"triggerLookup\" as a dependency,\n // however, this will change on any change made on any\n // element. Checking if \"value\" has changed is enough\n // to trigger a lookup when the correct dependencies change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [autoLookupValueString, isLoading])\n\n const retryLookup = React.useCallback(() => {\n const abortController = new AbortController()\n triggerLookup({\n newValue: autoLookupValue,\n abortController,\n continueLookupOnAbort: true,\n })\n }, [autoLookupValue, triggerLookup])\n\n const contextValue = React.useMemo(\n () => ({\n isLookup: true,\n isLookupRequestInFlight,\n isLoading,\n onLookup: triggerLookup,\n allowLookupOnEmptyValue: runLookupOnClear,\n isLookingUp,\n areLookupsDisallowed,\n }),\n [\n isLookupRequestInFlight,\n isLoading,\n runLookupOnClear,\n triggerLookup,\n isLookingUp,\n areLookupsDisallowed,\n ],\n )\n\n return (\n <LookupNotificationContext.Provider value={contextValue}>\n {children}\n\n {loadError && (\n <ErrorMessage\n title=\"Error Loading Configuration\"\n onTryAgain={onTryAgain}\n >\n <span className=\"cypress-lookup-notification-loading-error\">\n {loadError.message}\n </span>\n </ErrorMessage>\n )}\n\n <div\n className={clsx('ob-lookup__notification', {\n 'is-looking-up': isLookingUp,\n 'is-extended':\n hasLookupFailed || (isCancellable && !hasLookupSucceeded),\n 'is-retryable':\n hasLookupFailed &&\n autoLookupValue !== undefined &&\n autoLookupValue !== null,\n })}\n >\n <div className=\"notification has-margin-top-7 has-text-centered\">\n {hasLookupFailed && (\n <>\n <button\n type=\"button\"\n className=\"delete fade-in\"\n onClick={() => setIsLookingUp(false)}\n aria-label=\"lookup-failure-close-button\"\n />\n\n <div>\n {isOffline && isNotStaticLookup ? (\n <div>\n <MaterialIcon className=\"fade-in has-text-warning\">\n wifi_off\n </MaterialIcon>\n <p className=\"fade-in\" role=\"alert\">\n It looks like you&apos;re offline. Please try again when\n connectivity is restored.\n </p>\n </div>\n ) : (\n <div>\n <MaterialIcon className=\"fade-in has-text-danger\">\n error_outline\n </MaterialIcon>\n <p\n role=\"alert\"\n className=\"fade-in\"\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{\n __html: lookupErrorHTML || '',\n }}\n />\n {autoLookupValue !== undefined &&\n autoLookupValue !== null && (\n <button\n type=\"button\"\n className={clsx(\n 'fade-in button is-primary ob-lookup__retry-button cypress-retry-lookup-button has-margin-top-8',\n )}\n onClick={() => retryLookup()}\n disabled={isLookupRequestInFlight || isLoading}\n aria-label=\"lookup-retry-button\"\n >\n <span></span>\n <span className=\"icon\">\n <MaterialIcon className=\"refresh\">\n refresh\n </MaterialIcon>\n </span>\n <span>&nbsp;Retry Lookup</span>\n </button>\n )}\n </div>\n )}\n </div>\n </>\n )}\n\n {hasLookupSucceeded && (\n <>\n <MaterialIcon\n className=\"has-text-success fade-in\"\n role=\"status\"\n aria-label=\"lookup successful\"\n >\n check_circle_outline\n </MaterialIcon>\n </>\n )}\n\n {!hasLookupSucceeded && !hasLookupFailed && <OnLoading small />}\n\n {isCancellable && !hasLookupSucceeded && !hasLookupFailed && (\n <div className=\"has-margin-top-5 fade-in\" role=\"alert\">\n <p>Taking longer than expected?</p>\n <button\n type=\"button\"\n className=\"button has-margin-top-8\"\n onClick={onCancelLookup}\n >\n Cancel\n </button>\n </div>\n )}\n </div>\n </div>\n </LookupNotificationContext.Provider>\n )\n}\n\nexport default function LookupNotification(props: Props) {\n if (props.element.isDataLookup || props.element.isElementLookup) {\n return <LookupNotificationComponent {...props} />\n }\n\n return <>{props.children}</>\n}\n\nasync function fetchLookup(\n formElementLookup: formService.FormElementLookupResult | undefined,\n payload: FetchLookupPayload,\n abortSignal: AbortSignal,\n): Promise<\n | SubmissionTypes.S3SubmissionData['submission']\n | FormTypes.FormElement[]\n | undefined\n> {\n if (!formElementLookup) {\n return\n }\n\n if (formElementLookup.records) {\n const elementName = payload.element.name\n const inputValue = payload.submission[elementName]\n\n const matchingRecord = formElementLookup.records.find(\n (r) =>\n (r.inputType === 'UNDEFINED' && !inputValue) ||\n (r.inputType !== 'UNDEFINED' && r.inputValue === inputValue),\n )\n\n // insert prefill values\n return matchingRecord?.preFills.reduce<\n SubmissionTypes.S3SubmissionData['submission']\n >((lookupResult, prefill) => {\n switch (prefill.type) {\n case 'TEXT':\n lookupResult[prefill.formElementName] = prefill.text\n break\n case 'NUMBER':\n lookupResult[prefill.formElementName] = prefill.number\n break\n case 'CLEAR':\n lookupResult[prefill.formElementName] = undefined\n break\n }\n return lookupResult\n }, {})\n }\n\n if (!formElementLookup.url) {\n console.log(\n 'Could not find dynamic URL or static records for form element lookup:',\n formElementLookup,\n )\n throw new Error('Could not find element lookup configuration')\n }\n\n const headers = await generateHeaders()\n console.log(\n `Attempting a ${formElementLookup.type} lookup request to:`,\n formElementLookup.url,\n )\n const response = await fetch(formElementLookup.url, {\n method: 'POST',\n headers,\n body: JSON.stringify(payload),\n signal: abortSignal,\n })\n\n const data = await response.json()\n console.log(\n 'Response from lookup to: POST',\n formElementLookup.url,\n response.status,\n data,\n )\n\n if (!response.ok) {\n Sentry.captureException(\n new Error(`Received ${response.status} status code from lookup`),\n )\n if (response.status === 400 && data && data.message) {\n throw data.message\n }\n throw new Error('Invalid response from lookup')\n }\n\n return data as FormTypes.FormElement[]\n}\n"]}
@@ -18,16 +18,14 @@ export type Props<T extends FormTypes._NestedElementsElement> = {
18
18
  /**
19
19
  * Inherited lock for nested fields (`parentReadOnly`). True when the whole
20
20
  * form is read-only, an ancestor is read-only, or a parent element’s
21
- * definition has `readOnly: true`. Does not include an ancestor’s audience
22
- * lock. A child with `approverEditability.type` `ALL_STEPS` also ignores this
23
- * inherited `readOnly` lock while an approver is reviewing.
21
+ * definition has `readOnly: true`. A child included in
22
+ * `editableFormElementIds` ignores this inherited lock.
24
23
  */
25
24
  readOnly?: boolean;
26
25
  /**
27
- * When set, forces each child’s `readOnly` instead of the usual
28
- * inherit-or-audience calculation. Used for synthetic nested fields (Civica
29
- * name records, Freshdesk dependent fields) that should follow their parent’s
30
- * audience lock.
26
+ * When set, forces each child’s `readOnly` instead of the usual calculation.
27
+ * Used for synthetic nested fields (Civica name records, Freshdesk dependent
28
+ * fields) that should follow their parent.
31
29
  */
32
30
  readOnlyOverride?: boolean;
33
31
  };
@@ -44,9 +44,8 @@ import { FormSubmissionModelContextProvider } from '../../hooks/useFormSubmissio
44
44
  import useBooleanState from '../../hooks/useBooleanState';
45
45
  import useFormAudience from '../../hooks/useFormAudience';
46
46
  import useFormIsReadOnly from '../../hooks/useFormIsReadOnly';
47
+ import useIsFormElementReadOnly from '../../hooks/useIsFormElementReadOnly';
47
48
  import isElementHiddenForAudience from '../../services/isElementHiddenForAudience';
48
- import { isApproverEditable } from '../../services/isElementReadOnlyForAudience';
49
- import resolveFormElementReadOnly from '../../services/resolveFormElementReadOnly';
50
49
  import FormElementAPINSWLiquorLicence from '../../form-elements/FormElementAPINSWLiquorLicence';
51
50
  import ElementDOMId from '../../utils/elementDOMIds';
52
51
  import FormElementPointCadastralParcel from '../../form-elements/FormElementPointCadastralParcel';
@@ -54,7 +53,7 @@ import FormElementLookupButton from '../../form-elements/FormElementLookupButton
54
53
  import FormElementPointAddressV3 from '../../form-elements/FormElementPointAddressV3';
55
54
  function OneBlinkFormElements({ formId, elements, isEven, idPrefix, displayValidationMessages, formElementsValidation, formElementsConditionallyShown, onChange, onLookup, onUpdateFormElements, model, parentElement, sectionState, readOnly, readOnlyOverride, }) {
56
55
  const audience = useFormAudience();
57
- const formIsReadOnly = useFormIsReadOnly();
56
+ const isFormReadOnly = useFormIsReadOnly();
58
57
  return (_jsx(FormSubmissionModelContextProvider, { elements: parentElement.elements, model: model, formElementsConditionallyShown: formElementsConditionallyShown, children: elements.map((element) => {
59
58
  var _a, _b;
60
59
  if (element.type === 'section') {
@@ -67,7 +66,7 @@ function OneBlinkFormElements({ formId, elements, isEven, idPrefix, displayValid
67
66
  const sectionHeaderId = `ob-section-header-${element.id}`;
68
67
  return (_jsx("div", { className: clsx('ob-element cypress-element-container', element.customCssClasses, {
69
68
  'is-hidden': isElementHiddenForAudience(element, audience),
70
- }), "aria-labelledby": sectionHeaderId, "aria-describedby": ariaDescribedBy, role: "region", children: _jsx(FormElementSection, { childrenReadOnly: formIsReadOnly || !!readOnly, formId: formId, element: element, displayValidationMessages: displayValidationMessages, idPrefix: idPrefix, formElementsConditionallyShown: formElementsConditionallyShown, formElementsValidation: formElementsValidation, onChange: onChange, onLookup: onLookup, onUpdateFormElements: onUpdateFormElements, model: model, parentElement: parentElement, sectionHeaderId: sectionHeaderId, sectionState: sectionState }) }, element.id));
69
+ }), "aria-labelledby": sectionHeaderId, "aria-describedby": ariaDescribedBy, role: "region", children: _jsx(FormElementSection, { childrenReadOnly: isFormReadOnly || !!readOnly, formId: formId, element: element, displayValidationMessages: displayValidationMessages, idPrefix: idPrefix, formElementsConditionallyShown: formElementsConditionallyShown, formElementsValidation: formElementsValidation, onChange: onChange, onLookup: onLookup, onUpdateFormElements: onUpdateFormElements, model: model, parentElement: parentElement, sectionHeaderId: sectionHeaderId, sectionState: sectionState }) }, element.id));
71
70
  }
72
71
  if (element.type === 'page' ||
73
72
  ((_b = formElementsConditionallyShown === null || formElementsConditionallyShown === void 0 ? void 0 : formElementsConditionallyShown[element.name]) === null || _b === void 0 ? void 0 : _b.isHidden)) {
@@ -78,39 +77,15 @@ function OneBlinkFormElements({ formId, elements, isEven, idPrefix, displayValid
78
77
  }
79
78
  export default React.memo(OneBlinkFormElements);
80
79
  function FormElementSwitchContainer(props) {
80
+ var _a;
81
81
  const { element, formElementValidation, displayValidationMessage } = props;
82
82
  const audience = useFormAudience();
83
- const formIsReadOnly = useFormIsReadOnly();
84
- const descendantsReadOnly = React.useMemo(() => {
85
- if (formIsReadOnly) {
86
- return true;
87
- }
88
- if (props.parentReadOnly) {
89
- return true;
90
- }
91
- return 'readOnly' in element && element.readOnly === true;
92
- }, [element, formIsReadOnly, props.parentReadOnly]);
93
- const readOnly = React.useMemo(() => {
94
- if (formIsReadOnly) {
95
- return true;
96
- }
97
- if (props.readOnlyOverride !== undefined) {
98
- return props.readOnlyOverride;
99
- }
100
- if (audience === 'APPROVER' && isApproverEditable(element)) {
101
- return false;
102
- }
103
- if (descendantsReadOnly) {
104
- return true;
105
- }
106
- return resolveFormElementReadOnly(element, audience);
107
- }, [
108
- audience,
109
- descendantsReadOnly,
110
- element,
111
- formIsReadOnly,
112
- props.readOnlyOverride,
113
- ]);
83
+ const isFormReadOnly = useFormIsReadOnly();
84
+ const isFormElementReadOnly = useIsFormElementReadOnly(element, props.parentReadOnly);
85
+ const descendantsReadOnly = isFormReadOnly ||
86
+ props.parentReadOnly === true ||
87
+ ('readOnly' in element && element.readOnly === true);
88
+ const readOnly = (_a = props.readOnlyOverride) !== null && _a !== void 0 ? _a : isFormElementReadOnly;
114
89
  const [isDirty, setIsDirty] = useBooleanState(false);
115
90
  const elementDOMId = React.useMemo(() => new ElementDOMId(props.id), [props.id]);
116
91
  const getValidationClass = () => {