@oneblink/apps-react 13.0.0-beta.11 → 13.0.0-beta.13
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/OneBlinkFormBase.js +8 -9
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/OneBlinkReadOnlyForm.d.ts +2 -1
- package/dist/OneBlinkReadOnlyForm.js +2 -1
- package/dist/OneBlinkReadOnlyForm.js.map +1 -1
- package/dist/form-elements/FormElementForm.js +7 -1
- package/dist/form-elements/FormElementForm.js.map +1 -1
- package/dist/hooks/useFormValidation.d.ts +2 -2
- package/dist/hooks/useFormValidation.js +5 -2
- package/dist/hooks/useFormValidation.js.map +1 -1
- package/dist/services/dynamic-elements.d.ts +7 -0
- package/dist/services/dynamic-elements.js +16 -2
- package/dist/services/dynamic-elements.js.map +1 -1
- package/dist/services/form-validation/extensions.d.ts +2 -1
- package/dist/services/form-validation/extensions.js +2 -1
- package/dist/services/form-validation/extensions.js.map +1 -1
- package/dist/services/form-validation/getApproverEditableFormElementIds.d.ts +2 -0
- package/dist/services/form-validation/getApproverEditableFormElementIds.js +14 -0
- package/dist/services/form-validation/getApproverEditableFormElementIds.js.map +1 -0
- package/dist/services/form-validation/validateSubmission.d.ts +2 -1
- package/dist/services/form-validation/validateSubmission.js +17 -3
- package/dist/services/form-validation/validateSubmission.js.map +1 -1
- package/dist/utils/read-only-form-elements.d.ts +22 -0
- package/dist/utils/read-only-form-elements.js +70 -0
- package/dist/utils/read-only-form-elements.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneBlinkReadOnlyForm.js","sourceRoot":"","sources":["../src/OneBlinkReadOnlyForm.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,
|
|
1
|
+
{"version":3,"file":"OneBlinkReadOnlyForm.js","sourceRoot":"","sources":["../src/OneBlinkReadOnlyForm.t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AA","sourcesContent":["import * as React from 'react'\nimport OneBlinkFormBase, { OneBlinkReadOnlyFormProps } 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. Selecting a `form` or\n * `infoPage` element makes all of its descendants 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"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import OneBlinkFormElements from '../components/renderer/OneBlinkFormElements';
|
|
4
|
+
import useEditableFormElementIds, { EditableFormElementIdsContext, } from '../hooks/useEditableFormElementIds';
|
|
4
5
|
import ElementDOMId from '../utils/elementDOMIds';
|
|
6
|
+
import { getNestedEditableFormElementIds } from '../utils/read-only-form-elements';
|
|
5
7
|
function FormElementForm({ formId, element, readOnly, childrenReadOnly, readOnlyOverrideChildren, value, id, formElementValidation, displayValidationMessages, formElementConditionallyShown, onChange, onLookup, onUpdateFormElements, sectionState, }) {
|
|
6
8
|
const handleNestedChange = React.useCallback((nestedElement, { value: nestedElementValue, executedLookups: nestedExecutedLookups, sectionState, isDerivedChange, }, idPrefix) => {
|
|
7
9
|
if (nestedElement.type === 'section') {
|
|
@@ -109,7 +111,11 @@ function FormElementForm({ formId, element, readOnly, childrenReadOnly, readOnly
|
|
|
109
111
|
});
|
|
110
112
|
}, [element.id, onUpdateFormElements]);
|
|
111
113
|
const elementDOMId = React.useMemo(() => new ElementDOMId(id), [id]);
|
|
112
|
-
|
|
114
|
+
const editableFormElementIds = useEditableFormElementIds();
|
|
115
|
+
const nestedEditableFormElementIds = React.useMemo(() => readOnlyOverrideChildren
|
|
116
|
+
? editableFormElementIds
|
|
117
|
+
: getNestedEditableFormElementIds(element, editableFormElementIds), [editableFormElementIds, element, readOnlyOverrideChildren]);
|
|
118
|
+
return (_jsx(EditableFormElementIdsContext.Provider, { value: nestedEditableFormElementIds, children: _jsx(OneBlinkFormElements, { formId: formId, formElementsValidation: validation, displayValidationMessages: displayValidationMessages, elements: parentElement.elements, onChange: handleNestedChange, onLookup: handleLookup, formElementsConditionallyShown: formElementsConditionallyShown, model: value || {}, parentElement: parentElement, readOnly: childrenReadOnly, readOnlyOverride: readOnlyOverrideChildren ? readOnly : undefined, idPrefix: elementDOMId.subFormDOMIdPrefix, onUpdateFormElements: handleUpdateNestedFormElements, sectionState: sectionState }) }));
|
|
113
119
|
}
|
|
114
120
|
export default React.memo(FormElementForm);
|
|
115
121
|
//# sourceMappingURL=FormElementForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElementForm.js","sourceRoot":"","sources":["../../src/form-elements/FormElementForm.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAU9E,OAAO,YAAY,MAAM,wBAAwB,CAAA;AAqCjD,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,EAAE,gBAAgB,EAC1B,gBAAgB,EAAE,wBAAwB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EACjE,QAAQ,EAAE,YAAY,CAAC,kBAAkB,EACzC,oBAAoB,EAAE,8BAA8B,EACpD,YAAY,EAAE,YAAY,GAC1B,CACH,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport OneBlinkFormElements from '../components/renderer/OneBlinkFormElements'\nimport {\n ExecutedLookups,\n FormElementConditionallyShown,\n FormElementLookupHandler,\n FormElementValidation,\n NestedFormElementValueChangeHandler,\n SectionState,\n UpdateFormElementsHandler,\n} from '../types/form'\nimport ElementDOMId from '../utils/elementDOMIds'\n\nexport type Props = {\n formId: number\n id: string\n element: FormTypes.FormFormElement\n /**\n * Whether this nested form is locked. Used as `readOnlyOverride` for\n * synthetic children when `readOnlyOverrideChildren` is set. Nested fields do\n * not inherit this value as a blanket lock so a child included in\n * `editableFormElementIds` can stay editable.\n */\n readOnly: boolean\n /**\n * Lock to apply to nested fields (`OneBlinkFormElements.readOnly` /\n * `parentReadOnly`). True when the whole form is read-only, a parent is\n * read-only, or this element’s definition has `readOnly: true`.\n */\n childrenReadOnly: boolean\n /**\n * When true, nested fields use this element’s `readOnly` as\n * `readOnlyOverride` instead of calculating their own. Used by Civica name\n * records and Freshdesk dependent fields.\n */\n readOnlyOverrideChildren?: boolean\n value: SubmissionTypes.S3SubmissionData['submission'] | undefined\n onChange: NestedFormElementValueChangeHandler<\n SubmissionTypes.S3SubmissionData['submission']\n >\n onLookup: FormElementLookupHandler\n formElementValidation: FormElementValidation | undefined\n displayValidationMessages: boolean\n formElementConditionallyShown: FormElementConditionallyShown | undefined\n onUpdateFormElements: UpdateFormElementsHandler\n sectionState: SectionState\n}\n\nfunction FormElementForm({\n formId,\n element,\n readOnly,\n childrenReadOnly,\n readOnlyOverrideChildren,\n value,\n id,\n formElementValidation,\n displayValidationMessages,\n formElementConditionallyShown,\n onChange,\n onLookup,\n onUpdateFormElements,\n sectionState,\n}: Props) {\n const handleNestedChange = React.useCallback(\n (\n nestedElement: FormTypes.FormElement,\n {\n value: nestedElementValue,\n executedLookups: nestedExecutedLookups,\n sectionState,\n isDerivedChange,\n }: Parameters<NestedFormElementValueChangeHandler>[1],\n idPrefix?: string,\n ) => {\n if (nestedElement.type === 'section') {\n // trigger onChange to update sectionState\n onChange(\n {\n ...nestedElement,\n id: idPrefix ? `${idPrefix}${nestedElement.id}` : nestedElement.id,\n },\n { executedLookups: undefined, sectionState },\n )\n }\n if (!('name' in nestedElement)) return\n onChange(element, {\n value: (existingValue) => ({\n ...existingValue,\n [nestedElement.name]:\n typeof nestedElementValue === 'function'\n ? nestedElementValue(\n existingValue ? existingValue[nestedElement.name] : undefined,\n )\n : nestedElementValue,\n }),\n executedLookups: (existingExecutedLookups) => {\n if (\n typeof existingExecutedLookups === 'boolean' ||\n Array.isArray(existingExecutedLookups)\n ) {\n return {}\n }\n return {\n ...existingExecutedLookups,\n [nestedElement.name]:\n typeof nestedExecutedLookups === 'function'\n ? nestedExecutedLookups(\n existingExecutedLookups?.[\n nestedElement.name\n ] as ExecutedLookups,\n )\n : nestedExecutedLookups,\n }\n },\n sectionState,\n isDerivedChange,\n })\n },\n [element, onChange],\n )\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults, options) => {\n onLookup((currentFormSubmission) => {\n let model = currentFormSubmission.submission[\n element.name\n ] as SubmissionTypes.S3SubmissionData['submission']\n let newExecutedLookups = currentFormSubmission.executedLookups?.[\n element.name\n ] as ExecutedLookups\n\n const elements = currentFormSubmission.elements.map((formElement) => {\n if (\n formElement.type === 'form' &&\n formElement.name === element.name &&\n Array.isArray(formElement.elements)\n ) {\n const { elements, submission, executedLookups } =\n mergeLookupResults({\n elements: formElement.elements,\n submission: model,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: newExecutedLookups,\n sectionState: currentFormSubmission.sectionState,\n })\n model = submission\n newExecutedLookups = executedLookups as ExecutedLookups\n return {\n ...formElement,\n elements,\n }\n }\n return formElement\n })\n\n const submission = {\n ...currentFormSubmission.submission,\n [element.name]: model,\n }\n\n return {\n elements,\n submission,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: {\n ...currentFormSubmission.executedLookups,\n [element.name]: newExecutedLookups,\n },\n sectionState: currentFormSubmission.sectionState,\n }\n }, options)\n },\n [element.name, onLookup],\n )\n\n const validation = React.useMemo(() => {\n return !!formElementValidation &&\n typeof formElementValidation !== 'string' &&\n formElementValidation.type === 'formElements'\n ? formElementValidation.formElements\n : undefined\n }, [formElementValidation])\n\n const formElementsConditionallyShown = React.useMemo(() => {\n return formElementConditionallyShown &&\n formElementConditionallyShown.type === 'formElements'\n ? formElementConditionallyShown.formElements\n : undefined\n }, [formElementConditionallyShown])\n\n const parentElement = React.useMemo(\n () => ({\n elements: Array.isArray(element.elements) ? element.elements : [],\n }),\n [element.elements],\n )\n\n const handleUpdateNestedFormElements =\n React.useCallback<UpdateFormElementsHandler>(\n (setter) => {\n onUpdateFormElements((formElements) => {\n return formElements.map((formElement) => {\n if (\n formElement.id === element.id &&\n formElement.type === 'form' &&\n Array.isArray(formElement.elements)\n ) {\n return {\n ...formElement,\n elements: setter(formElement.elements),\n }\n }\n return formElement\n })\n })\n },\n [element.id, onUpdateFormElements],\n )\n\n const elementDOMId = React.useMemo(() => new ElementDOMId(id), [id])\n\n return (\n <OneBlinkFormElements\n formId={formId}\n formElementsValidation={validation}\n displayValidationMessages={displayValidationMessages}\n elements={parentElement.elements}\n onChange={handleNestedChange}\n onLookup={handleLookup}\n formElementsConditionallyShown={formElementsConditionallyShown}\n model={value || {}}\n parentElement={parentElement}\n readOnly={childrenReadOnly}\n readOnlyOverride={readOnlyOverrideChildren ? readOnly : undefined}\n idPrefix={elementDOMId.subFormDOMIdPrefix}\n onUpdateFormElements={handleUpdateNestedFormElements}\n sectionState={sectionState}\n />\n )\n}\n\nexport default React.memo(FormElementForm)\n"]}
|
|
1
|
+
{"version":3,"file":"FormElementForm.js","sourceRoot":"","sources":["../../src/form-elements/FormElementForm.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAC9E,OAAO,yBAAyB,EAAE,EAChC,6BAA6B,GAC9B,MAAM,oCAAoC,CAAA;AAU3C,OAAO,YAAY,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAA;AAqClF,SAAS,eAAe,CAAC,EACvB,MAAM,EACN,OAAO,EACP,QAAQ,EACR,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,EACL,EAAE,EACF,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,YAAY,GACN;IACN,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAC1C,CACE,aAAoC,EACpC,EACE,KAAK,EAAE,kBAAkB,EACzB,eAAe,EAAE,qBAAqB,EACtC,YAAY,EACZ,eAAe,GACoC,EACrD,QAAiB,EACjB,EAAE;QACF,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACrC,0CAA0C;YAC1C,QAAQ,CACN;gBACE,GAAG,aAAa;gBAChB,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE;aACnE,EACD,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,CAC7C,CAAA;QACH,CAAC;QACD,IAAI,CAAC,CAAC,MAAM,IAAI,aAAa,CAAC;YAAE,OAAM;QACtC,QAAQ,CAAC,OAAO,EAAE;YAChB,KAAK,EAAE,CAAC,aAAa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AM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IACpE,MAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAA;IAC1D,MAAM,4BAA4B,GAAG,KAAK,CAAC,OAAO,CAChD,GAAG,EAAE,CACH,wBAAwB;QACtB,CAAC,CAAC,sBAAsB;QACxB,CAAC,CAAC,+BAA+B,CAAC,OAAO,EAAE,sBAAsB,CAAC,EACtE,CAAC,sBAAsB,EAAE,OAAO,EAAE,wBAAwB,CAAC,CAC5D,CAAA;IAED,OAAO,CACL,KAAC,6BAA6B,CAAC,QAAQ,IACrC,KAAK,EAAE,4BAA4B,YAEnC,KAAC,oBAAoB,IACnB,MAAM,EAAE,MAAM,EACd,sBAAsB,EAAE,UAAU,EAClC,yBAAyB,EAAE,yBAAyB,EACpD,QAAQ,EAAE,aAAa,CAAC,QAAQ,EAChC,QAAQ,EAAE,kBAAkB,EAC5B,QAAQ,EAAE,YAAY,EACtB,8BAA8B,EAAE,8BAA8B,EAC9D,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,gBAAgB,EAC1B,gBAAgB,EAAE,wBAAwB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EACjE,QAAQ,EAAE,YAAY,CAAC,kBAAkB,EACzC,oBAAoB,EAAE,8BAA8B,EACpD,YAAY,EAAE,YAAY,GAC1B,GACqC,CAC1C,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport OneBlinkFormElements from '../components/renderer/OneBlinkFormElements'\nimport useEditableFormElementIds, {\n EditableFormElementIdsContext,\n} from '../hooks/useEditableFormElementIds'\nimport {\n ExecutedLookups,\n FormElementConditionallyShown,\n FormElementLookupHandler,\n FormElementValidation,\n NestedFormElementValueChangeHandler,\n SectionState,\n UpdateFormElementsHandler,\n} from '../types/form'\nimport ElementDOMId from '../utils/elementDOMIds'\nimport { getNestedEditableFormElementIds } from '../utils/read-only-form-elements'\n\nexport type Props = {\n formId: number\n id: string\n element: FormTypes.FormFormElement\n /**\n * Whether this nested form is locked. Used as `readOnlyOverride` for\n * synthetic children when `readOnlyOverrideChildren` is set. Nested fields do\n * not inherit this value as a blanket lock so a child included in\n * `editableFormElementIds` can stay editable.\n */\n readOnly: boolean\n /**\n * Lock to apply to nested fields (`OneBlinkFormElements.readOnly` /\n * `parentReadOnly`). True when the whole form is read-only, a parent is\n * read-only, or this element’s definition has `readOnly: true`.\n */\n childrenReadOnly: boolean\n /**\n * When true, nested fields use this element’s `readOnly` as\n * `readOnlyOverride` instead of calculating their own. Used by Civica name\n * records and Freshdesk dependent fields.\n */\n readOnlyOverrideChildren?: boolean\n value: SubmissionTypes.S3SubmissionData['submission'] | undefined\n onChange: NestedFormElementValueChangeHandler<\n SubmissionTypes.S3SubmissionData['submission']\n >\n onLookup: FormElementLookupHandler\n formElementValidation: FormElementValidation | undefined\n displayValidationMessages: boolean\n formElementConditionallyShown: FormElementConditionallyShown | undefined\n onUpdateFormElements: UpdateFormElementsHandler\n sectionState: SectionState\n}\n\nfunction FormElementForm({\n formId,\n element,\n readOnly,\n childrenReadOnly,\n readOnlyOverrideChildren,\n value,\n id,\n formElementValidation,\n displayValidationMessages,\n formElementConditionallyShown,\n onChange,\n onLookup,\n onUpdateFormElements,\n sectionState,\n}: Props) {\n const handleNestedChange = React.useCallback(\n (\n nestedElement: FormTypes.FormElement,\n {\n value: nestedElementValue,\n executedLookups: nestedExecutedLookups,\n sectionState,\n isDerivedChange,\n }: Parameters<NestedFormElementValueChangeHandler>[1],\n idPrefix?: string,\n ) => {\n if (nestedElement.type === 'section') {\n // trigger onChange to update sectionState\n onChange(\n {\n ...nestedElement,\n id: idPrefix ? `${idPrefix}${nestedElement.id}` : nestedElement.id,\n },\n { executedLookups: undefined, sectionState },\n )\n }\n if (!('name' in nestedElement)) return\n onChange(element, {\n value: (existingValue) => ({\n ...existingValue,\n [nestedElement.name]:\n typeof nestedElementValue === 'function'\n ? nestedElementValue(\n existingValue ? existingValue[nestedElement.name] : undefined,\n )\n : nestedElementValue,\n }),\n executedLookups: (existingExecutedLookups) => {\n if (\n typeof existingExecutedLookups === 'boolean' ||\n Array.isArray(existingExecutedLookups)\n ) {\n return {}\n }\n return {\n ...existingExecutedLookups,\n [nestedElement.name]:\n typeof nestedExecutedLookups === 'function'\n ? nestedExecutedLookups(\n existingExecutedLookups?.[\n nestedElement.name\n ] as ExecutedLookups,\n )\n : nestedExecutedLookups,\n }\n },\n sectionState,\n isDerivedChange,\n })\n },\n [element, onChange],\n )\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults, options) => {\n onLookup((currentFormSubmission) => {\n let model = currentFormSubmission.submission[\n element.name\n ] as SubmissionTypes.S3SubmissionData['submission']\n let newExecutedLookups = currentFormSubmission.executedLookups?.[\n element.name\n ] as ExecutedLookups\n\n const elements = currentFormSubmission.elements.map((formElement) => {\n if (\n formElement.type === 'form' &&\n formElement.name === element.name &&\n Array.isArray(formElement.elements)\n ) {\n const { elements, submission, executedLookups } =\n mergeLookupResults({\n elements: formElement.elements,\n submission: model,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: newExecutedLookups,\n sectionState: currentFormSubmission.sectionState,\n })\n model = submission\n newExecutedLookups = executedLookups as ExecutedLookups\n return {\n ...formElement,\n elements,\n }\n }\n return formElement\n })\n\n const submission = {\n ...currentFormSubmission.submission,\n [element.name]: model,\n }\n\n return {\n elements,\n submission,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: {\n ...currentFormSubmission.executedLookups,\n [element.name]: newExecutedLookups,\n },\n sectionState: currentFormSubmission.sectionState,\n }\n }, options)\n },\n [element.name, onLookup],\n )\n\n const validation = React.useMemo(() => {\n return !!formElementValidation &&\n typeof formElementValidation !== 'string' &&\n formElementValidation.type === 'formElements'\n ? formElementValidation.formElements\n : undefined\n }, [formElementValidation])\n\n const formElementsConditionallyShown = React.useMemo(() => {\n return formElementConditionallyShown &&\n formElementConditionallyShown.type === 'formElements'\n ? formElementConditionallyShown.formElements\n : undefined\n }, [formElementConditionallyShown])\n\n const parentElement = React.useMemo(\n () => ({\n elements: Array.isArray(element.elements) ? element.elements : [],\n }),\n [element.elements],\n )\n\n const handleUpdateNestedFormElements =\n React.useCallback<UpdateFormElementsHandler>(\n (setter) => {\n onUpdateFormElements((formElements) => {\n return formElements.map((formElement) => {\n if (\n formElement.id === element.id &&\n formElement.type === 'form' &&\n Array.isArray(formElement.elements)\n ) {\n return {\n ...formElement,\n elements: setter(formElement.elements),\n }\n }\n return formElement\n })\n })\n },\n [element.id, onUpdateFormElements],\n )\n\n const elementDOMId = React.useMemo(() => new ElementDOMId(id), [id])\n const editableFormElementIds = useEditableFormElementIds()\n const nestedEditableFormElementIds = React.useMemo(\n () =>\n readOnlyOverrideChildren\n ? editableFormElementIds\n : getNestedEditableFormElementIds(element, editableFormElementIds),\n [editableFormElementIds, element, readOnlyOverrideChildren],\n )\n\n return (\n <EditableFormElementIdsContext.Provider\n value={nestedEditableFormElementIds}\n >\n <OneBlinkFormElements\n formId={formId}\n formElementsValidation={validation}\n displayValidationMessages={displayValidationMessages}\n elements={parentElement.elements}\n onChange={handleNestedChange}\n onLookup={handleLookup}\n formElementsConditionallyShown={formElementsConditionallyShown}\n model={value || {}}\n parentElement={parentElement}\n readOnly={childrenReadOnly}\n readOnlyOverride={readOnlyOverrideChildren ? readOnly : undefined}\n idPrefix={elementDOMId.subFormDOMIdPrefix}\n onUpdateFormElements={handleUpdateNestedFormElements}\n sectionState={sectionState}\n />\n </EditableFormElementIdsContext.Provider>\n )\n}\n\nexport default React.memo(FormElementForm)\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
2
|
import { CaptchaType, ExecutedLookups, FormElementsConditionallyShown } from '../types/form';
|
|
3
|
-
export default function useFormValidation(pages: FormTypes.PageElement[]): {
|
|
4
|
-
validate: (submission: SubmissionTypes.S3SubmissionData["submission"], formElementsConditionallyShown: FormElementsConditionallyShown, executedLookups: ExecutedLookups, captchaType: CaptchaType, isOffline: boolean, audience: FormTypes.FormElementHiddenFromAudience, editableFormElementIds
|
|
3
|
+
export default function useFormValidation(pages: FormTypes.PageElement[], approvalSteps: FormTypes.Form['approvalSteps']): {
|
|
4
|
+
validate: (submission: SubmissionTypes.S3SubmissionData["submission"], formElementsConditionallyShown: FormElementsConditionallyShown, executedLookups: ExecutedLookups, captchaType: CaptchaType, isOffline: boolean, audience: FormTypes.FormElementHiddenFromAudience, editableFormElementIds: string[] | undefined) => import("../types/form").FormElementsValidation | undefined;
|
|
5
5
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import validateSubmission from '../services/form-validation/validateSubmission';
|
|
3
|
+
import getApproverEditableFormElementIds from '../services/form-validation/getApproverEditableFormElementIds';
|
|
3
4
|
function stripFormElementsWithoutName(formElements, hasReadOnlyAncestor) {
|
|
4
5
|
return formElements.reduce((memo, formElement) => {
|
|
5
6
|
const isReadOnly = hasReadOnlyAncestor ||
|
|
@@ -38,10 +39,11 @@ function stripFormElementsWithoutName(formElements, hasReadOnlyAncestor) {
|
|
|
38
39
|
}
|
|
39
40
|
}, []);
|
|
40
41
|
}
|
|
41
|
-
export default function useFormValidation(pages) {
|
|
42
|
+
export default function useFormValidation(pages, approvalSteps) {
|
|
42
43
|
const formElementsWithName = React.useMemo(() => {
|
|
43
44
|
return stripFormElementsWithoutName(pages, false);
|
|
44
45
|
}, [pages]);
|
|
46
|
+
const approverEditableFormElementIds = React.useMemo(() => getApproverEditableFormElementIds(approvalSteps), [approvalSteps]);
|
|
45
47
|
const handleValidate = React.useCallback((submission, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds) => {
|
|
46
48
|
return validateSubmission({
|
|
47
49
|
elements: formElementsWithName,
|
|
@@ -52,8 +54,9 @@ export default function useFormValidation(pages) {
|
|
|
52
54
|
isOffline,
|
|
53
55
|
audience,
|
|
54
56
|
editableFormElementIds,
|
|
57
|
+
approverEditableFormElementIds,
|
|
55
58
|
});
|
|
56
|
-
}, [formElementsWithName]);
|
|
59
|
+
}, [approverEditableFormElementIds, formElementsWithName]);
|
|
57
60
|
return {
|
|
58
61
|
validate: handleValidate,
|
|
59
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormValidation.js","sourceRoot":"","sources":["../../src/hooks/useFormValidation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,kBAAkB,MAAM,gDAAgD,CAAA;
|
|
1
|
+
{"version":3,"file":"useFormValidation.js","sourceRoot":"","sources":["../../src/hooks/useFormValidation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,kBAAkB,MAAM,gDAAgD,CAAA;AAC/E,OAAO,iCAAiC,MAAM,+DAA+D,CAAA;AAO7G,SAAS,4BAA4B,CACnC,YAAqC,EACrC,mBAA4B;IAE5B,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE;QACpB,MAAM,UAAU,GACd,mBAAmB;YACnB,CAAC,UAAU,IAAI,WAAW,IAAI,WAAW,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAA;QAE9D,QAAQ,WAAW,CAAC,IAAI,EAAE,CAAC;YACzB,KAAK,SAAS,CAAC,CAAC,CAAC;gBACf,gEAAgE;gBAChE,kEAAkE;gBAClE,yBAAyB;gBACzB,IAAI,UAAU,EAAE,CAAC;oBACf,OAAO,IAAI,CAAA;gBACb,CAAC;gBACD,OAAO,CAA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C9B,eAAe;YACf,WAAW;YACX,SAAS;YACT,QAAQ;YACR,sBAAsB;YACtB,8BAA8B;SAC/B,CAAC,CAAA;IACJ,CAAC,EACD,CAAC,8BAA8B,EAAE,oBAAoB,CAAC,CACvD,CAAA;IAED,OAAO;QACL,QAAQ,EAAE,cAAc;KACzB,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\n\nimport validateSubmission from '../services/form-validation/validateSubmission'\nimport getApproverEditableFormElementIds from '../services/form-validation/getApproverEditableFormElementIds'\nimport {\n CaptchaType,\n ExecutedLookups,\n FormElementsConditionallyShown,\n} from '../types/form'\n\nfunction stripFormElementsWithoutName(\n formElements: FormTypes.FormElement[],\n hasReadOnlyAncestor: boolean,\n): FormTypes.FormElementWithName[] {\n return formElements.reduce<FormTypes.FormElementWithName[]>(\n (memo, formElement) => {\n const isReadOnly =\n hasReadOnlyAncestor ||\n ('readOnly' in formElement && formElement.readOnly === true)\n\n switch (formElement.type) {\n case 'captcha': {\n // The renderer omits a captcha inside a read-only container, so\n // requiring one here would fail validation with an error the user\n // cannot see or resolve.\n if (isReadOnly) {\n return memo\n }\n return [...memo, formElement]\n }\n case 'page':\n case 'section': {\n return [\n ...memo,\n ...stripFormElementsWithoutName(formElement.elements, isReadOnly),\n ]\n }\n case 'infoPage':\n case 'form':\n case 'repeatableSet': {\n return [\n ...memo,\n {\n ...formElement,\n elements: stripFormElementsWithoutName(\n formElement.elements || [],\n isReadOnly,\n ),\n },\n ]\n }\n default: {\n return [...memo, formElement]\n }\n }\n },\n [],\n )\n}\n\nexport default function useFormValidation(\n pages: FormTypes.PageElement[],\n approvalSteps: FormTypes.Form['approvalSteps'],\n) {\n const formElementsWithName = React.useMemo(() => {\n return stripFormElementsWithoutName(pages, false)\n }, [pages])\n const approverEditableFormElementIds = React.useMemo(\n () => getApproverEditableFormElementIds(approvalSteps),\n [approvalSteps],\n )\n\n const handleValidate = React.useCallback(\n (\n submission: SubmissionTypes.S3SubmissionData['submission'],\n formElementsConditionallyShown: FormElementsConditionallyShown,\n executedLookups: ExecutedLookups,\n captchaType: CaptchaType,\n isOffline: boolean,\n audience: FormTypes.FormElementHiddenFromAudience,\n editableFormElementIds: string[] | undefined,\n ) => {\n return validateSubmission({\n elements: formElementsWithName,\n submission,\n formElementsConditionallyShown,\n executedLookups,\n captchaType,\n isOffline,\n audience,\n editableFormElementIds,\n approverEditableFormElementIds,\n })\n },\n [approverEditableFormElementIds, formElementsWithName],\n )\n\n return {\n validate: handleValidate,\n }\n}\n"]}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { FormTypes } from '@oneblink/types';
|
|
2
2
|
export declare function generateConfirmationFormElementName(formElement: FormTypes.EmailElement): string;
|
|
3
|
+
/**
|
|
4
|
+
* The element a dynamic element was generated from, or `undefined` for an
|
|
5
|
+
* element that came from the form definition. Logic that needs to treat a
|
|
6
|
+
* dynamic element like the element it belongs to can rely on this instead of
|
|
7
|
+
* knowing which element types generate what.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getGeneratedByFormElementId(formElement: FormTypes.FormElement): string | undefined;
|
|
3
10
|
export declare const injectDynamicElements: (formElements: FormTypes.FormElement[]) => FormTypes.FormElement[];
|
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
export function generateConfirmationFormElementName(formElement) {
|
|
5
5
|
return window.btoa(formElement.name);
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* The element a dynamic element was generated from, or `undefined` for an
|
|
9
|
+
* element that came from the form definition. Logic that needs to treat a
|
|
10
|
+
* dynamic element like the element it belongs to can rely on this instead of
|
|
11
|
+
* knowing which element types generate what.
|
|
12
|
+
*/
|
|
13
|
+
export function getGeneratedByFormElementId(formElement) {
|
|
14
|
+
if ('generatedByFormElementId' in formElement &&
|
|
15
|
+
typeof formElement.generatedByFormElementId === 'string') {
|
|
16
|
+
return formElement.generatedByFormElementId;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
7
19
|
export const injectDynamicElements = (formElements) => {
|
|
8
20
|
return formElements.reduce((memo, formElement) => {
|
|
9
21
|
if ('elements' in formElement && Array.isArray(formElement.elements)) {
|
|
@@ -18,7 +30,7 @@ export const injectDynamicElements = (formElements) => {
|
|
|
18
30
|
case 'email': {
|
|
19
31
|
if (formElement.requiresConfirmation) {
|
|
20
32
|
const confirmationFormElementName = generateConfirmationFormElementName(formElement);
|
|
21
|
-
|
|
33
|
+
const confirmationFormElement = {
|
|
22
34
|
...formElement,
|
|
23
35
|
id: confirmationFormElementName,
|
|
24
36
|
name: confirmationFormElementName,
|
|
@@ -29,7 +41,9 @@ export const injectDynamicElements = (formElements) => {
|
|
|
29
41
|
hint: undefined,
|
|
30
42
|
hintPosition: undefined,
|
|
31
43
|
requiresConfirmation: false,
|
|
32
|
-
|
|
44
|
+
generatedByFormElementId: formElement.id,
|
|
45
|
+
};
|
|
46
|
+
memo.push(confirmationFormElement);
|
|
33
47
|
}
|
|
34
48
|
}
|
|
35
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-elements.js","sourceRoot":"","sources":["../../src/services/dynamic-elements.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,oGAAoG;AACpG,oFAAoF;AAIpF,MAAM,UAAU,mCAAmC,CACjD,WAAmC;IAEnC,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;AACtC,CAAC;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,YAAqC,EACZ,EAAE;IAC3B,OAAO,YAAY,CAAC,MAAM,CAA0B,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE;QACxE,IAAI,UAAU,IAAI,WAAW,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;YACrE,IAAI,CAAC,IAAI,CAAC;gBACR,GAAG,WAAW;gBACd,QAAQ,EAAE,qBAAqB,CAAC,WAAW,CAAC,QAA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QAAQ,WAAW,CAAC,IAAI,EAAE,CAAC;YACzB,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,IAAI,WAAW,CAAC,oBAAoB,EAAE,CAAC;oBACrC,MAAM,2BAA2B,GAC/B,mCAAmC,CAAC,WAAW,CAAC,CAAA;oBAElD,MAAM,uBAAuB,GAAG;wBAC9B,GAAG,WAAW;wBACd,EAAE,EAAE,2BAA2B;wBAC/B,IAAI,EAAE,2BAA2B;wBACjC,KAAK,EAAE,WAAW,WAAW,CAAC,KAAK,EAAE;wBACrC,YAAY,EAAE,KAAK;wBACnB,eAAe,EAAE,KAAK;wBACtB,YAAY,EAAE,SAAS;wBACvB,IAAI,EAAE,SAAS;wBACf,YAAY,EAAE,SAAS;wBACvB,oBAAoB,EAAE,KAAK;wBAC3B,wBAAwB,EAAE,WAAW,CAAC,EAAE;qBACzC,CAAA;oBACD,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA","sourcesContent":["// This file houses logic related to dynamic elements\n// (Our term for elements that are created exclusively by our logic for display on the client side).\n// These elements are not part of the form definition or the stored form submission.\n\nimport { FormTypes } from '@oneblink/types'\n\nexport function generateConfirmationFormElementName(\n formElement: FormTypes.EmailElement,\n) {\n return window.btoa(formElement.name)\n}\n\n/**\n * The element a dynamic element was generated from, or `undefined` for an\n * element that came from the form definition. Logic that needs to treat a\n * dynamic element like the element it belongs to can rely on this instead of\n * knowing which element types generate what.\n */\nexport function getGeneratedByFormElementId(\n formElement: FormTypes.FormElement,\n): string | undefined {\n if (\n 'generatedByFormElementId' in formElement &&\n typeof formElement.generatedByFormElementId === 'string'\n ) {\n return formElement.generatedByFormElementId\n }\n}\n\nexport const injectDynamicElements = (\n formElements: FormTypes.FormElement[],\n): FormTypes.FormElement[] => {\n return formElements.reduce<FormTypes.FormElement[]>((memo, formElement) => {\n if ('elements' in formElement && Array.isArray(formElement.elements)) {\n memo.push({\n ...formElement,\n elements: injectDynamicElements(formElement.elements || []),\n })\n return memo\n }\n\n memo.push(formElement)\n\n switch (formElement.type) {\n case 'email': {\n if (formElement.requiresConfirmation) {\n const confirmationFormElementName =\n generateConfirmationFormElementName(formElement)\n\n const confirmationFormElement = {\n ...formElement,\n id: confirmationFormElementName,\n name: confirmationFormElementName,\n label: `Confirm ${formElement.label}`,\n isDataLookup: false,\n isElementLookup: false,\n defaultValue: undefined,\n hint: undefined,\n hintPosition: undefined,\n requiresConfirmation: false,\n generatedByFormElementId: formElement.id,\n }\n memo.push(confirmationFormElement)\n }\n }\n }\n\n return memo\n }, [])\n}\n"]}
|
|
@@ -11,7 +11,7 @@ declare const validationExtensions: {
|
|
|
11
11
|
regex<DefaultValue>(value: unknown, formElement: FormTypes.FormElementWithInput<DefaultValue>): string[];
|
|
12
12
|
attachment(value: unknown): string[];
|
|
13
13
|
numberRegex(value: unknown, formElement: FormTypes.NumberElement): string[];
|
|
14
|
-
nestedElements(value: unknown, { formElement, formElements, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds, }: {
|
|
14
|
+
nestedElements(value: unknown, { formElement, formElements, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds, approverEditableFormElementIds, }: {
|
|
15
15
|
formElement: FormTypes.FormElementWithName;
|
|
16
16
|
formElements: FormTypes.FormElementWithName[] | undefined;
|
|
17
17
|
formElementsConditionallyShown: FormElementsConditionallyShown | undefined;
|
|
@@ -20,6 +20,7 @@ declare const validationExtensions: {
|
|
|
20
20
|
isOffline: boolean;
|
|
21
21
|
audience: FormTypes.FormElementHiddenFromAudience;
|
|
22
22
|
editableFormElementIds?: string[];
|
|
23
|
+
approverEditableFormElementIds?: string[];
|
|
23
24
|
}): {
|
|
24
25
|
type: "formElements";
|
|
25
26
|
formElements: import("../../types/form").FormElementsValidation;
|
|
@@ -53,7 +53,7 @@ const validationExtensions = {
|
|
|
53
53
|
}
|
|
54
54
|
return [];
|
|
55
55
|
},
|
|
56
|
-
nestedElements(value, { formElement, formElements, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds, }) {
|
|
56
|
+
nestedElements(value, { formElement, formElements, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds, approverEditableFormElementIds, }) {
|
|
57
57
|
if (formElements) {
|
|
58
58
|
const nestedExecutedLookupsValue = executedLookups !== undefined &&
|
|
59
59
|
typeof executedLookups !== 'boolean' &&
|
|
@@ -75,6 +75,7 @@ const validationExtensions = {
|
|
|
75
75
|
isOffline,
|
|
76
76
|
audience,
|
|
77
77
|
editableFormElementIds,
|
|
78
|
+
approverEditableFormElementIds,
|
|
78
79
|
});
|
|
79
80
|
if (errors) {
|
|
80
81
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../../../src/services/form-validation/extensions.ts"],"names":[],"mappings":"AAMA,OAAO,kBAAkB,MAAM,sBAAsB,CAAA;AACrD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,OAAO,CAAC,EACN,eAAe,EACf,WAAW,GAOZ;QACC,IAAI,CAAC,WAAW,CAAC,YAAY,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC;YAC9D,OAAO,EAAE,CAAA;QACX,CAAC;QAED,0DAA0D;QAC1D,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,sBAAsB,GAAG,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAG,WAAW,CAAC,IAAI,CAAC,CAAA;QAClE,IAAI,sBAAsB,KAAK,IAAI,EAAE,CAAC;YACpC,OAAO,EAAE,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IACX,CAAC;IAED,cAAc,CACZ,KAAc,EACd,EACE,WAAW,EACX,YAAY,EACZ,8BAA8B,EAC9B,eAAe,EACf,WAAW,EACX,SAAS,EACT,QAAQ,EACR,sBAAsB,
|
|
1
|
+
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../../../src/services/form-validation/extensions.ts"],"names":[],"mappings":"AAMA,OAAO,kBAAkB,MAAM,sBAAsB,CAAA;AACrD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,OAAO,CAAC,EACN,eAAe,EACf,WAAW,GAOZ;QACC,IAAI,CAAC,WAAW,CAAC,YAAY,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC;YAC9D,OAAO,EAAE,CAAA;QACX,CAAC;QAED,0DAA0D;QAC1D,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,sBAAsB,GAAG,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAG,WAAW,CAAC,IAAI,CAAC,CAAA;QAClE,IAAI,sBAAsB,KAAK,IAAI,EAAE,CAAC;YACpC,OAAO,EAAE,CAAA;QACX,CAAC;QAED,OAAO;YACL,+BAA+B,CAC7B,WAAW,CAAC,YAAY,EACxB,WAAW,CAAC,IAAI,KAAK,cAAc;gBACjC,CAAC,CAAC,WAAW,CAAC,eAAe;gBAC7B,CAAC,CAAC,SAAS,CACd;SACF,CAAA;IACH,CAAC;IAED,QAAQ,CACN,KAAc,EACd,EAAE,QAAQ,EAAE,eAAe,EAAiC,EAC5D,OAAe;QAEf,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE;gBAChC,OAAO,EAAE,eAAe,IAAI,OAAO;aACpC,CAAC,CAAA;QACJ,CAAC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6BAA6B,GACjC,8BAA8B,aAA9B,8BAA8B,uBAA9B,8BAA8B,CAAG,WAAW,CAAC,IAAI,CAAC,CAAA;YACpD,MAAM,MAAM,GAAG,kBAAkB,CAAC;gBAChC,QAAQ,EAAE,YAA+C;gBACzD,UAAU,EAAE,KAAuD;gBACnE,8BAA8B,EAC5B,CAAA,6BAA6B,aAA7B,6BAA6B,uBAA7B,6BAA6B,CAAE,IAAI,MAAK,cAAc;oBACpD,CAAC,CAAC,6BAA6B,CAAC,YAAY;oBAC5C,CAAC,CAAC,SAAS;gBACf,eAAe,EACb,OAAO,0BAA0B,KAAK,SAAS;oBAC/C,CAAC,KAAK,CAAC,OAAO,CAAC,0BAA0B,CAAC;oBACxC,CAAC,CAAC,0BAA0B;oBAC5B,CAAC,CAAC,EAAE;gBACR,WAAW;gBACX,SAAS;gBACT,QAAQ;gBACR,sBAAsB;gBACtB,8BAA8B;aAC/B,CAAC,CAAA;YACF,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO;oBACL,IAAI,EAAE,cAAuB;oBAC7B,YAAY,EAAE,MAAM;iBACrB,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,SAAkB,EAAE,OAAe;QACzC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACnC,CAAC;CACF,CAAA;AAED,eAAe,oBAAoB,CAAA","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport {\n CaptchaType,\n ExecutedLookups,\n FormElementsConditionallyShown,\n} from '../../types/form'\nimport validateSubmission from './validateSubmission'\nimport {\n generateLookupValidationMessage,\n getInvalidAttachment,\n} from './validators'\nimport { validators } from './validate-dot-js'\n\nconst validationExtensions = {\n lookups({\n executedLookups,\n formElement,\n }: {\n formElement: FormTypes.LookupFormElement &\n FormTypes.FormElementRequired & {\n type: FormTypes.FormElement['type']\n }\n executedLookups: ExecutedLookups\n }): string[] {\n if (!formElement.isDataLookup && !formElement.isElementLookup) {\n return []\n }\n\n // Lookups must only be executed on required form elements\n if (!formElement.required) {\n return []\n }\n\n const elementExecutedLookups = executedLookups?.[formElement.name]\n if (elementExecutedLookups === true) {\n return []\n }\n\n return [\n generateLookupValidationMessage(\n formElement.lookupButton,\n formElement.type === 'lookupButton'\n ? formElement.requiredMessage\n : undefined,\n ),\n ]\n },\n\n presence(\n value: unknown,\n { required, requiredMessage }: FormTypes.FormElementRequired,\n message: string,\n ) {\n if (required) {\n return validators.presence(value, {\n message: requiredMessage || message,\n })\n }\n return []\n },\n\n regex<DefaultValue>(\n value: unknown,\n formElement: FormTypes.FormElementWithInput<DefaultValue>,\n ) {\n if (formElement.regexPattern) {\n return validators.regexValidation(value, {\n pattern: formElement.regexPattern,\n flags: formElement.regexFlags,\n message: formElement.regexMessage,\n })\n }\n return []\n },\n\n attachment(value: unknown): string[] {\n const attachmentError = getInvalidAttachment(value)\n if (attachmentError) {\n return [attachmentError.errorMessage]\n }\n return []\n },\n\n numberRegex(value: unknown, formElement: FormTypes.NumberElement) {\n if (\n formElement.regexPattern &&\n typeof value === 'number' &&\n !Number.isNaN(value)\n ) {\n return validationExtensions.regex(value.toString(), formElement)\n }\n return []\n },\n\n nestedElements(\n value: unknown,\n {\n formElement,\n formElements,\n formElementsConditionallyShown,\n executedLookups,\n captchaType,\n isOffline,\n audience,\n editableFormElementIds,\n approverEditableFormElementIds,\n }: {\n formElement: FormTypes.FormElementWithName\n formElements: FormTypes.FormElementWithName[] | undefined\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined\n executedLookups: ExecutedLookups\n captchaType: CaptchaType\n isOffline: boolean\n audience: FormTypes.FormElementHiddenFromAudience\n editableFormElementIds?: string[]\n approverEditableFormElementIds?: string[]\n },\n ) {\n if (formElements) {\n const nestedExecutedLookupsValue =\n executedLookups !== undefined &&\n typeof executedLookups !== 'boolean' &&\n !Array.isArray(executedLookups)\n ? executedLookups[formElement.name]\n : {}\n\n const formElementConditionallyShown =\n formElementsConditionallyShown?.[formElement.name]\n const errors = validateSubmission({\n elements: formElements as FormTypes.FormElementWithName[],\n submission: value as SubmissionTypes.S3SubmissionData['submission'],\n formElementsConditionallyShown:\n formElementConditionallyShown?.type === 'formElements'\n ? formElementConditionallyShown.formElements\n : undefined,\n executedLookups:\n typeof nestedExecutedLookupsValue !== 'boolean' &&\n !Array.isArray(nestedExecutedLookupsValue)\n ? nestedExecutedLookupsValue\n : {},\n captchaType,\n isOffline,\n audience,\n editableFormElementIds,\n approverEditableFormElementIds,\n })\n if (errors) {\n return {\n type: 'formElements' as const,\n formElements: errors,\n }\n }\n }\n },\n\n offline(isOffline: boolean, message: string) {\n return isOffline ? [message] : []\n },\n}\n\nexport default validationExtensions\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function getApproverEditableFormElementIds(approvalSteps) {
|
|
2
|
+
var _a;
|
|
3
|
+
const editableFormElementIds = new Set();
|
|
4
|
+
for (const step of approvalSteps !== null && approvalSteps !== void 0 ? approvalSteps : []) {
|
|
5
|
+
const nodes = step.type === 'CONCURRENT' ? step.nodes : [step];
|
|
6
|
+
for (const node of nodes) {
|
|
7
|
+
for (const formElementId of (_a = node.editableFormElementIds) !== null && _a !== void 0 ? _a : []) {
|
|
8
|
+
editableFormElementIds.add(formElementId);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return [...editableFormElementIds];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=getApproverEditableFormElementIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getApproverEditableFormElementIds.js","sourceRoot":"","sources":["../../../src/services/form-validation/getApproverEditableFormElementIds.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,iCAAiC,CACvD,aAA+D;;IAE/D,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhD,KAAK,MAAM,IAAI,IAAI,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,EAAE,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAC9D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,KAAK,MAAM,aAAa,IAAI,MAAA,IAAI,CAAC,sBAAsB,mCAAI,EAAE,EAAE,CAAC;gBAC9D,sBAAsB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,sBAAsB,CAAC,CAAA;AACpC,CAAC","sourcesContent":["import { ApprovalTypes } from '@oneblink/types'\n\nexport default function getApproverEditableFormElementIds(\n approvalSteps: ApprovalTypes.FormApprovalFlowStep[] | undefined,\n): string[] {\n const editableFormElementIds = new Set<string>()\n\n for (const step of approvalSteps ?? []) {\n const nodes = step.type === 'CONCURRENT' ? step.nodes : [step]\n for (const node of nodes) {\n for (const formElementId of node.editableFormElementIds ?? []) {\n editableFormElementIds.add(formElementId)\n }\n }\n }\n\n return [...editableFormElementIds]\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FormTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
2
|
import { CaptchaType, ExecutedLookups, FormElementsConditionallyShown, FormElementsValidation } from '../../types/form';
|
|
3
3
|
export declare const RECAPTCHA_OFFLINE_MESSAGE = "We could not verify you are human while you are offline.";
|
|
4
|
-
export default function validateSubmission({ elements, submission, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds, }: {
|
|
4
|
+
export default function validateSubmission({ elements, submission, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds, approverEditableFormElementIds, }: {
|
|
5
5
|
elements: FormTypes.FormElementWithName[];
|
|
6
6
|
submission: SubmissionTypes.S3SubmissionData['submission'];
|
|
7
7
|
formElementsConditionallyShown: FormElementsConditionallyShown | undefined;
|
|
@@ -10,4 +10,5 @@ export default function validateSubmission({ elements, submission, formElementsC
|
|
|
10
10
|
isOffline: boolean;
|
|
11
11
|
audience: FormTypes.FormElementHiddenFromAudience;
|
|
12
12
|
editableFormElementIds?: string[];
|
|
13
|
+
approverEditableFormElementIds?: string[];
|
|
13
14
|
}): FormElementsValidation | undefined;
|
|
@@ -9,9 +9,10 @@ import { generateConfirmationFormElementName } from '../dynamic-elements';
|
|
|
9
9
|
import { determineLookupButtonIsRequired } from './determineLookupButtonIsRequired';
|
|
10
10
|
import { defaultAutoSnapshotButtonLabel, generateArcGISAutomatedSnapshotFileName, } from '../../form-elements/FormElementArcGISWebMap';
|
|
11
11
|
import { fileUploadService } from '@oneblink/sdk-core';
|
|
12
|
-
import { checkIsFormElementEditable, checkIsFormElementIdEditable, } from '../../utils/read-only-form-elements';
|
|
12
|
+
import { checkIsFormElementEditable, checkIsFormElementIdEditable, getNestedEditableFormElementIds, } from '../../utils/read-only-form-elements';
|
|
13
|
+
import isElementHiddenForAudience from '../isElementHiddenForAudience';
|
|
13
14
|
export const RECAPTCHA_OFFLINE_MESSAGE = 'We could not verify you are human while you are offline.';
|
|
14
|
-
export default function validateSubmission({ elements, submission, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds, }) {
|
|
15
|
+
export default function validateSubmission({ elements, submission, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds, approverEditableFormElementIds, }) {
|
|
15
16
|
const formElementsValidation = elements.reduce((partialFormElementsValidation, formElement) => {
|
|
16
17
|
var _a, _b, _c, _d, _e;
|
|
17
18
|
switch (formElement.type) {
|
|
@@ -29,6 +30,13 @@ export default function validateSubmission({ elements, submission, formElementsC
|
|
|
29
30
|
if (formElementConditionallyShown === null || formElementConditionallyShown === void 0 ? void 0 : formElementConditionallyShown.isHidden) {
|
|
30
31
|
return partialFormElementsValidation;
|
|
31
32
|
}
|
|
33
|
+
// Approver-editable elements hidden from submitters are completed later.
|
|
34
|
+
// Ignore all validation here, including invalid prefilled values.
|
|
35
|
+
if (audience === 'SUBMITTER' &&
|
|
36
|
+
isElementHiddenForAudience(formElement, audience) &&
|
|
37
|
+
(approverEditableFormElementIds === null || approverEditableFormElementIds === void 0 ? void 0 : approverEditableFormElementIds.includes(formElement.id))) {
|
|
38
|
+
return partialFormElementsValidation;
|
|
39
|
+
}
|
|
32
40
|
// A user that cannot change this element, or anything nested inside it,
|
|
33
41
|
// has no way to resolve an error on it. Reviewers still see the page
|
|
34
42
|
// navigation buttons and can submit the form by pressing Enter, either of
|
|
@@ -464,6 +472,7 @@ export default function validateSubmission({ elements, submission, formElementsC
|
|
|
464
472
|
isOffline,
|
|
465
473
|
audience,
|
|
466
474
|
editableFormElementIds,
|
|
475
|
+
approverEditableFormElementIds,
|
|
467
476
|
});
|
|
468
477
|
if (entryValidation) {
|
|
469
478
|
errorsByIndex[index] = entryValidation;
|
|
@@ -490,6 +499,7 @@ export default function validateSubmission({ elements, submission, formElementsC
|
|
|
490
499
|
isOffline,
|
|
491
500
|
audience,
|
|
492
501
|
editableFormElementIds,
|
|
502
|
+
approverEditableFormElementIds,
|
|
493
503
|
});
|
|
494
504
|
if (nestedFormValidation) {
|
|
495
505
|
partialFormElementsValidation[formElement.name] =
|
|
@@ -499,6 +509,8 @@ export default function validateSubmission({ elements, submission, formElementsC
|
|
|
499
509
|
}
|
|
500
510
|
case 'infoPage':
|
|
501
511
|
case 'form': {
|
|
512
|
+
const nestedEditableFormElementIds = getNestedEditableFormElementIds(formElement, editableFormElementIds);
|
|
513
|
+
const nestedApproverEditableFormElementIds = getNestedEditableFormElementIds(formElement, approverEditableFormElementIds);
|
|
502
514
|
const nestedFormValidation = validationExtensions.nestedElements(value, {
|
|
503
515
|
formElement,
|
|
504
516
|
formElements: formElement.elements,
|
|
@@ -507,7 +519,8 @@ export default function validateSubmission({ elements, submission, formElementsC
|
|
|
507
519
|
captchaType,
|
|
508
520
|
isOffline,
|
|
509
521
|
audience,
|
|
510
|
-
editableFormElementIds,
|
|
522
|
+
editableFormElementIds: nestedEditableFormElementIds,
|
|
523
|
+
approverEditableFormElementIds: nestedApproverEditableFormElementIds,
|
|
511
524
|
});
|
|
512
525
|
if (nestedFormValidation) {
|
|
513
526
|
partialFormElementsValidation[formElement.name] =
|
|
@@ -526,6 +539,7 @@ export default function validateSubmission({ elements, submission, formElementsC
|
|
|
526
539
|
isOffline,
|
|
527
540
|
audience,
|
|
528
541
|
editableFormElementIds,
|
|
542
|
+
approverEditableFormElementIds,
|
|
529
543
|
});
|
|
530
544
|
if (nestedFormValidation) {
|
|
531
545
|
partialFormElementsValidation[formElement.name] =
|