@oneblink/apps-react 13.0.0-beta.3 → 13.0.0-beta.4
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.d.ts +23 -3
- package/dist/OneBlinkFormBase.js +38 -7
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/OneBlinkReadOnlyForm.d.ts +17 -7
- package/dist/OneBlinkReadOnlyForm.js +24 -8
- package/dist/OneBlinkReadOnlyForm.js.map +1 -1
- package/dist/components/renderer/LookupNotification.js +8 -12
- package/dist/components/renderer/LookupNotification.js.map +1 -1
- package/dist/components/renderer/OneBlinkFormElements.d.ts +5 -7
- package/dist/components/renderer/OneBlinkFormElements.js +10 -35
- package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
- package/dist/components/renderer/ReverseGeocode.js +4 -11
- package/dist/components/renderer/ReverseGeocode.js.map +1 -1
- package/dist/form-elements/FormElementForm.d.ts +8 -9
- package/dist/form-elements/FormElementForm.js.map +1 -1
- package/dist/form-elements/FormElementRepeatableSet.d.ts +4 -4
- package/dist/form-elements/FormElementRepeatableSet.js.map +1 -1
- package/dist/form-elements/FormElementSection.d.ts +3 -3
- package/dist/form-elements/FormElementSection.js.map +1 -1
- package/dist/hooks/useAreLookupsDisallowed.d.ts +2 -0
- package/dist/hooks/useAreLookupsDisallowed.js +12 -0
- package/dist/hooks/useAreLookupsDisallowed.js.map +1 -0
- package/dist/hooks/useEditableFormElementIds.d.ts +3 -0
- package/dist/hooks/useEditableFormElementIds.js +6 -0
- package/dist/hooks/useEditableFormElementIds.js.map +1 -0
- package/dist/hooks/useFormSubmissionAttempt.d.ts +88 -0
- package/dist/hooks/useFormSubmissionAttempt.js +103 -0
- package/dist/hooks/useFormSubmissionAttempt.js.map +1 -0
- package/dist/hooks/useFormValidation.d.ts +1 -1
- package/dist/hooks/useFormValidation.js +2 -1
- package/dist/hooks/useFormValidation.js.map +1 -1
- package/dist/hooks/useIsFormElementReadOnly.d.ts +2 -0
- package/dist/hooks/useIsFormElementReadOnly.js +13 -0
- package/dist/hooks/useIsFormElementReadOnly.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.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/validateSubmission.d.ts +2 -1
- package/dist/services/form-validation/validateSubmission.js +14 -9
- package/dist/services/form-validation/validateSubmission.js.map +1 -1
- package/dist/utils/read-only-form-elements.d.ts +37 -0
- package/dist/utils/read-only-form-elements.js +63 -0
- package/dist/utils/read-only-form-elements.js.map +1 -0
- package/package.json +2 -1
- package/dist/services/isElementReadOnlyForAudience.d.ts +0 -20
- package/dist/services/isElementReadOnlyForAudience.js +0 -46
- package/dist/services/isElementReadOnlyForAudience.js.map +0 -1
- package/dist/services/resolveFormElementReadOnly.d.ts +0 -10
- package/dist/services/resolveFormElementReadOnly.js +0 -17
- package/dist/services/resolveFormElementReadOnly.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElementRepeatableSet.js","sourceRoot":"","sources":["../../src/form-elements/FormElementRepeatableSet.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,mBAAmB,EAAE,EAC1B,sBAAsB,EACtB,6BAA6B,GAC9B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAC9E,OAAO,KAAK,MAAM,8BAA8B,CAAA;AAChD,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AACxF,OAAO,kBAAkB,MAAM,6BAA6B,CAAA;AAa5D,OAAO,kCAAkC,MAAM,6CAA6C,CAAA;AAC5F,OAAO,yBAAyB,M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L,OAAO,EACP,QAAQ,EACR,OAAO,GAQR;IACC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,IAAI,CACb,uEAAuE,EACvE,OAAO,CACR,EACD,OAAO,EAAE,KAAK,EACd,QAAQ,EAAE,QAAQ,gBACN,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAC9D,EAAE,EAAE,EAAE,aAEN,eAAM,SAAS,EAAC,MAAM,YACpB,KAAC,YAAY,sBAAmB,GAC3B,EACN,CAAC,CAAC,OAAO,CAAC,gBAAgB,IAAI,yBAAO,OAAO,CAAC,gBAAgB,GAAQ,IAC/D,CACV,CAAA;AACH,CAAC;AAED,SAAS,YAAY,CAAC,EACpB,eAAe,EACf,OAAO,EACP,QAAQ,EACR,SAAS,EACT,KAAK,GAON;;IACC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,IAAI,CACb,gFAAgF,EAChF,SAAS,CACV,EACD,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,QAAQ,gBACN,GAAG,MAAA,OAAO,CAAC,mBAAmB,mCAAI,cAAc,IAAI,KAAK,GAAG,CAAC,EAAE,aAE3E,eAAM,SAAS,EAAC,MAAM,YACpB,KAAC,YAAY,iCAA8B,GACtC,EACN,CAAC,CAAC,OAAO,CAAC,mBAAmB,IAAI,CAChC,yBAAO,OAAO,CAAC,mBAAmB,GAAQ,CAC3C,IACM,CACV,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport clsx from 'clsx'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport useBooleanState from '../hooks/useBooleanState'\nimport generateDefaultData, {\n ENTRY_ID_PROPERTY_NAME,\n generateNewRepeatableSetEntry,\n} from '../services/generate-default-data'\nimport OneBlinkFormElements from '../components/renderer/OneBlinkFormElements'\nimport Modal from '../components/renderer/Modal'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport useValidationClass from '../hooks/useValidationClass'\nimport {\n ExecutedLookups,\n FormElementConditionallyShown,\n FormElementLookupHandler,\n FormElementsConditionallyShown,\n FormElementsValidation,\n FormElementValidation,\n NestedFormElementValueChangeHandler,\n IsDirtyProps,\n UpdateFormElementsHandler,\n SectionState,\n} from '../types/form'\nimport useFormElementRepeatableSetEntries from '../hooks/useFormElementRepeatableSetEntries'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport MaterialIcon from '../components/MaterialIcon'\nimport ElementDOMId from '../utils/elementDOMIds'\nimport { Collapse } from '@mui/material'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype Props = {\n formId: number\n id: string\n isEven: boolean\n element: FormTypes.RepeatableSetElement\n /**\n * Whether this set’s own controls (add/remove entries) are locked.\n * Includes audience lock, so an approver may be unable to add or remove\n * entries even when a nested `ALL_STEPS` field is still editable.\n */\n readOnly: boolean\n /**\n * Lock to apply to fields inside each entry. True when the whole form is\n * read-only, a parent is read-only, or this element’s definition has\n * `readOnly: true`. Does not include this set’s audience lock.\n */\n childrenReadOnly: boolean\n value: Array<SubmissionTypes.S3SubmissionData['submission']> | undefined\n onChange: NestedFormElementValueChangeHandler<\n SubmissionTypes.S3SubmissionData['submission'][]\n >\n onLookup: FormElementLookupHandler\n formElementConditionallyShown: FormElementConditionallyShown | undefined\n formElementValidation: FormElementValidation | undefined\n displayValidationMessage: boolean\n onUpdateFormElements: UpdateFormElementsHandler\n sectionState: SectionState\n} & IsDirtyProps\n\nconst RepeatableSetIndexContext = React.createContext<number>(0)\n\nfunction RepeatableSetEntryProvider({\n index,\n isAnimated,\n element,\n idPrefix,\n onRemove,\n children,\n}: {\n isAnimated: boolean\n index: number\n element: FormTypes.RepeatableSetElement\n idPrefix?: string\n onRemove: (\n index: number,\n element: FormTypes.RepeatableSetElement,\n idPrefix?: string,\n ) => void\n children: (renderProps: { onRemove: () => void }) => React.ReactNode\n}) {\n const [isExpanded, setIsExpanded] = React.useState(true)\n\n const handleRemove = React.useCallback(() => {\n if (isAnimated) {\n setIsExpanded(false)\n } else {\n onRemove(index, element, idPrefix)\n }\n }, [index, isAnimated, onRemove, element, idPrefix])\n\n const node = (\n <RepeatableSetIndexContext.Provider value={index}>\n {children({\n onRemove: handleRemove,\n })}\n </RepeatableSetIndexContext.Provider>\n )\n\n if (!isAnimated) {\n return node\n }\n\n return (\n <Collapse\n in={isExpanded}\n appear\n onExited={() => {\n onRemove(index, element, idPrefix)\n }}\n classes={{\n root: 'ob-repeatable-set__collapsible',\n wrapper: 'ob-repeatable-set__collapsible-wrapper',\n wrapperInner: 'ob-repeatable-set__collapsible-wrapper-inner',\n }}\n >\n {node}\n </Collapse>\n )\n}\n\nexport function useRepeatableSetIndexText(text: string) {\n const index = React.useContext(RepeatableSetIndexContext)\n return React.useMemo(\n () => text.replace('{INDEX}', (index + 1).toString()),\n [index, text],\n )\n}\n\nfunction FormElementRepeatableSet({\n formId,\n element,\n readOnly,\n childrenReadOnly,\n value,\n formElementValidation,\n id,\n isEven,\n displayValidationMessage,\n formElementConditionallyShown,\n onChange,\n onLookup,\n onUpdateFormElements,\n isDirty,\n setIsDirty,\n sectionState,\n}: Props) {\n const entries = React.useMemo(\n () => (Array.isArray(value) ? value : []),\n [value],\n )\n\n const handleAddEntry = React.useCallback(\n (index: number) => {\n onChange(element, {\n value: (existingEntries) => {\n const newEntries = [...(existingEntries || [])]\n const entry = generateDefaultData(\n element.elements,\n generateNewRepeatableSetEntry(),\n )\n\n newEntries.splice(index, 0, entry)\n return newEntries\n },\n executedLookups: (existingExecutedLookups) => {\n if (\n existingExecutedLookups !== undefined &&\n !Array.isArray(existingExecutedLookups)\n ) {\n return []\n }\n\n const newExistingExecutedLookups = [\n ...((existingExecutedLookups as ExecutedLookups[]) ??\n Array.from(Array(entries.length))),\n ]\n newExistingExecutedLookups.push({})\n return newExistingExecutedLookups\n },\n sectionState: (currentSectionState) => {\n return (\n currentSectionState?.map((section) => {\n const idPrefixPattern = new RegExp(\n `(.+)?${element.name}_entry-(.+)_(.+)`,\n )\n const entryIdPrefixMatches = section.id.match(idPrefixPattern)\n\n if (entryIdPrefixMatches) {\n const startOfId = entryIdPrefixMatches[1]\n const entryIndex = parseInt(entryIdPrefixMatches[2])\n const restOfId = entryIdPrefixMatches[3]\n\n if (entryIndex >= index) {\n const newEntryIndex = entryIndex + 1\n section.id = `${startOfId ? startOfId : ''}${element.name}_entry-${newEntryIndex}_${restOfId}`\n }\n }\n\n return section\n }, []) || []\n )\n },\n })\n setIsDirty()\n },\n [element, onChange, setIsDirty, entries.length],\n )\n\n const handleRemoveEntry = React.useCallback(\n (\n index: number,\n element: FormTypes.RepeatableSetElement,\n idPrefix?: string,\n ) => {\n const entryIdPrefix = idPrefix || ''\n\n onChange(element, {\n value: (existingEntries) => {\n const newEntries = [...(existingEntries || [])]\n newEntries.splice(index, 1)\n return newEntries\n },\n executedLookups: (existingExecutedLookups) => {\n if (!Array.isArray(existingExecutedLookups)) {\n return []\n }\n const newExistingExecutedLookups = [...existingExecutedLookups]\n\n newExistingExecutedLookups.splice(index, 1)\n return newExistingExecutedLookups\n },\n sectionState: (currentSectionState) => {\n return (\n currentSectionState?.reduce(\n (\n state: {\n id: string\n state: 'COLLAPSED' | 'EXPANDED'\n }[],\n section,\n ) => {\n const idPrefixPattern = new RegExp(\n `(.+)?${element.name}_entry-(\\\\d+)`,\n )\n const entryIdPrefixMatches =\n entryIdPrefix.match(idPrefixPattern)\n if (\n !section.id.startsWith(entryIdPrefix) &&\n entryIdPrefixMatches\n ) {\n const parentElementPath =\n entryIdPrefixMatches[1] || `${element.name}_entry`\n // only update nested sections where the parent path matches the entry that was removed\n if (section.id.startsWith(parentElementPath)) {\n // Match pattern: {elementName}_entry-{index}_\n // also yields a prefix and suffix for any match found\n const idPrefixWithFullIdPattern = new RegExp(\n `(.+)?${element.name}_entry-(\\\\d+)_(.+)`,\n )\n const match = section.id.match(idPrefixWithFullIdPattern)\n\n if (match) {\n const oldEntryIndex = parseInt(match[2], 10)\n if (oldEntryIndex > index) {\n const prefix = match[1]\n const restOfId = match[3]\n const newEntryIndex = oldEntryIndex - 1\n section.id = `${prefix ? prefix : ''}${element.name}_entry-${newEntryIndex}_${restOfId}`\n }\n }\n }\n\n state.push(section)\n }\n\n return state\n },\n [],\n ) || []\n )\n },\n })\n setIsDirty()\n },\n [onChange, setIsDirty],\n )\n\n const handleNestedChange = React.useCallback(\n (\n index: number,\n nestedElement: FormTypes.FormElement,\n {\n value,\n executedLookups,\n sectionState,\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)) {\n return\n }\n onChange(element, {\n value: (existingEntries) => {\n const newEntries = (existingEntries || []).map((entry, i) => {\n if (i === index) {\n return {\n ...entry,\n [nestedElement.name]:\n typeof value === 'function'\n ? value(entry[nestedElement.name])\n : value,\n }\n } else {\n return entry\n }\n })\n return newEntries\n },\n executedLookups: (existingExecutedLookups) => {\n const elementExecutedLookups = existingExecutedLookups ?? []\n if (!Array.isArray(elementExecutedLookups)) {\n return elementExecutedLookups\n }\n const newExecutedLookups = elementExecutedLookups.map(\n (executedLookup, i) => {\n if (i === index) {\n const updatedExecutedLookups =\n typeof executedLookups === 'function'\n ? executedLookups(executedLookup?.[nestedElement.name])\n : executedLookups\n return {\n ...executedLookup,\n [nestedElement.name]: updatedExecutedLookups,\n }\n }\n return executedLookup\n },\n )\n return newExecutedLookups\n },\n sectionState,\n })\n },\n [element, onChange],\n )\n\n const { minSetEntries, maxSetEntries } =\n useFormElementRepeatableSetEntries(element)\n\n const repeatableSetValidation = React.useMemo(\n () =>\n !formElementValidation ||\n typeof formElementValidation === 'string' ||\n formElementValidation.type !== 'repeatableSet'\n ? undefined\n : formElementValidation,\n [formElementValidation],\n )\n\n const repeatableSetEntriesConditionallyShown =\n formElementConditionallyShown &&\n formElementConditionallyShown.type === 'repeatableSet'\n ? formElementConditionallyShown.entries\n : {}\n\n const { validationClassName } = useValidationClass({\n formElementsValid: !repeatableSetValidation,\n displayInvalidClassName: isDirty || displayValidationMessage,\n validClassName: 'ob-repeatable-set-element__valid',\n invalidClassName: 'ob-repeatable-set-element__invalid',\n })\n\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n\n const showAddButton = React.useMemo(\n () => !maxSetEntries || entries.length < maxSetEntries,\n [maxSetEntries, entries.length],\n )\n\n const repeatableSetContainerClass = React.useMemo(() => {\n const prefix = 'ob-repeatable-set-container-layout__'\n switch (element.layout) {\n case 'MULTIPLE_ADD_BUTTONS':\n return prefix + 'multiple-add-buttons'\n default:\n return 'single-add-button'\n }\n }, [element.layout])\n\n return (\n <div\n className={clsx('cypress-repeatable-set-element', validationClassName)}\n aria-labelledby={`${id}-label`}\n aria-describedby={ariaDescribedby}\n role=\"region\"\n >\n {/* */}\n <FormElementLabelContainer\n className={clsx(\n 'ob-repeatable-set',\n isEven ? 'even' : 'odd',\n repeatableSetContainerClass,\n )}\n element={element}\n id={id}\n required={!!minSetEntries && minSetEntries > 0}\n associateLabelWithInput={false}\n >\n {element.layout === 'MULTIPLE_ADD_BUTTONS' && showAddButton && (\n <AddButton\n onAdd={() => handleAddEntry(0)}\n element={element}\n readOnly={readOnly}\n classes={['ob-button-repeatable-set-layout__multiple-add-buttons']}\n id={id}\n />\n )}\n {entries.map((entry, index) => {\n return (\n <RepeatableSetEntry\n key={entry[ENTRY_ID_PROPERTY_NAME] as string}\n formId={formId}\n index={index}\n id={id}\n isEven={isEven}\n entry={entry}\n element={element}\n readOnly={readOnly}\n childrenReadOnly={childrenReadOnly}\n showAddButton={\n element.layout === 'MULTIPLE_ADD_BUTTONS' && showAddButton\n }\n onChange={handleNestedChange}\n onLookup={onLookup}\n onAdd={handleAddEntry}\n onRemove={handleRemoveEntry}\n formElementsConditionallyShown={\n repeatableSetEntriesConditionallyShown[index.toString()]\n }\n formElementsValidation={\n repeatableSetValidation &&\n repeatableSetValidation.entries[index.toString()]\n }\n displayValidationMessages={displayValidationMessage}\n onUpdateFormElements={onUpdateFormElements}\n sectionState={sectionState}\n />\n )\n })}\n {(!element.layout || element.layout === 'SINGLE_ADD_BUTTON') &&\n showAddButton && (\n <AddButton\n onAdd={() => handleAddEntry(entries.length)}\n element={element}\n readOnly={readOnly}\n id={id}\n />\n )}\n {(isDirty || displayValidationMessage) &&\n !!repeatableSetValidation &&\n !!repeatableSetValidation.set && (\n <FormElementValidationMessage\n message={repeatableSetValidation.set}\n />\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nexport default React.memo(FormElementRepeatableSet)\n\ntype RepeatableSetEntryProps = {\n formId: number\n id: string\n index: number\n isEven: boolean\n entry: SubmissionTypes.S3SubmissionData['submission']\n element: FormTypes.RepeatableSetElement\n /**\n * Whether this entry’s add/remove controls are locked. See\n * `FormElementRepeatableSet` `readOnly`.\n */\n readOnly: boolean\n /**\n * Lock to apply to fields in this entry. See `FormElementRepeatableSet`\n * `childrenReadOnly`.\n */\n childrenReadOnly: boolean\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined\n formElementsValidation: FormElementsValidation | undefined\n displayValidationMessages: boolean\n showAddButton: boolean\n onChange: (\n index: number,\n formElement: FormTypes.FormElement,\n {\n value,\n executedLookups,\n }: Parameters<NestedFormElementValueChangeHandler>[1],\n idPrefix?: string,\n ) => void\n onLookup: FormElementLookupHandler\n onAdd: (index: number) => unknown\n onRemove: (\n index: number,\n element: FormTypes.RepeatableSetElement,\n idPrefix?: string,\n ) => unknown\n onUpdateFormElements: UpdateFormElementsHandler\n sectionState: SectionState\n}\n\nconst RepeatableSetEntry = React.memo<RepeatableSetEntryProps>(\n function RepeatableSetEntry({\n formId,\n id,\n index,\n isEven,\n entry,\n element,\n readOnly,\n childrenReadOnly,\n formElementsConditionallyShown,\n displayValidationMessages,\n formElementsValidation,\n onChange,\n onLookup,\n onAdd,\n onRemove,\n onUpdateFormElements,\n showAddButton,\n sectionState,\n }: RepeatableSetEntryProps) {\n const [isConfirmingRemove, confirmRemove, cancelRemove] =\n useBooleanState(false)\n const elementDOMId = React.useMemo(() => new ElementDOMId(id), [id])\n\n const handleChange: NestedFormElementValueChangeHandler = React.useCallback(\n (nestedElement, { value, executedLookups, sectionState }, idPrefix) => {\n onChange(\n index,\n nestedElement,\n {\n value,\n executedLookups,\n sectionState,\n },\n idPrefix,\n )\n },\n [index, onChange],\n )\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults) => {\n onLookup((currentFormSubmission) => {\n let newEntry = {}\n const entries = currentFormSubmission.submission[\n element.name\n ] as Array<SubmissionTypes.S3SubmissionData['submission']>\n const repeatableSetExecutedLookups =\n (currentFormSubmission.executedLookups?.[\n element.name\n ] as ExecutedLookups[]) ?? Array.from(Array(entries.length))\n // if the repeatable set is prefilled or has minimum entries then executed lookups exists,\n // but is an empty array\n for (let i = 0; i < entries.length; i++) {\n if (!repeatableSetExecutedLookups[index]) {\n repeatableSetExecutedLookups[index] = {}\n }\n }\n let newExecutedLookups: ExecutedLookups = {}\n const elements = currentFormSubmission.elements.map((formElement) => {\n if (\n formElement.type === 'repeatableSet' &&\n formElement.name === element.name\n ) {\n const { elements, submission, executedLookups } =\n mergeLookupResults({\n elements: formElement.elements,\n submission: entries[index],\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: repeatableSetExecutedLookups[index] ?? {},\n sectionState: currentFormSubmission.sectionState,\n })\n newEntry = 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]: entries.map((entry, i) => {\n if (i === index) {\n return newEntry\n }\n return entry\n }),\n }\n\n let updatedExecutedLookups = currentFormSubmission.executedLookups\n if (Array.isArray(repeatableSetExecutedLookups)) {\n updatedExecutedLookups = {\n ...currentFormSubmission.executedLookups,\n [element.name]: repeatableSetExecutedLookups.map((entry, i) => {\n if (i == index) {\n return newExecutedLookups\n }\n return entry\n }),\n }\n }\n\n return {\n elements,\n submission,\n executedLookups: updatedExecutedLookups,\n }\n })\n },\n [element.name, index, onLookup],\n )\n\n const { validationClassName } = useValidationClass({\n formElementsValid: !formElementsValidation,\n displayInvalidClassName: displayValidationMessages,\n validClassName: 'ob-repeatable-set__valid',\n invalidClassName: 'ob-repeatable-set__invalid',\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 === 'repeatableSet'\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 idPrefix = elementDOMId.repeatableSetEntryDOMIdPrefix(\n index.toString(),\n )\n\n return (\n <RepeatableSetEntryProvider\n index={index}\n element={element}\n idPrefix={idPrefix}\n onRemove={onRemove}\n isAnimated={element.layout === 'MULTIPLE_ADD_BUTTONS'}\n >\n {({ onRemove }) => (\n <>\n <Modal\n isOpen={isConfirmingRemove}\n className=\"cypress-repeatable-set-prompt\"\n titleClassName=\"cypress-repeatable-set-remove-entry-header\"\n title={element.removeSetEntryLabel || 'Remove Entry'}\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button is-light cypress-cancel-repeatable-set\"\n onClick={cancelRemove}\n >\n Cancel\n </button>\n <button\n type=\"button\"\n className=\"button ob-button is-primary cypress-confirm-repeatable-set\"\n onClick={() => {\n cancelRemove()\n onRemove()\n }}\n autoFocus\n >\n Yes\n </button>\n </>\n }\n >\n Are you sure you want to remove this entry?\n </Modal>\n\n <div\n className={clsx(\n 'ob-repeatable-set__container cypress-repeatable-set-container',\n validationClassName,\n )}\n >\n {(!element.layout || element.layout === 'SINGLE_ADD_BUTTON') && (\n <RemoveButton\n onConfirmRemove={confirmRemove}\n element={element}\n readOnly={readOnly}\n className=\"ob-repeatable-set__button-remove-top\"\n index={index}\n />\n )}\n\n <OneBlinkFormElements\n formId={formId}\n idPrefix={idPrefix}\n isEven={isEven}\n formElementsValidation={formElementsValidation}\n displayValidationMessages={displayValidationMessages}\n elements={element.elements}\n onChange={handleChange}\n onLookup={handleLookup}\n model={entry}\n parentElement={element}\n readOnly={childrenReadOnly}\n formElementsConditionallyShown={formElementsConditionallyShown}\n onUpdateFormElements={handleUpdateNestedFormElements}\n sectionState={sectionState}\n />\n {element.layout === 'MULTIPLE_ADD_BUTTONS' && (\n <RemoveButton\n onConfirmRemove={confirmRemove}\n element={element}\n readOnly={readOnly}\n index={index}\n className=\"ob-repeatable-set__button-remove-bottom\"\n />\n )}\n </div>\n {showAddButton && (\n <AddButton\n onAdd={() => onAdd(index + 1)}\n element={element}\n readOnly={readOnly}\n classes={[\n 'ob-button-repeatable-set-layout__multiple-add-buttons',\n ]}\n />\n )}\n </>\n )}\n </RepeatableSetEntryProvider>\n )\n },\n)\n\nfunction AddButton({\n id,\n onAdd,\n element,\n readOnly,\n classes,\n}: {\n id?: string\n onAdd: () => void\n element: FormTypes.RepeatableSetElement\n readOnly: boolean\n isPrimary?: boolean\n classes?: string[]\n}) {\n return (\n <button\n type=\"button\"\n className={clsx(\n 'button ob-button ob-button__add cypress-add-repeatable-set is-primary',\n classes,\n )}\n onClick={onAdd}\n disabled={readOnly}\n aria-label={element.addSetEntryLabel ? undefined : 'Add Entry'}\n id={id}\n >\n <span className=\"icon\">\n <MaterialIcon>add</MaterialIcon>\n </span>\n {!!element.addSetEntryLabel && <span>{element.addSetEntryLabel}</span>}\n </button>\n )\n}\n\nfunction RemoveButton({\n onConfirmRemove,\n element,\n readOnly,\n className,\n index,\n}: {\n onConfirmRemove: () => void\n element: FormTypes.RepeatableSetElement\n readOnly: boolean\n className?: string\n index: number\n}) {\n return (\n <button\n type=\"button\"\n className={clsx(\n 'button ob-button ob-button_remove is-light cypress-remove-repeatable-set-entry',\n className,\n )}\n onClick={onConfirmRemove}\n disabled={readOnly}\n aria-label={`${element.removeSetEntryLabel ?? 'Remove Entry'} ${index + 1}`}\n >\n <span className=\"icon\">\n <MaterialIcon>delete_outline</MaterialIcon>\n </span>\n {!!element.removeSetEntryLabel && (\n <span>{element.removeSetEntryLabel}</span>\n )}\n </button>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FormElementRepeatableSet.js","sourceRoot":"","sources":["../../src/form-elements/FormElementRepeatableSet.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,mBAAmB,EAAE,EAC1B,sBAAsB,EACtB,6BAA6B,GAC9B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAC9E,OAAO,KAAK,MAAM,8BAA8B,CAAA;AAChD,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AACxF,OAAO,kBAAkB,MAAM,6BAA6B,CAAA;AAa5D,OAAO,kCAAkC,MAAM,6CAA6C,CAAA;AAC5F,OAAO,yBAAyB,MAAM,oCAAoC,CAAA;AAC1E,OAAO,YAAY,MAAM,4BAA4B,CAAA;AACrD,OAAO,YAAY,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,4BAA4B,MAAM,qDAAqD,CAAA;AA+B9F,MAAM,yBAAyB,GAAG,KAAK,CAAC,aAAa,CAAS,CAAC,CAAC,CAAA;AAEhE,SAAS,0BAA0B,CAAC,EAClC,KAAK,EACL,UAAU,EACV,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,QAAQ,GAYT;IACC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,I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AA;AACH,CAAC;AAED,SAAS,YAAY,CAAC,EACpB,eAAe,EACf,OAAO,EACP,QAAQ,EACR,SAAS,EACT,KAAK,GAON;;IACC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,IAAI,CACb,gFAAgF,EAChF,SAAS,CACV,EACD,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,QAAQ,gBACN,GAAG,MAAA,OAAO,CAAC,mBAAmB,mCAAI,cAAc,IAAI,KAAK,GAAG,CAAC,EAAE,aAE3E,eAAM,SAAS,EAAC,MAAM,YACpB,KAAC,YAAY,iCAA8B,GACtC,EACN,CAAC,CAAC,OAAO,CAAC,mBAAmB,IAAI,CAChC,yBAAO,OAAO,CAAC,mBAAmB,GAAQ,CAC3C,IACM,CACV,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport clsx from 'clsx'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport useBooleanState from '../hooks/useBooleanState'\nimport generateDefaultData, {\n ENTRY_ID_PROPERTY_NAME,\n generateNewRepeatableSetEntry,\n} from '../services/generate-default-data'\nimport OneBlinkFormElements from '../components/renderer/OneBlinkFormElements'\nimport Modal from '../components/renderer/Modal'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport useValidationClass from '../hooks/useValidationClass'\nimport {\n ExecutedLookups,\n FormElementConditionallyShown,\n FormElementLookupHandler,\n FormElementsConditionallyShown,\n FormElementsValidation,\n FormElementValidation,\n NestedFormElementValueChangeHandler,\n IsDirtyProps,\n UpdateFormElementsHandler,\n SectionState,\n} from '../types/form'\nimport useFormElementRepeatableSetEntries from '../hooks/useFormElementRepeatableSetEntries'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport MaterialIcon from '../components/MaterialIcon'\nimport ElementDOMId from '../utils/elementDOMIds'\nimport { Collapse } from '@mui/material'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype Props = {\n formId: number\n id: string\n isEven: boolean\n element: FormTypes.RepeatableSetElement\n /**\n * Whether this set’s own controls (add/remove entries) are locked. The set\n * itself must be listed in `editableFormElementIds` to add or remove entries;\n * a nested field being listed is not enough.\n */\n readOnly: boolean\n /**\n * Lock to apply to fields inside each entry. True when the whole form is\n * read-only, a parent is read-only, or this element’s definition has\n * `readOnly: true`.\n */\n childrenReadOnly: boolean\n value: Array<SubmissionTypes.S3SubmissionData['submission']> | undefined\n onChange: NestedFormElementValueChangeHandler<\n SubmissionTypes.S3SubmissionData['submission'][]\n >\n onLookup: FormElementLookupHandler\n formElementConditionallyShown: FormElementConditionallyShown | undefined\n formElementValidation: FormElementValidation | undefined\n displayValidationMessage: boolean\n onUpdateFormElements: UpdateFormElementsHandler\n sectionState: SectionState\n} & IsDirtyProps\n\nconst RepeatableSetIndexContext = React.createContext<number>(0)\n\nfunction RepeatableSetEntryProvider({\n index,\n isAnimated,\n element,\n idPrefix,\n onRemove,\n children,\n}: {\n isAnimated: boolean\n index: number\n element: FormTypes.RepeatableSetElement\n idPrefix?: string\n onRemove: (\n index: number,\n element: FormTypes.RepeatableSetElement,\n idPrefix?: string,\n ) => void\n children: (renderProps: { onRemove: () => void }) => React.ReactNode\n}) {\n const [isExpanded, setIsExpanded] = React.useState(true)\n\n const handleRemove = React.useCallback(() => {\n if (isAnimated) {\n setIsExpanded(false)\n } else {\n onRemove(index, element, idPrefix)\n }\n }, [index, isAnimated, onRemove, element, idPrefix])\n\n const node = (\n <RepeatableSetIndexContext.Provider value={index}>\n {children({\n onRemove: handleRemove,\n })}\n </RepeatableSetIndexContext.Provider>\n )\n\n if (!isAnimated) {\n return node\n }\n\n return (\n <Collapse\n in={isExpanded}\n appear\n onExited={() => {\n onRemove(index, element, idPrefix)\n }}\n classes={{\n root: 'ob-repeatable-set__collapsible',\n wrapper: 'ob-repeatable-set__collapsible-wrapper',\n wrapperInner: 'ob-repeatable-set__collapsible-wrapper-inner',\n }}\n >\n {node}\n </Collapse>\n )\n}\n\nexport function useRepeatableSetIndexText(text: string) {\n const index = React.useContext(RepeatableSetIndexContext)\n return React.useMemo(\n () => text.replace('{INDEX}', (index + 1).toString()),\n [index, text],\n )\n}\n\nfunction FormElementRepeatableSet({\n formId,\n element,\n readOnly,\n childrenReadOnly,\n value,\n formElementValidation,\n id,\n isEven,\n displayValidationMessage,\n formElementConditionallyShown,\n onChange,\n onLookup,\n onUpdateFormElements,\n isDirty,\n setIsDirty,\n sectionState,\n}: Props) {\n const entries = React.useMemo(\n () => (Array.isArray(value) ? value : []),\n [value],\n )\n\n const handleAddEntry = React.useCallback(\n (index: number) => {\n onChange(element, {\n value: (existingEntries) => {\n const newEntries = [...(existingEntries || [])]\n const entry = generateDefaultData(\n element.elements,\n generateNewRepeatableSetEntry(),\n )\n\n newEntries.splice(index, 0, entry)\n return newEntries\n },\n executedLookups: (existingExecutedLookups) => {\n if (\n existingExecutedLookups !== undefined &&\n !Array.isArray(existingExecutedLookups)\n ) {\n return []\n }\n\n const newExistingExecutedLookups = [\n ...((existingExecutedLookups as ExecutedLookups[]) ??\n Array.from(Array(entries.length))),\n ]\n newExistingExecutedLookups.push({})\n return newExistingExecutedLookups\n },\n sectionState: (currentSectionState) => {\n return (\n currentSectionState?.map((section) => {\n const idPrefixPattern = new RegExp(\n `(.+)?${element.name}_entry-(.+)_(.+)`,\n )\n const entryIdPrefixMatches = section.id.match(idPrefixPattern)\n\n if (entryIdPrefixMatches) {\n const startOfId = entryIdPrefixMatches[1]\n const entryIndex = parseInt(entryIdPrefixMatches[2])\n const restOfId = entryIdPrefixMatches[3]\n\n if (entryIndex >= index) {\n const newEntryIndex = entryIndex + 1\n section.id = `${startOfId ? startOfId : ''}${element.name}_entry-${newEntryIndex}_${restOfId}`\n }\n }\n\n return section\n }, []) || []\n )\n },\n })\n setIsDirty()\n },\n [element, onChange, setIsDirty, entries.length],\n )\n\n const handleRemoveEntry = React.useCallback(\n (\n index: number,\n element: FormTypes.RepeatableSetElement,\n idPrefix?: string,\n ) => {\n const entryIdPrefix = idPrefix || ''\n\n onChange(element, {\n value: (existingEntries) => {\n const newEntries = [...(existingEntries || [])]\n newEntries.splice(index, 1)\n return newEntries\n },\n executedLookups: (existingExecutedLookups) => {\n if (!Array.isArray(existingExecutedLookups)) {\n return []\n }\n const newExistingExecutedLookups = [...existingExecutedLookups]\n\n newExistingExecutedLookups.splice(index, 1)\n return newExistingExecutedLookups\n },\n sectionState: (currentSectionState) => {\n return (\n currentSectionState?.reduce(\n (\n state: {\n id: string\n state: 'COLLAPSED' | 'EXPANDED'\n }[],\n section,\n ) => {\n const idPrefixPattern = new RegExp(\n `(.+)?${element.name}_entry-(\\\\d+)`,\n )\n const entryIdPrefixMatches =\n entryIdPrefix.match(idPrefixPattern)\n if (\n !section.id.startsWith(entryIdPrefix) &&\n entryIdPrefixMatches\n ) {\n const parentElementPath =\n entryIdPrefixMatches[1] || `${element.name}_entry`\n // only update nested sections where the parent path matches the entry that was removed\n if (section.id.startsWith(parentElementPath)) {\n // Match pattern: {elementName}_entry-{index}_\n // also yields a prefix and suffix for any match found\n const idPrefixWithFullIdPattern = new RegExp(\n `(.+)?${element.name}_entry-(\\\\d+)_(.+)`,\n )\n const match = section.id.match(idPrefixWithFullIdPattern)\n\n if (match) {\n const oldEntryIndex = parseInt(match[2], 10)\n if (oldEntryIndex > index) {\n const prefix = match[1]\n const restOfId = match[3]\n const newEntryIndex = oldEntryIndex - 1\n section.id = `${prefix ? prefix : ''}${element.name}_entry-${newEntryIndex}_${restOfId}`\n }\n }\n }\n\n state.push(section)\n }\n\n return state\n },\n [],\n ) || []\n )\n },\n })\n setIsDirty()\n },\n [onChange, setIsDirty],\n )\n\n const handleNestedChange = React.useCallback(\n (\n index: number,\n nestedElement: FormTypes.FormElement,\n {\n value,\n executedLookups,\n sectionState,\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)) {\n return\n }\n onChange(element, {\n value: (existingEntries) => {\n const newEntries = (existingEntries || []).map((entry, i) => {\n if (i === index) {\n return {\n ...entry,\n [nestedElement.name]:\n typeof value === 'function'\n ? value(entry[nestedElement.name])\n : value,\n }\n } else {\n return entry\n }\n })\n return newEntries\n },\n executedLookups: (existingExecutedLookups) => {\n const elementExecutedLookups = existingExecutedLookups ?? []\n if (!Array.isArray(elementExecutedLookups)) {\n return elementExecutedLookups\n }\n const newExecutedLookups = elementExecutedLookups.map(\n (executedLookup, i) => {\n if (i === index) {\n const updatedExecutedLookups =\n typeof executedLookups === 'function'\n ? executedLookups(executedLookup?.[nestedElement.name])\n : executedLookups\n return {\n ...executedLookup,\n [nestedElement.name]: updatedExecutedLookups,\n }\n }\n return executedLookup\n },\n )\n return newExecutedLookups\n },\n sectionState,\n })\n },\n [element, onChange],\n )\n\n const { minSetEntries, maxSetEntries } =\n useFormElementRepeatableSetEntries(element)\n\n const repeatableSetValidation = React.useMemo(\n () =>\n !formElementValidation ||\n typeof formElementValidation === 'string' ||\n formElementValidation.type !== 'repeatableSet'\n ? undefined\n : formElementValidation,\n [formElementValidation],\n )\n\n const repeatableSetEntriesConditionallyShown =\n formElementConditionallyShown &&\n formElementConditionallyShown.type === 'repeatableSet'\n ? formElementConditionallyShown.entries\n : {}\n\n const { validationClassName } = useValidationClass({\n formElementsValid: !repeatableSetValidation,\n displayInvalidClassName: isDirty || displayValidationMessage,\n validClassName: 'ob-repeatable-set-element__valid',\n invalidClassName: 'ob-repeatable-set-element__invalid',\n })\n\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n\n const showAddButton = React.useMemo(\n () => !maxSetEntries || entries.length < maxSetEntries,\n [maxSetEntries, entries.length],\n )\n\n const repeatableSetContainerClass = React.useMemo(() => {\n const prefix = 'ob-repeatable-set-container-layout__'\n switch (element.layout) {\n case 'MULTIPLE_ADD_BUTTONS':\n return prefix + 'multiple-add-buttons'\n default:\n return 'single-add-button'\n }\n }, [element.layout])\n\n return (\n <div\n className={clsx('cypress-repeatable-set-element', validationClassName)}\n aria-labelledby={`${id}-label`}\n aria-describedby={ariaDescribedby}\n role=\"region\"\n >\n {/* */}\n <FormElementLabelContainer\n className={clsx(\n 'ob-repeatable-set',\n isEven ? 'even' : 'odd',\n repeatableSetContainerClass,\n )}\n element={element}\n id={id}\n required={!!minSetEntries && minSetEntries > 0}\n associateLabelWithInput={false}\n >\n {element.layout === 'MULTIPLE_ADD_BUTTONS' && showAddButton && (\n <AddButton\n onAdd={() => handleAddEntry(0)}\n element={element}\n readOnly={readOnly}\n classes={['ob-button-repeatable-set-layout__multiple-add-buttons']}\n id={id}\n />\n )}\n {entries.map((entry, index) => {\n return (\n <RepeatableSetEntry\n key={entry[ENTRY_ID_PROPERTY_NAME] as string}\n formId={formId}\n index={index}\n id={id}\n isEven={isEven}\n entry={entry}\n element={element}\n readOnly={readOnly}\n childrenReadOnly={childrenReadOnly}\n showAddButton={\n element.layout === 'MULTIPLE_ADD_BUTTONS' && showAddButton\n }\n onChange={handleNestedChange}\n onLookup={onLookup}\n onAdd={handleAddEntry}\n onRemove={handleRemoveEntry}\n formElementsConditionallyShown={\n repeatableSetEntriesConditionallyShown[index.toString()]\n }\n formElementsValidation={\n repeatableSetValidation &&\n repeatableSetValidation.entries[index.toString()]\n }\n displayValidationMessages={displayValidationMessage}\n onUpdateFormElements={onUpdateFormElements}\n sectionState={sectionState}\n />\n )\n })}\n {(!element.layout || element.layout === 'SINGLE_ADD_BUTTON') &&\n showAddButton && (\n <AddButton\n onAdd={() => handleAddEntry(entries.length)}\n element={element}\n readOnly={readOnly}\n id={id}\n />\n )}\n {(isDirty || displayValidationMessage) &&\n !!repeatableSetValidation &&\n !!repeatableSetValidation.set && (\n <FormElementValidationMessage\n message={repeatableSetValidation.set}\n />\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nexport default React.memo(FormElementRepeatableSet)\n\ntype RepeatableSetEntryProps = {\n formId: number\n id: string\n index: number\n isEven: boolean\n entry: SubmissionTypes.S3SubmissionData['submission']\n element: FormTypes.RepeatableSetElement\n /**\n * Whether this entry’s add/remove controls are locked. See\n * `FormElementRepeatableSet` `readOnly`.\n */\n readOnly: boolean\n /**\n * Lock to apply to fields in this entry. See `FormElementRepeatableSet`\n * `childrenReadOnly`.\n */\n childrenReadOnly: boolean\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined\n formElementsValidation: FormElementsValidation | undefined\n displayValidationMessages: boolean\n showAddButton: boolean\n onChange: (\n index: number,\n formElement: FormTypes.FormElement,\n {\n value,\n executedLookups,\n }: Parameters<NestedFormElementValueChangeHandler>[1],\n idPrefix?: string,\n ) => void\n onLookup: FormElementLookupHandler\n onAdd: (index: number) => unknown\n onRemove: (\n index: number,\n element: FormTypes.RepeatableSetElement,\n idPrefix?: string,\n ) => unknown\n onUpdateFormElements: UpdateFormElementsHandler\n sectionState: SectionState\n}\n\nconst RepeatableSetEntry = React.memo<RepeatableSetEntryProps>(\n function RepeatableSetEntry({\n formId,\n id,\n index,\n isEven,\n entry,\n element,\n readOnly,\n childrenReadOnly,\n formElementsConditionallyShown,\n displayValidationMessages,\n formElementsValidation,\n onChange,\n onLookup,\n onAdd,\n onRemove,\n onUpdateFormElements,\n showAddButton,\n sectionState,\n }: RepeatableSetEntryProps) {\n const [isConfirmingRemove, confirmRemove, cancelRemove] =\n useBooleanState(false)\n const elementDOMId = React.useMemo(() => new ElementDOMId(id), [id])\n\n const handleChange: NestedFormElementValueChangeHandler = React.useCallback(\n (nestedElement, { value, executedLookups, sectionState }, idPrefix) => {\n onChange(\n index,\n nestedElement,\n {\n value,\n executedLookups,\n sectionState,\n },\n idPrefix,\n )\n },\n [index, onChange],\n )\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults) => {\n onLookup((currentFormSubmission) => {\n let newEntry = {}\n const entries = currentFormSubmission.submission[\n element.name\n ] as Array<SubmissionTypes.S3SubmissionData['submission']>\n const repeatableSetExecutedLookups =\n (currentFormSubmission.executedLookups?.[\n element.name\n ] as ExecutedLookups[]) ?? Array.from(Array(entries.length))\n // if the repeatable set is prefilled or has minimum entries then executed lookups exists,\n // but is an empty array\n for (let i = 0; i < entries.length; i++) {\n if (!repeatableSetExecutedLookups[index]) {\n repeatableSetExecutedLookups[index] = {}\n }\n }\n let newExecutedLookups: ExecutedLookups = {}\n const elements = currentFormSubmission.elements.map((formElement) => {\n if (\n formElement.type === 'repeatableSet' &&\n formElement.name === element.name\n ) {\n const { elements, submission, executedLookups } =\n mergeLookupResults({\n elements: formElement.elements,\n submission: entries[index],\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: repeatableSetExecutedLookups[index] ?? {},\n sectionState: currentFormSubmission.sectionState,\n })\n newEntry = 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]: entries.map((entry, i) => {\n if (i === index) {\n return newEntry\n }\n return entry\n }),\n }\n\n let updatedExecutedLookups = currentFormSubmission.executedLookups\n if (Array.isArray(repeatableSetExecutedLookups)) {\n updatedExecutedLookups = {\n ...currentFormSubmission.executedLookups,\n [element.name]: repeatableSetExecutedLookups.map((entry, i) => {\n if (i == index) {\n return newExecutedLookups\n }\n return entry\n }),\n }\n }\n\n return {\n elements,\n submission,\n executedLookups: updatedExecutedLookups,\n }\n })\n },\n [element.name, index, onLookup],\n )\n\n const { validationClassName } = useValidationClass({\n formElementsValid: !formElementsValidation,\n displayInvalidClassName: displayValidationMessages,\n validClassName: 'ob-repeatable-set__valid',\n invalidClassName: 'ob-repeatable-set__invalid',\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 === 'repeatableSet'\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 idPrefix = elementDOMId.repeatableSetEntryDOMIdPrefix(\n index.toString(),\n )\n\n return (\n <RepeatableSetEntryProvider\n index={index}\n element={element}\n idPrefix={idPrefix}\n onRemove={onRemove}\n isAnimated={element.layout === 'MULTIPLE_ADD_BUTTONS'}\n >\n {({ onRemove }) => (\n <>\n <Modal\n isOpen={isConfirmingRemove}\n className=\"cypress-repeatable-set-prompt\"\n titleClassName=\"cypress-repeatable-set-remove-entry-header\"\n title={element.removeSetEntryLabel || 'Remove Entry'}\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button is-light cypress-cancel-repeatable-set\"\n onClick={cancelRemove}\n >\n Cancel\n </button>\n <button\n type=\"button\"\n className=\"button ob-button is-primary cypress-confirm-repeatable-set\"\n onClick={() => {\n cancelRemove()\n onRemove()\n }}\n autoFocus\n >\n Yes\n </button>\n </>\n }\n >\n Are you sure you want to remove this entry?\n </Modal>\n\n <div\n className={clsx(\n 'ob-repeatable-set__container cypress-repeatable-set-container',\n validationClassName,\n )}\n >\n {(!element.layout || element.layout === 'SINGLE_ADD_BUTTON') && (\n <RemoveButton\n onConfirmRemove={confirmRemove}\n element={element}\n readOnly={readOnly}\n className=\"ob-repeatable-set__button-remove-top\"\n index={index}\n />\n )}\n\n <OneBlinkFormElements\n formId={formId}\n idPrefix={idPrefix}\n isEven={isEven}\n formElementsValidation={formElementsValidation}\n displayValidationMessages={displayValidationMessages}\n elements={element.elements}\n onChange={handleChange}\n onLookup={handleLookup}\n model={entry}\n parentElement={element}\n readOnly={childrenReadOnly}\n formElementsConditionallyShown={formElementsConditionallyShown}\n onUpdateFormElements={handleUpdateNestedFormElements}\n sectionState={sectionState}\n />\n {element.layout === 'MULTIPLE_ADD_BUTTONS' && (\n <RemoveButton\n onConfirmRemove={confirmRemove}\n element={element}\n readOnly={readOnly}\n index={index}\n className=\"ob-repeatable-set__button-remove-bottom\"\n />\n )}\n </div>\n {showAddButton && (\n <AddButton\n onAdd={() => onAdd(index + 1)}\n element={element}\n readOnly={readOnly}\n classes={[\n 'ob-button-repeatable-set-layout__multiple-add-buttons',\n ]}\n />\n )}\n </>\n )}\n </RepeatableSetEntryProvider>\n )\n },\n)\n\nfunction AddButton({\n id,\n onAdd,\n element,\n readOnly,\n classes,\n}: {\n id?: string\n onAdd: () => void\n element: FormTypes.RepeatableSetElement\n readOnly: boolean\n isPrimary?: boolean\n classes?: string[]\n}) {\n return (\n <button\n type=\"button\"\n className={clsx(\n 'button ob-button ob-button__add cypress-add-repeatable-set is-primary',\n classes,\n )}\n onClick={onAdd}\n disabled={readOnly}\n aria-label={element.addSetEntryLabel ? undefined : 'Add Entry'}\n id={id}\n >\n <span className=\"icon\">\n <MaterialIcon>add</MaterialIcon>\n </span>\n {!!element.addSetEntryLabel && <span>{element.addSetEntryLabel}</span>}\n </button>\n )\n}\n\nfunction RemoveButton({\n onConfirmRemove,\n element,\n readOnly,\n className,\n index,\n}: {\n onConfirmRemove: () => void\n element: FormTypes.RepeatableSetElement\n readOnly: boolean\n className?: string\n index: number\n}) {\n return (\n <button\n type=\"button\"\n className={clsx(\n 'button ob-button ob-button_remove is-light cypress-remove-repeatable-set-entry',\n className,\n )}\n onClick={onConfirmRemove}\n disabled={readOnly}\n aria-label={`${element.removeSetEntryLabel ?? 'Remove Entry'} ${index + 1}`}\n >\n <span className=\"icon\">\n <MaterialIcon>delete_outline</MaterialIcon>\n </span>\n {!!element.removeSetEntryLabel && (\n <span>{element.removeSetEntryLabel}</span>\n )}\n </button>\n )\n}\n"]}
|
|
@@ -5,9 +5,9 @@ import { SectionState } from '../types/form';
|
|
|
5
5
|
declare function FormElementSection<T extends FormTypes._NestedElementsElement>({ element, childrenReadOnly, onLookup, displayValidationMessages, onUpdateFormElements, sectionHeaderId, sectionState, ...props }: Omit<Props<T>, 'elements' | 'readOnly'> & {
|
|
6
6
|
element: FormTypes.SectionElement;
|
|
7
7
|
/**
|
|
8
|
-
* Lock to apply to nested fields. True when the whole form is read-only
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Lock to apply to nested fields. True when the whole form is read-only or a
|
|
9
|
+
* parent is read-only. A child included in `editableFormElementIds` can stay
|
|
10
|
+
* editable.
|
|
11
11
|
*/
|
|
12
12
|
childrenReadOnly: boolean;
|
|
13
13
|
sectionHeaderId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElementSection.js","sourceRoot":"","sources":["../../src/form-elements/FormElementSection.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,OAAO,MAAM,gCAAgC,CAAA;AAEpD,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,oBAEN,MAAM,6CAA6C,CAAA;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAA;AAO7E,OAAO,EACL,cAAc,EACd,WAAW,GACZ,MAAM,kDAAkD,CAAA;AACzD,OAAO,kBAAkB,MAAM,6BAA6B,CAAA;AAC5D,OAAO,YAAY,MAAM,4BAA4B,CAAA;AAErD,SAAS,qBAAqB,CAAC,KAA+B;IAC5D,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,kBAAkB,CAA6C,EACtE,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EACf,YAAY,GAAG,EAAE,EACjB,GAAG,KAAK,EAWT;IACC,MAAM,iBAAiB,GAAG,YAAY,CAAC,IAAI,CACzC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EA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sB;oBAC/B,MAAM,EAAE,uBAAuB;iBAChC,YAED,KAAC,sBAAsB,IACrB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,+BAA+B,YAE3C,KAAC,oBAAoB,OACf,KAAK,EACT,QAAQ,EAAE,gBAAgB,EAC1B,yBAAyB,EAAE,wBAAwB,EACnD,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAC1B,oBAAoB,EAAE,8BAA8B,EACpD,YAAY,EAAE,YAAY,GAC1B,GACqB,GAChB,IACP,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;AAE7C,MAAM,sBAAsB,GAAG,CAAC,EAC9B,QAAQ,EACR,OAAO,EACP,UAAU,GAKX,EAAE,EAAE;IACH,OAAO,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CACrC,eAAK,SAAS,EAAC,2CAA2C,aACvD,QAAQ,EAET,kBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,+DAA+D,EACzE,OAAO,EAAE,UAAU,aAEnB,eAAM,SAAS,EAAC,MAAM,YACpB,KAAC,YAAY,8BAA2B,GACnC,EACP,sCAAqB,IACd,IACL,CACP,CAAC,CAAC,CAAC,CACF,4BAAG,QAAQ,GAAI,CAChB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport clsx from 'clsx'\nimport { Collapse } from '@mui/material'\nimport Tooltip from '../components/renderer/Tooltip'\nimport { FormTypes } from '@oneblink/types'\nimport useBooleanState from '../hooks/useBooleanState'\nimport OneBlinkFormElements, {\n Props,\n} from '../components/renderer/OneBlinkFormElements'\nimport { checkSectionValidity } from '../services/form-validation/validators'\nimport {\n FormElementLookupHandler,\n UpdateFormElementsHandler,\n ExecutedLookups,\n SectionState,\n} from '../types/form'\nimport {\n HintBelowLabel,\n HintTooltip,\n} from '../components/renderer/FormElementLabelContainer'\nimport useValidationClass from '../hooks/useValidationClass'\nimport MaterialIcon from '../components/MaterialIcon'\n\nfunction sectionStateToBoolean(state: 'COLLAPSED' | 'EXPANDED') {\n if (state === 'COLLAPSED') {\n return true\n }\n return false\n}\n\nfunction FormElementSection<T extends FormTypes._NestedElementsElement>({\n element,\n childrenReadOnly,\n onLookup,\n displayValidationMessages,\n onUpdateFormElements,\n sectionHeaderId,\n sectionState = [],\n ...props\n}: Omit<Props<T>, 'elements' | 'readOnly'> & {\n element: FormTypes.SectionElement\n /**\n * Lock to apply to nested fields. True when the whole form is read-only\n * or a parent is read-only. Does not include this section’s audience\n * lock, so an `ALL_STEPS` child can stay editable.\n */\n childrenReadOnly: boolean\n sectionHeaderId: string\n sectionState?: SectionState\n}) {\n const sectionStateEntry = sectionState.find(\n (section) => section.id === `${props['idPrefix']}${element.id}`,\n )\n const isCollapsedFromState = sectionStateEntry?.state\n ? sectionStateToBoolean(sectionStateEntry.state)\n : element.isCollapsed\n\n const [isCollapsed, , , toggle] = useBooleanState(isCollapsedFromState)\n\n const handleToggle = React.useCallback(() => {\n // trigger onChange to update the sectionState\n props.onChange(\n element,\n {\n executedLookups: undefined,\n sectionState,\n },\n props['idPrefix'],\n )\n toggle()\n }, [element, props, sectionState, toggle])\n\n const [isDisplayingError, setIsDisplayingError] = React.useState(isCollapsed)\n const headerRef = React.useRef<HTMLDivElement>(null)\n const id = `${props['idPrefix']}${element.id}`\n\n React.useEffect(() => {\n if (isCollapsed && !isDisplayingError) {\n setIsDisplayingError(true)\n }\n }, [isCollapsed, isDisplayingError])\n\n const displayValidationMessage =\n displayValidationMessages || isDisplayingError\n\n const isValid = React.useMemo(\n () => !checkSectionValidity(element, props.formElementsValidation),\n [element, props.formElementsValidation],\n )\n\n const { validationClassName, valid } = useValidationClass({\n formElementsValid: isValid,\n displayInvalidClassName: displayValidationMessage,\n validClassName: 'ob-section__valid',\n invalidClassName: 'ob-section__invalid',\n })\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults) => {\n onLookup((currentFormSubmission) => {\n let model = currentFormSubmission.submission\n let newExecutedLookups: ExecutedLookups = {}\n const elements = currentFormSubmission.elements.map((formElement) => {\n if (formElement.type === 'section' && formElement.id === element.id) {\n const { elements, submission, executedLookups } =\n mergeLookupResults({\n elements: formElement.elements,\n submission: currentFormSubmission.submission,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: currentFormSubmission.executedLookups,\n sectionState: currentFormSubmission.sectionState,\n })\n model = submission\n newExecutedLookups = executedLookups\n return {\n ...formElement,\n elements,\n }\n }\n return formElement\n })\n\n return {\n elements,\n submission: model,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: newExecutedLookups,\n sectionState: currentFormSubmission.sectionState,\n }\n })\n },\n [element.id, onLookup],\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 === 'section'\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 handleClickBottomCollapseButton = React.useCallback(() => {\n handleToggle()\n headerRef.current?.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n inline: 'nearest',\n })\n }, [handleToggle])\n\n return (\n <div className={clsx('ob-section', validationClassName)}>\n <div\n className={clsx('ob-section__header cypress-section-header', {\n 'ob-section__header-filled': element.canCollapseFromBottom,\n })}\n onClick={handleToggle}\n tabIndex={0}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n handleToggle()\n }\n }}\n ref={headerRef}\n >\n <h3 className=\"ob-section__header-text title is-3\" id={sectionHeaderId}>\n {element.label}\n {element.hint &&\n (element.hintPosition === 'TOOLTIP' || !element.hintPosition) && (\n <HintTooltip hint={element.hint} inputId={id} />\n )}\n </h3>\n <div className=\"ob-section__header-icon-container\">\n {!valid && displayValidationMessage && (\n <Tooltip title=\"Section has errors\">\n <MaterialIcon className=\"has-text-danger cypress-section-invalid-icon section-invalid-icon fade-in\">\n warning\n </MaterialIcon>\n </Tooltip>\n )}\n <MaterialIcon\n className={clsx('ob-section__header-icon', {\n 'is-rotated': !isCollapsed,\n })}\n >\n expand_more\n </MaterialIcon>\n </div>\n {element.hint && element.hintPosition === 'BELOW_LABEL' && (\n <div className=\"ob-section__hint-text-container\">\n <HintBelowLabel hint={element.hint} inputId={id} />\n </div>\n )}\n </div>\n {!element.canCollapseFromBottom && <hr className=\"ob-section__divider\" />}\n <Collapse\n in={!isCollapsed}\n classes={{\n root: 'ob-section__content',\n entered: 'ob-section__expanded',\n hidden: 'ob-section__collapsed',\n }}\n >\n <SectionElementsWrapper\n element={element}\n onCollapse={handleClickBottomCollapseButton}\n >\n <OneBlinkFormElements\n {...props}\n readOnly={childrenReadOnly}\n displayValidationMessages={displayValidationMessage}\n onLookup={handleLookup}\n elements={element.elements}\n onUpdateFormElements={handleUpdateNestedFormElements}\n sectionState={sectionState}\n />\n </SectionElementsWrapper>\n </Collapse>\n </div>\n )\n}\n\nexport default React.memo(FormElementSection)\n\nconst SectionElementsWrapper = ({\n children,\n element,\n onCollapse,\n}: {\n children: React.ReactNode\n element: FormTypes.SectionElement\n onCollapse: () => void\n}) => {\n return element.canCollapseFromBottom ? (\n <div className=\"ob-section__collapsible-content-container\">\n {children}\n\n <button\n type=\"button\"\n className=\"button is-rounded is-light ob-section__bottom-collapse-button\"\n onClick={onCollapse}\n >\n <span className=\"icon\">\n <MaterialIcon>expand_less</MaterialIcon>\n </span>\n <span>Collapse</span>\n </button>\n </div>\n ) : (\n <>{children}</>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FormElementSection.js","sourceRoot":"","sources":["../../src/form-elements/FormElementSection.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe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O,CAAC,qBAAqB,CAAC,CAAC,CAAC,CACrC,eAAK,SAAS,EAAC,2CAA2C,aACvD,QAAQ,EAET,kBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,+DAA+D,EACzE,OAAO,EAAE,UAAU,aAEnB,eAAM,SAAS,EAAC,MAAM,YACpB,KAAC,YAAY,8BAA2B,GACnC,EACP,sCAAqB,IACd,IACL,CACP,CAAC,CAAC,CAAC,CACF,4BAAG,QAAQ,GAAI,CAChB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport clsx from 'clsx'\nimport { Collapse } from '@mui/material'\nimport Tooltip from '../components/renderer/Tooltip'\nimport { FormTypes } from '@oneblink/types'\nimport useBooleanState from '../hooks/useBooleanState'\nimport OneBlinkFormElements, {\n Props,\n} from '../components/renderer/OneBlinkFormElements'\nimport { checkSectionValidity } from '../services/form-validation/validators'\nimport {\n FormElementLookupHandler,\n UpdateFormElementsHandler,\n ExecutedLookups,\n SectionState,\n} from '../types/form'\nimport {\n HintBelowLabel,\n HintTooltip,\n} from '../components/renderer/FormElementLabelContainer'\nimport useValidationClass from '../hooks/useValidationClass'\nimport MaterialIcon from '../components/MaterialIcon'\n\nfunction sectionStateToBoolean(state: 'COLLAPSED' | 'EXPANDED') {\n if (state === 'COLLAPSED') {\n return true\n }\n return false\n}\n\nfunction FormElementSection<T extends FormTypes._NestedElementsElement>({\n element,\n childrenReadOnly,\n onLookup,\n displayValidationMessages,\n onUpdateFormElements,\n sectionHeaderId,\n sectionState = [],\n ...props\n}: Omit<Props<T>, 'elements' | 'readOnly'> & {\n element: FormTypes.SectionElement\n /**\n * Lock to apply to nested fields. True when the whole form is read-only or a\n * parent is read-only. A child included in `editableFormElementIds` can stay\n * editable.\n */\n childrenReadOnly: boolean\n sectionHeaderId: string\n sectionState?: SectionState\n}) {\n const sectionStateEntry = sectionState.find(\n (section) => section.id === `${props['idPrefix']}${element.id}`,\n )\n const isCollapsedFromState = sectionStateEntry?.state\n ? sectionStateToBoolean(sectionStateEntry.state)\n : element.isCollapsed\n\n const [isCollapsed, , , toggle] = useBooleanState(isCollapsedFromState)\n\n const handleToggle = React.useCallback(() => {\n // trigger onChange to update the sectionState\n props.onChange(\n element,\n {\n executedLookups: undefined,\n sectionState,\n },\n props['idPrefix'],\n )\n toggle()\n }, [element, props, sectionState, toggle])\n\n const [isDisplayingError, setIsDisplayingError] = React.useState(isCollapsed)\n const headerRef = React.useRef<HTMLDivElement>(null)\n const id = `${props['idPrefix']}${element.id}`\n\n React.useEffect(() => {\n if (isCollapsed && !isDisplayingError) {\n setIsDisplayingError(true)\n }\n }, [isCollapsed, isDisplayingError])\n\n const displayValidationMessage =\n displayValidationMessages || isDisplayingError\n\n const isValid = React.useMemo(\n () => !checkSectionValidity(element, props.formElementsValidation),\n [element, props.formElementsValidation],\n )\n\n const { validationClassName, valid } = useValidationClass({\n formElementsValid: isValid,\n displayInvalidClassName: displayValidationMessage,\n validClassName: 'ob-section__valid',\n invalidClassName: 'ob-section__invalid',\n })\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults) => {\n onLookup((currentFormSubmission) => {\n let model = currentFormSubmission.submission\n let newExecutedLookups: ExecutedLookups = {}\n const elements = currentFormSubmission.elements.map((formElement) => {\n if (formElement.type === 'section' && formElement.id === element.id) {\n const { elements, submission, executedLookups } =\n mergeLookupResults({\n elements: formElement.elements,\n submission: currentFormSubmission.submission,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: currentFormSubmission.executedLookups,\n sectionState: currentFormSubmission.sectionState,\n })\n model = submission\n newExecutedLookups = executedLookups\n return {\n ...formElement,\n elements,\n }\n }\n return formElement\n })\n\n return {\n elements,\n submission: model,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: newExecutedLookups,\n sectionState: currentFormSubmission.sectionState,\n }\n })\n },\n [element.id, onLookup],\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 === 'section'\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 handleClickBottomCollapseButton = React.useCallback(() => {\n handleToggle()\n headerRef.current?.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n inline: 'nearest',\n })\n }, [handleToggle])\n\n return (\n <div className={clsx('ob-section', validationClassName)}>\n <div\n className={clsx('ob-section__header cypress-section-header', {\n 'ob-section__header-filled': element.canCollapseFromBottom,\n })}\n onClick={handleToggle}\n tabIndex={0}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n handleToggle()\n }\n }}\n ref={headerRef}\n >\n <h3 className=\"ob-section__header-text title is-3\" id={sectionHeaderId}>\n {element.label}\n {element.hint &&\n (element.hintPosition === 'TOOLTIP' || !element.hintPosition) && (\n <HintTooltip hint={element.hint} inputId={id} />\n )}\n </h3>\n <div className=\"ob-section__header-icon-container\">\n {!valid && displayValidationMessage && (\n <Tooltip title=\"Section has errors\">\n <MaterialIcon className=\"has-text-danger cypress-section-invalid-icon section-invalid-icon fade-in\">\n warning\n </MaterialIcon>\n </Tooltip>\n )}\n <MaterialIcon\n className={clsx('ob-section__header-icon', {\n 'is-rotated': !isCollapsed,\n })}\n >\n expand_more\n </MaterialIcon>\n </div>\n {element.hint && element.hintPosition === 'BELOW_LABEL' && (\n <div className=\"ob-section__hint-text-container\">\n <HintBelowLabel hint={element.hint} inputId={id} />\n </div>\n )}\n </div>\n {!element.canCollapseFromBottom && <hr className=\"ob-section__divider\" />}\n <Collapse\n in={!isCollapsed}\n classes={{\n root: 'ob-section__content',\n entered: 'ob-section__expanded',\n hidden: 'ob-section__collapsed',\n }}\n >\n <SectionElementsWrapper\n element={element}\n onCollapse={handleClickBottomCollapseButton}\n >\n <OneBlinkFormElements\n {...props}\n readOnly={childrenReadOnly}\n displayValidationMessages={displayValidationMessage}\n onLookup={handleLookup}\n elements={element.elements}\n onUpdateFormElements={handleUpdateNestedFormElements}\n sectionState={sectionState}\n />\n </SectionElementsWrapper>\n </Collapse>\n </div>\n )\n}\n\nexport default React.memo(FormElementSection)\n\nconst SectionElementsWrapper = ({\n children,\n element,\n onCollapse,\n}: {\n children: React.ReactNode\n element: FormTypes.SectionElement\n onCollapse: () => void\n}) => {\n return element.canCollapseFromBottom ? (\n <div className=\"ob-section__collapsible-content-container\">\n {children}\n\n <button\n type=\"button\"\n className=\"button is-rounded is-light ob-section__bottom-collapse-button\"\n onClick={onCollapse}\n >\n <span className=\"icon\">\n <MaterialIcon>expand_less</MaterialIcon>\n </span>\n <span>Collapse</span>\n </button>\n </div>\n ) : (\n <>{children}</>\n )\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import useEditableFormElementIds from './useEditableFormElementIds';
|
|
2
|
+
import useFormIsReadOnly from './useFormIsReadOnly';
|
|
3
|
+
import { checkAreLookupsDisallowed } from '../utils/read-only-form-elements';
|
|
4
|
+
export default function useAreLookupsDisallowed(element) {
|
|
5
|
+
const isFormReadOnly = useFormIsReadOnly();
|
|
6
|
+
const editableFormElementIds = useEditableFormElementIds();
|
|
7
|
+
return checkAreLookupsDisallowed(element, {
|
|
8
|
+
isFormReadOnly,
|
|
9
|
+
editableFormElementIds,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=useAreLookupsDisallowed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAreLookupsDisallowed.js","sourceRoot":"","sources":["../../src/hooks/useAreLookupsDisallowed.ts"],"names":[],"mappings":"AACA,OAAO,yBAAyB,MAAM,6BAA6B,CAAA;AACnE,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAE5E,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAC7C,OAA4D;IAE5D,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAA;IAC1C,MAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAA;IAE1D,OAAO,yBAAyB,CAAC,OAAO,EAAE;QACxC,cAAc;QACd,sBAAsB;KACvB,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\r\nimport useEditableFormElementIds from './useEditableFormElementIds'\r\nimport useFormIsReadOnly from './useFormIsReadOnly'\r\nimport { checkAreLookupsDisallowed } from '../utils/read-only-form-elements'\r\n\r\nexport default function useAreLookupsDisallowed(\r\n element: FormTypes.FormElement | FormTypes.LookupFormElement,\r\n): boolean {\r\n const isFormReadOnly = useFormIsReadOnly()\r\n const editableFormElementIds = useEditableFormElementIds()\r\n\r\n return checkAreLookupsDisallowed(element, {\r\n isFormReadOnly,\r\n editableFormElementIds,\r\n })\r\n}\r\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export const EditableFormElementIdsContext = React.createContext(undefined);
|
|
3
|
+
export default function useEditableFormElementIds() {
|
|
4
|
+
return React.useContext(EditableFormElementIdsContext);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=useEditableFormElementIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditableFormElementIds.js","sourceRoot":"","sources":["../../src/hooks/useEditableFormElementIds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,CAAC,MAAM,6BAA6B,GAAG,KAAK,CAAC,aAAa,CAE9D,SAAS,CAAC,CAAA;AAEZ,MAAM,CAAC,OAAO,UAAU,yBAAyB;IAC/C,OAAO,KAAK,CAAC,UAAU,CAAC,6BAA6B,CAAC,CAAA;AACxD,CAAC","sourcesContent":["import * as React from 'react'\n\nexport const EditableFormElementIdsContext = React.createContext<\n string[] | undefined\n>(undefined)\n\nexport default function useEditableFormElementIds(): string[] | undefined {\n return React.useContext(EditableFormElementIdsContext)\n}\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Call after the host has successfully persisted the edits (for example after
|
|
4
|
+
* an approval upload). This clears the unsaved-changes navigation guard.
|
|
5
|
+
*
|
|
6
|
+
* Do not call it until that work has finished: cancelling a confirmation dialog
|
|
7
|
+
* after a successful attempt must still prompt if the user navigates away.
|
|
8
|
+
*/
|
|
9
|
+
export type FormSubmissionAttemptAllowNavigation = () => void;
|
|
10
|
+
/**
|
|
11
|
+
* Runs the form’s existing submit-preparation path (validation, BSB checks,
|
|
12
|
+
* attachments, and the same error UI as a real submit).
|
|
13
|
+
*
|
|
14
|
+
* Resolves with {@link FormSubmissionAttemptAllowNavigation} when the host may
|
|
15
|
+
* continue (for example approve and upload an edit). Resolves `false` when
|
|
16
|
+
* preparation failed; field errors and toasts have already been shown. Does
|
|
17
|
+
* **not** call `onSubmit`, captcha, or analytics.
|
|
18
|
+
*/
|
|
19
|
+
export type FormSubmissionAttempt = () => Promise<false | FormSubmissionAttemptAllowNavigation>;
|
|
20
|
+
/**
|
|
21
|
+
* Optional context that lets a host (for example Approvals) trigger the
|
|
22
|
+
* rendered form’s submit-preparation path without duplicating it.
|
|
23
|
+
*
|
|
24
|
+
* Wrap both the form and the host action (Approve) so they share one registry.
|
|
25
|
+
* `OneBlinkFormBase` registers when `editableFormElementIds` is set. If nothing
|
|
26
|
+
* is registered, {@link useFormSubmissionAttempt} still resolves with a no-op
|
|
27
|
+
* {@link FormSubmissionAttemptAllowNavigation} so hosts without an editable form
|
|
28
|
+
* are unchanged.
|
|
29
|
+
*
|
|
30
|
+
* #### Example
|
|
31
|
+
*
|
|
32
|
+
* ```jsx
|
|
33
|
+
* import {
|
|
34
|
+
* FormSubmissionAttemptContextProvider,
|
|
35
|
+
* OneBlinkReadOnlyForm,
|
|
36
|
+
* useFormSubmissionAttempt,
|
|
37
|
+
* } from '@oneblink/apps-react'
|
|
38
|
+
*
|
|
39
|
+
* function ApproveButton() {
|
|
40
|
+
* const attemptFormSubmission = useFormSubmissionAttempt()
|
|
41
|
+
*
|
|
42
|
+
* const onClickApprove = async () => {
|
|
43
|
+
* const allowNavigation = await attemptFormSubmission()
|
|
44
|
+
* if (!allowNavigation) {
|
|
45
|
+
* return
|
|
46
|
+
* }
|
|
47
|
+
* // continue with the host action, then:
|
|
48
|
+
* allowNavigation()
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* return <button onClick={onClickApprove}>Approve</button>
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* function Approval() {
|
|
55
|
+
* return (
|
|
56
|
+
* <FormSubmissionAttemptContextProvider>
|
|
57
|
+
* <OneBlinkReadOnlyForm editableFormElementIds={['element-id']} />
|
|
58
|
+
* <ApproveButton />
|
|
59
|
+
* </FormSubmissionAttemptContextProvider>
|
|
60
|
+
* )
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param props
|
|
65
|
+
* @returns
|
|
66
|
+
* @group Components
|
|
67
|
+
*/
|
|
68
|
+
export declare function FormSubmissionAttemptContextProvider({ children, }: {
|
|
69
|
+
/** The form and the host action that must share one submission attempt. */
|
|
70
|
+
children: React.ReactNode;
|
|
71
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the latest form submission attempt registered under a
|
|
74
|
+
* {@link FormSubmissionAttemptContextProvider}. Safe to call without a provider:
|
|
75
|
+
* preparation is skipped and the promise resolves with a no-op
|
|
76
|
+
* {@link FormSubmissionAttemptAllowNavigation}.
|
|
77
|
+
*
|
|
78
|
+
* @returns
|
|
79
|
+
* @group Hooks
|
|
80
|
+
*/
|
|
81
|
+
export declare function useFormSubmissionAttempt(): FormSubmissionAttempt;
|
|
82
|
+
/**
|
|
83
|
+
* Registers this form’s {@link FormSubmissionAttempt} with the nearest
|
|
84
|
+
* {@link FormSubmissionAttemptContextProvider}, if one exists. Used internally
|
|
85
|
+
* by `OneBlinkFormBase` when `editableFormElementIds` is provided. Pass
|
|
86
|
+
* `undefined` to skip registration (for example a fully read-only form).
|
|
87
|
+
*/
|
|
88
|
+
export declare function useRegisterFormSubmissionAttempt(attempt: FormSubmissionAttempt | undefined): void;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
const FormSubmissionAttemptContext = React.createContext(null);
|
|
4
|
+
/**
|
|
5
|
+
* Optional context that lets a host (for example Approvals) trigger the
|
|
6
|
+
* rendered form’s submit-preparation path without duplicating it.
|
|
7
|
+
*
|
|
8
|
+
* Wrap both the form and the host action (Approve) so they share one registry.
|
|
9
|
+
* `OneBlinkFormBase` registers when `editableFormElementIds` is set. If nothing
|
|
10
|
+
* is registered, {@link useFormSubmissionAttempt} still resolves with a no-op
|
|
11
|
+
* {@link FormSubmissionAttemptAllowNavigation} so hosts without an editable form
|
|
12
|
+
* are unchanged.
|
|
13
|
+
*
|
|
14
|
+
* #### Example
|
|
15
|
+
*
|
|
16
|
+
* ```jsx
|
|
17
|
+
* import {
|
|
18
|
+
* FormSubmissionAttemptContextProvider,
|
|
19
|
+
* OneBlinkReadOnlyForm,
|
|
20
|
+
* useFormSubmissionAttempt,
|
|
21
|
+
* } from '@oneblink/apps-react'
|
|
22
|
+
*
|
|
23
|
+
* function ApproveButton() {
|
|
24
|
+
* const attemptFormSubmission = useFormSubmissionAttempt()
|
|
25
|
+
*
|
|
26
|
+
* const onClickApprove = async () => {
|
|
27
|
+
* const allowNavigation = await attemptFormSubmission()
|
|
28
|
+
* if (!allowNavigation) {
|
|
29
|
+
* return
|
|
30
|
+
* }
|
|
31
|
+
* // continue with the host action, then:
|
|
32
|
+
* allowNavigation()
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* return <button onClick={onClickApprove}>Approve</button>
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* function Approval() {
|
|
39
|
+
* return (
|
|
40
|
+
* <FormSubmissionAttemptContextProvider>
|
|
41
|
+
* <OneBlinkReadOnlyForm editableFormElementIds={['element-id']} />
|
|
42
|
+
* <ApproveButton />
|
|
43
|
+
* </FormSubmissionAttemptContextProvider>
|
|
44
|
+
* )
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @param props
|
|
49
|
+
* @returns
|
|
50
|
+
* @group Components
|
|
51
|
+
*/
|
|
52
|
+
export function FormSubmissionAttemptContextProvider({ children, }) {
|
|
53
|
+
const attemptsRef = React.useRef([]);
|
|
54
|
+
const register = React.useCallback((attempt) => {
|
|
55
|
+
attemptsRef.current.push(attempt);
|
|
56
|
+
return () => {
|
|
57
|
+
attemptsRef.current = attemptsRef.current.filter((registeredAttempt) => registeredAttempt !== attempt);
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
const attempt = React.useCallback(() => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const registeredAttempts = attemptsRef.current;
|
|
63
|
+
return ((_b = (_a = registeredAttempts[registeredAttempts.length - 1]) === null || _a === void 0 ? void 0 : _a.call(registeredAttempts)) !== null && _b !== void 0 ? _b : Promise.resolve(noopAllowNavigation));
|
|
64
|
+
}, []);
|
|
65
|
+
const value = React.useMemo(() => ({
|
|
66
|
+
register,
|
|
67
|
+
attempt,
|
|
68
|
+
}), [attempt, register]);
|
|
69
|
+
return (_jsx(FormSubmissionAttemptContext.Provider, { value: value, children: children }));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns the latest form submission attempt registered under a
|
|
73
|
+
* {@link FormSubmissionAttemptContextProvider}. Safe to call without a provider:
|
|
74
|
+
* preparation is skipped and the promise resolves with a no-op
|
|
75
|
+
* {@link FormSubmissionAttemptAllowNavigation}.
|
|
76
|
+
*
|
|
77
|
+
* @returns
|
|
78
|
+
* @group Hooks
|
|
79
|
+
*/
|
|
80
|
+
export function useFormSubmissionAttempt() {
|
|
81
|
+
var _a;
|
|
82
|
+
const context = React.useContext(FormSubmissionAttemptContext);
|
|
83
|
+
return (_a = context === null || context === void 0 ? void 0 : context.attempt) !== null && _a !== void 0 ? _a : allowSubmissionAttempt;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Registers this form’s {@link FormSubmissionAttempt} with the nearest
|
|
87
|
+
* {@link FormSubmissionAttemptContextProvider}, if one exists. Used internally
|
|
88
|
+
* by `OneBlinkFormBase` when `editableFormElementIds` is provided. Pass
|
|
89
|
+
* `undefined` to skip registration (for example a fully read-only form).
|
|
90
|
+
*/
|
|
91
|
+
export function useRegisterFormSubmissionAttempt(attempt) {
|
|
92
|
+
const context = React.useContext(FormSubmissionAttemptContext);
|
|
93
|
+
React.useLayoutEffect(() => {
|
|
94
|
+
if (attempt) {
|
|
95
|
+
return context === null || context === void 0 ? void 0 : context.register(attempt);
|
|
96
|
+
}
|
|
97
|
+
}, [attempt, context]);
|
|
98
|
+
}
|
|
99
|
+
function noopAllowNavigation() { }
|
|
100
|
+
function allowSubmissionAttempt() {
|
|
101
|
+
return Promise.resolve(noopAllowNavigation);
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=useFormSubmissionAttempt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormSubmissionAttempt.js","sourceRoot":"","sources":["../../src/hooks/useFormSubmissionAttempt.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AA6B9B,MAAM,4BAA4B,GAChC,KAAK,CAAC,aAAa,CAA2C,IAAI,CAAC,CAAA;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,oCAAoC,CAAC,EACnD,QAAQ,GAIT;IACC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAA0B,EAAE,CAAC,CAAA;IAE7D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A;IAE9D,KAAK,CAAC,eAAe,CAAC,GAAG,EAAE;QACzB,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;QACnC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;AACxB,CAAC;AAED,SAAS,mBAAmB,KAAI,CAAC;AAEjC,SAAS,sBAAsB;IAC7B,OAAO,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import * as React from 'react'\n\n/**\n * Call after the host has successfully persisted the edits (for example after\n * an approval upload). This clears the unsaved-changes navigation guard.\n *\n * Do not call it until that work has finished: cancelling a confirmation dialog\n * after a successful attempt must still prompt if the user navigates away.\n */\nexport type FormSubmissionAttemptAllowNavigation = () => void\n\n/**\n * Runs the form’s existing submit-preparation path (validation, BSB checks,\n * attachments, and the same error UI as a real submit).\n *\n * Resolves with {@link FormSubmissionAttemptAllowNavigation} when the host may\n * continue (for example approve and upload an edit). Resolves `false` when\n * preparation failed; field errors and toasts have already been shown. Does\n * **not** call `onSubmit`, captcha, or analytics.\n */\nexport type FormSubmissionAttempt = () => Promise<\n false | FormSubmissionAttemptAllowNavigation\n>\n\ntype FormSubmissionAttemptContextValue = {\n register: (attempt: FormSubmissionAttempt) => () => void\n attempt: FormSubmissionAttempt\n}\n\nconst FormSubmissionAttemptContext =\n React.createContext<FormSubmissionAttemptContextValue | null>(null)\n\n/**\n * Optional context that lets a host (for example Approvals) trigger the\n * rendered form’s submit-preparation path without duplicating it.\n *\n * Wrap both the form and the host action (Approve) so they share one registry.\n * `OneBlinkFormBase` registers when `editableFormElementIds` is set. If nothing\n * is registered, {@link useFormSubmissionAttempt} still resolves with a no-op\n * {@link FormSubmissionAttemptAllowNavigation} so hosts without an editable form\n * are unchanged.\n *\n * #### Example\n *\n * ```jsx\n * import {\n * FormSubmissionAttemptContextProvider,\n * OneBlinkReadOnlyForm,\n * useFormSubmissionAttempt,\n * } from '@oneblink/apps-react'\n *\n * function ApproveButton() {\n * const attemptFormSubmission = useFormSubmissionAttempt()\n *\n * const onClickApprove = async () => {\n * const allowNavigation = await attemptFormSubmission()\n * if (!allowNavigation) {\n * return\n * }\n * // continue with the host action, then:\n * allowNavigation()\n * }\n *\n * return <button onClick={onClickApprove}>Approve</button>\n * }\n *\n * function Approval() {\n * return (\n * <FormSubmissionAttemptContextProvider>\n * <OneBlinkReadOnlyForm editableFormElementIds={['element-id']} />\n * <ApproveButton />\n * </FormSubmissionAttemptContextProvider>\n * )\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function FormSubmissionAttemptContextProvider({\n children,\n}: {\n /** The form and the host action that must share one submission attempt. */\n children: React.ReactNode\n}) {\n const attemptsRef = React.useRef<FormSubmissionAttempt[]>([])\n\n const register = React.useCallback((attempt: FormSubmissionAttempt) => {\n attemptsRef.current.push(attempt)\n return () => {\n attemptsRef.current = attemptsRef.current.filter(\n (registeredAttempt) => registeredAttempt !== attempt,\n )\n }\n }, [])\n\n const attempt = React.useCallback<FormSubmissionAttempt>(() => {\n const registeredAttempts = attemptsRef.current\n return (\n registeredAttempts[registeredAttempts.length - 1]?.() ??\n Promise.resolve(noopAllowNavigation)\n )\n }, [])\n\n const value = React.useMemo(\n () => ({\n register,\n attempt,\n }),\n [attempt, register],\n )\n\n return (\n <FormSubmissionAttemptContext.Provider value={value}>\n {children}\n </FormSubmissionAttemptContext.Provider>\n )\n}\n\n/**\n * Returns the latest form submission attempt registered under a\n * {@link FormSubmissionAttemptContextProvider}. Safe to call without a provider:\n * preparation is skipped and the promise resolves with a no-op\n * {@link FormSubmissionAttemptAllowNavigation}.\n *\n * @returns\n * @group Hooks\n */\nexport function useFormSubmissionAttempt(): FormSubmissionAttempt {\n const context = React.useContext(FormSubmissionAttemptContext)\n return context?.attempt ?? allowSubmissionAttempt\n}\n\n/**\n * Registers this form’s {@link FormSubmissionAttempt} with the nearest\n * {@link FormSubmissionAttemptContextProvider}, if one exists. Used internally\n * by `OneBlinkFormBase` when `editableFormElementIds` is provided. Pass\n * `undefined` to skip registration (for example a fully read-only form).\n */\nexport function useRegisterFormSubmissionAttempt(\n attempt: FormSubmissionAttempt | undefined,\n): void {\n const context = React.useContext(FormSubmissionAttemptContext)\n\n React.useLayoutEffect(() => {\n if (attempt) {\n return context?.register(attempt)\n }\n }, [attempt, context])\n}\n\nfunction noopAllowNavigation() {}\n\nfunction allowSubmissionAttempt(): Promise<FormSubmissionAttemptAllowNavigation> {\n return Promise.resolve(noopAllowNavigation)\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
2
|
import { CaptchaType, ExecutedLookups, FormElementsConditionallyShown } from '../types/form';
|
|
3
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) => import("../types/form").FormElementsValidation | undefined;
|
|
4
|
+
validate: (submission: SubmissionTypes.S3SubmissionData["submission"], formElementsConditionallyShown: FormElementsConditionallyShown, executedLookups: ExecutedLookups, captchaType: CaptchaType, isOffline: boolean, audience: FormTypes.FormElementHiddenFromAudience, editableFormElementIds?: string[]) => import("../types/form").FormElementsValidation | undefined;
|
|
5
5
|
};
|
|
@@ -42,7 +42,7 @@ export default function useFormValidation(pages) {
|
|
|
42
42
|
const formElementsWithName = React.useMemo(() => {
|
|
43
43
|
return stripFormElementsWithoutName(pages, false);
|
|
44
44
|
}, [pages]);
|
|
45
|
-
const handleValidate = React.useCallback((submission, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience) => {
|
|
45
|
+
const handleValidate = React.useCallback((submission, formElementsConditionallyShown, executedLookups, captchaType, isOffline, audience, editableFormElementIds) => {
|
|
46
46
|
return validateSubmission({
|
|
47
47
|
elements: formElementsWithName,
|
|
48
48
|
submission,
|
|
@@ -51,6 +51,7 @@ export default function useFormValidation(pages) {
|
|
|
51
51
|
captchaType,
|
|
52
52
|
isOffline,
|
|
53
53
|
audience,
|
|
54
|
+
editableFormElementIds,
|
|
54
55
|
});
|
|
55
56
|
}, [formElementsWithName]);
|
|
56
57
|
return {
|
|
@@ -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;AAO/E,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,CAAC,GAAG,IAAI,EAAE,WAAW,CAAC,CAAA;YAC/B,CAAC;YACD,KAAK,MAAM,CAAC;YACZ,KAAK,SAAS,CAAC,CAAC,CAAC;gBACf,OAAO;oBACL,GAAG,IAAI;oBACP,GAAG,4BAA4B,CAAC,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC;iBAClE,CAAA;YACH,CAAC;YACD,KAAK,UAAU,CAAC;YAChB,KAAK,MAAM,CAAC;YACZ,KAAK,eAAe,CAAC,CAAC,CAAC;gBACrB,OAAO;oBACL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,UAAU;YACV,8BAA8B;YAC9B,eAAe;YACf,WAAW;YACX,SAAS;YACT,QAAQ;YACR,sBAAsB;SACvB,CAAC,CAAA;IACJ,CAAC,EACD,CAAC,oBAAoB,CAAC,CACvB,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 {\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(pages: FormTypes.PageElement[]) {\n const formElementsWithName = React.useMemo(() => {\n return stripFormElementsWithoutName(pages, false)\n }, [pages])\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[],\n ) => {\n return validateSubmission({\n elements: formElementsWithName,\n submission,\n formElementsConditionallyShown,\n executedLookups,\n captchaType,\n isOffline,\n audience,\n editableFormElementIds,\n })\n },\n [formElementsWithName],\n )\n\n return {\n validate: handleValidate,\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import useEditableFormElementIds from './useEditableFormElementIds';
|
|
2
|
+
import useFormIsReadOnly from './useFormIsReadOnly';
|
|
3
|
+
import { checkIsFormElementReadOnly } from '../utils/read-only-form-elements';
|
|
4
|
+
export default function useIsFormElementReadOnly(element, isInheritedReadOnly) {
|
|
5
|
+
const isFormReadOnly = useFormIsReadOnly();
|
|
6
|
+
const editableFormElementIds = useEditableFormElementIds();
|
|
7
|
+
return checkIsFormElementReadOnly(element, {
|
|
8
|
+
isFormReadOnly,
|
|
9
|
+
isInheritedReadOnly,
|
|
10
|
+
editableFormElementIds,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=useIsFormElementReadOnly.js.map
|