@oneblink/apps-react 13.4.0 → 13.5.0-beta.2
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 +6 -2
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/OneBlinkReadOnlyForm.d.ts +2 -0
- package/dist/OneBlinkReadOnlyForm.js +6 -1
- package/dist/OneBlinkReadOnlyForm.js.map +1 -1
- package/dist/apps/services/api/drafts.js +5 -2
- package/dist/apps/services/api/drafts.js.map +1 -1
- package/dist/apps/services/prepareSubmissionData.d.ts +14 -0
- package/dist/apps/services/prepareSubmissionData.js +27 -0
- package/dist/apps/services/prepareSubmissionData.js.map +1 -1
- package/dist/components/renderer/OneBlinkFormElements.js +2 -2
- package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
- package/dist/form-elements/FormElementLookupButton.js +7 -2
- package/dist/form-elements/FormElementLookupButton.js.map +1 -1
- package/dist/form-elements/FormElementRepeatableSet.js +17 -7
- package/dist/form-elements/FormElementRepeatableSet.js.map +1 -1
- package/dist/form-elements/FormElementSection.js +2 -1
- package/dist/form-elements/FormElementSection.js.map +1 -1
- package/dist/hooks/useConditionalLogic.js +3 -1
- package/dist/hooks/useConditionalLogic.js.map +1 -1
- package/dist/hooks/useFormElementOptions.js +13 -2
- package/dist/hooks/useFormElementOptions.js.map +1 -1
- package/dist/hooks/useFormSubmissionModelContext.d.ts +19 -1
- package/dist/hooks/useFormSubmissionModelContext.js +60 -14
- package/dist/hooks/useFormSubmissionModelContext.js.map +1 -1
- package/dist/hooks/useFormSubmissionState.d.ts +10 -1
- package/dist/hooks/useFormSubmissionState.js +8 -2
- package/dist/hooks/useFormSubmissionState.js.map +1 -1
- package/dist/hooks/useStructuralSharing.d.ts +9 -0
- package/dist/hooks/useStructuralSharing.js +20 -0
- package/dist/hooks/useStructuralSharing.js.map +1 -0
- package/dist/services/form-validation/validators.js +3 -0
- package/dist/services/form-validation/validators.js.map +1 -1
- package/dist/services/generate-default-data.d.ts +9 -1
- package/dist/services/generate-default-data.js +5 -3
- package/dist/services/generate-default-data.js.map +1 -1
- package/dist/types/form.d.ts +4 -0
- package/dist/types/form.js.map +1 -1
- package/dist/utils/replaceEqualDeep.d.ts +14 -0
- package/dist/utils/replaceEqualDeep.js +58 -0
- package/dist/utils/replaceEqualDeep.js.map +1 -0
- package/package.json +5 -3
|
@@ -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,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,QAA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AAC,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. 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 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)) {\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 isDerivedChange,\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 () =>\n maxSetEntries === undefined || 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 (\n nestedElement,\n { value, executedLookups, sectionState, isDerivedChange },\n idPrefix,\n ) => {\n onChange(\n index,\n nestedElement,\n {\n value,\n executedLookups,\n sectionState,\n isDerivedChange,\n },\n idPrefix,\n )\n },\n [index, onChange],\n )\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults, options) => {\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 }, options)\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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B,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 return {\n ...section,\n id: `${startOfId ? startOfId : ''}${element.name}_entry-${newEntryIndex}_${restOfId}`,\n }\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 state.push({\n ...section,\n id: `${prefix ? prefix : ''}${element.name}_entry-${newEntryIndex}_${restOfId}`,\n })\n return state\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 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)) {\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 isDerivedChange,\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 === undefined || 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 (\n nestedElement,\n { value, executedLookups, sectionState, isDerivedChange },\n idPrefix,\n ) => {\n onChange(\n index,\n nestedElement,\n {\n value,\n executedLookups,\n sectionState,\n isDerivedChange,\n },\n idPrefix,\n )\n },\n [index, onChange],\n )\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults, options) => {\n onLookup((currentFormSubmission) => {\n let newEntry = {}\n const entries = currentFormSubmission.submission[\n element.name\n ] as Array<SubmissionTypes.S3SubmissionData['submission']>\n const existingExecutedLookups = (currentFormSubmission\n .executedLookups?.[element.name] ??\n Array.from(Array(entries.length))) as ExecutedLookups[]\n const repeatableSetExecutedLookups = Array.isArray(\n existingExecutedLookups,\n )\n ? [...existingExecutedLookups]\n : existingExecutedLookups\n // if the repeatable set is prefilled or has minimum entries then executed lookups exists,\n // but is an empty array\n if (\n Array.isArray(repeatableSetExecutedLookups) &&\n !repeatableSetExecutedLookups[index]\n ) {\n repeatableSetExecutedLookups[index] = {}\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 }, options)\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"]}
|
|
@@ -16,7 +16,8 @@ function sectionStateToBoolean(state) {
|
|
|
16
16
|
}
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
const EMPTY_SECTION_STATE = [];
|
|
20
|
+
function FormElementSection({ element, childrenReadOnly, onLookup, displayValidationMessages, onUpdateFormElements, sectionHeaderId, sectionState = EMPTY_SECTION_STATE, ...props }) {
|
|
20
21
|
const sectionStateEntry = sectionState.find((section) => section.id === `${props['idPrefix']}${element.id}`);
|
|
21
22
|
const isCollapsedFromState = (sectionStateEntry === null || sectionStateEntry === void 0 ? void 0 : sectionStateEntry.state)
|
|
22
23
|
? sectionStateToBoolean(sectionStateEntry.state)
|
|
@@ -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;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAA;AAEzE,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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,qBAAqB,IAAI,aAAI,SAAS,EAAC,qBAAqB,GAAG,EACzE,KAAC,QAAQ,IACP,EAAE,EAAE,CAAC,WAAW,EAChB,OAAO,EAAE;oBACP,IAAI,EAAE,qBAAqB;oBAC3B,OAAO,EAAE,sBAAsB;oBAC/B,MAAM,EAAE,uBAAuB;iBAChC,YAED,KAAC,sBAAsB,IACrB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,+BAA+B,YAE3C,KAAC,yBAAyB,IAAC,UAAU,EAAE,CAAC,WAAW,YACjD,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,GACwB,GACL,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'\nimport { IsSectionExpandedProvider } from '../hooks/useIsSectionExpanded'\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, options) => {\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 }, options)\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 <IsSectionExpandedProvider isExpanded={!isCollapsed}>\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 </IsSectionExpandedProvider>\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,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;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAA;AAEzE,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,MAAM,mBAAmB,GAA8B,EAAE,CAAA;AAEzD,SAAS,kBAAkB,CAA6C,EACtE,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EACf,YAAY,GAAG,mBAAmB,EAClC,GAAG,KAAK,EAWT;IACC,MAAM,iBAAiB,GAAG,YAAY,CAAC,IAAI,CACzC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,EAAE,EAAE,CAChE,CAAA;IACD,MAAM,oBAAoB,GAAG,CAA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B,UAAU,EAAE,+BAA+B,YAE3C,KAAC,yBAAyB,IAAC,UAAU,EAAE,CAAC,WAAW,YACjD,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,GACwB,GACL,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'\nimport { IsSectionExpandedProvider } from '../hooks/useIsSectionExpanded'\n\nfunction sectionStateToBoolean(state: 'COLLAPSED' | 'EXPANDED') {\n if (state === 'COLLAPSED') {\n return true\n }\n return false\n}\n\nconst EMPTY_SECTION_STATE: NonNullable<SectionState> = []\n\nfunction FormElementSection<T extends FormTypes._NestedElementsElement>({\n element,\n childrenReadOnly,\n onLookup,\n displayValidationMessages,\n onUpdateFormElements,\n sectionHeaderId,\n sectionState = EMPTY_SECTION_STATE,\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, options) => {\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 }, options)\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 <IsSectionExpandedProvider isExpanded={!isCollapsed}>\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 </IsSectionExpandedProvider>\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,6 +1,7 @@
|
|
|
1
1
|
import { Sentry } from '../apps';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { conditionalLogicService } from '@oneblink/sdk-core';
|
|
4
|
+
import useStructuralSharing from './useStructuralSharing';
|
|
4
5
|
export default function useConditionalLogic({ formElements, submission, enableSubmission, }) {
|
|
5
6
|
const [conditionalLogicError, setConditionalLogicError] = React.useState();
|
|
6
7
|
const errorCallback = React.useCallback((error) => {
|
|
@@ -20,9 +21,10 @@ export default function useConditionalLogic({ formElements, submission, enableSu
|
|
|
20
21
|
submissionConditionallyEnabled: isSubmissionEnabled,
|
|
21
22
|
};
|
|
22
23
|
}, [formElements, submission, enableSubmission, errorCallback]);
|
|
24
|
+
const sharedFormElementsConditionallyShown = useStructuralSharing(formElementsConditionallyShown);
|
|
23
25
|
return {
|
|
24
26
|
conditionalLogicError,
|
|
25
|
-
formElementsConditionallyShown,
|
|
27
|
+
formElementsConditionallyShown: sharedFormElementsConditionallyShown,
|
|
26
28
|
submissionConditionallyEnabled,
|
|
27
29
|
};
|
|
28
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConditionalLogic.js","sourceRoot":"","sources":["../../src/hooks/useConditionalLogic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"useConditionalLogic.js","sourceRoot":"","sources":["../../src/hooks/useConditionalLogic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;AAEzD,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,YAAY,EACZ,UAAU,EACV,gBAAgB,GAKjB;IACC,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,GAAG,KAAK,CAAC,QAAQ,EAErE,CAAA;IAEH,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAAY,EAAE,EAAE;QACvD,OAAO,CAAC,IAAI,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAA;QAC7D,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAC9B,wBAAwB,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,GACtE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACjB,MAAM,EAAE,8BAA8B,EAAE,mBAAmB,EAAE,GAC3D,uBAAuB,CAAC,sCAAsC,CAAC;YAC7D,YAAY;YACZ,UAAU;YACV,gBAAgB;YAChB,aAAa;SACd,CAAC,CAAA;QAEJ,OAAO;YACL,8BAA8B;YAC9B,8BAA8B,EAAE,mBAAmB;SACpD,CAAA;IACH,CAAC,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAC,CAAA;IACjE,MAAM,oCAAoC,GAAG,oBAAoB,CAC/D,8BAA8B,CAC/B,CAAA;IAED,OAAO;QACL,qBAAqB;QACrB,8BAA8B,EAAE,oCAAoC;QACpE,8BAA8B;KAC/B,CAAA;AACH,CAAC","sourcesContent":["import { Sentry } from '../apps'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport { conditionalLogicService } from '@oneblink/sdk-core'\nimport useStructuralSharing from './useStructuralSharing'\n\nexport default function useConditionalLogic({\n formElements,\n submission,\n enableSubmission,\n}: {\n formElements: FormTypes.FormElement[]\n submission: SubmissionTypes.S3SubmissionData['submission']\n enableSubmission: FormTypes.Form['enableSubmission']\n}) {\n const [conditionalLogicError, setConditionalLogicError] = React.useState<\n Error | undefined\n >()\n\n const errorCallback = React.useCallback((error: Error) => {\n console.warn('Error while checking conditional logic', error)\n Sentry.captureException(error)\n setConditionalLogicError(error)\n }, [])\n\n const { formElementsConditionallyShown, submissionConditionallyEnabled } =\n React.useMemo(() => {\n const { formElementsConditionallyShown, isSubmissionEnabled } =\n conditionalLogicService.generateFormElementsConditionallyShown({\n formElements,\n submission,\n enableSubmission,\n errorCallback,\n })\n\n return {\n formElementsConditionallyShown,\n submissionConditionallyEnabled: isSubmissionEnabled,\n }\n }, [formElements, submission, enableSubmission, errorCallback])\n const sharedFormElementsConditionallyShown = useStructuralSharing(\n formElementsConditionallyShown,\n )\n\n return {\n conditionalLogicError,\n formElementsConditionallyShown: sharedFormElementsConditionallyShown,\n submissionConditionallyEnabled,\n }\n}\n"]}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useLoadDynamicOptionsEffect } from './useDynamicOptionsLoaderState';
|
|
3
|
-
import
|
|
3
|
+
import { useFormSubmissionModelWithParent } from './useFormSubmissionModelContext';
|
|
4
4
|
import processInjectableOption from '../services/injectableOptions';
|
|
5
5
|
import useTaskContext from './useTaskContext';
|
|
6
6
|
import useUserProfileForInjectables from './useUserProfileForInjectables';
|
|
7
|
+
function isInjectableText(text) {
|
|
8
|
+
return typeof text === 'string' && text.includes('{');
|
|
9
|
+
}
|
|
7
10
|
export default function useFormElementOptions({ element, value, onChange, conditionallyShownOptionsElement, onFilter, onUpdateFormElements, }) {
|
|
8
11
|
const taskContext = useTaskContext();
|
|
9
12
|
const userProfileForInjectables = useUserProfileForInjectables();
|
|
10
|
-
const
|
|
13
|
+
const hasInjectableOptions = React.useMemo(() => {
|
|
14
|
+
var _a;
|
|
15
|
+
return !!((_a = element.options) === null || _a === void 0 ? void 0 : _a.some((option) => isInjectableText(option.label) || isInjectableText(option.value)));
|
|
16
|
+
}, [element.options]);
|
|
17
|
+
const { formSubmissionModel, elements, parent } = useFormSubmissionModelWithParent(hasInjectableOptions);
|
|
11
18
|
const conditionallyShownOptions = conditionallyShownOptionsElement === null || conditionallyShownOptionsElement === void 0 ? void 0 : conditionallyShownOptionsElement.options;
|
|
12
19
|
//options that are shown due to conditional logic
|
|
13
20
|
const shownOptions = React.useMemo(() => {
|
|
@@ -24,6 +31,9 @@ export default function useFormElementOptions({ element, value, onChange, condit
|
|
|
24
31
|
}, [conditionallyShownOptions, element.options, onFilter]);
|
|
25
32
|
//
|
|
26
33
|
const withInjectedOptions = React.useMemo(() => {
|
|
34
|
+
if (!hasInjectableOptions) {
|
|
35
|
+
return shownOptions;
|
|
36
|
+
}
|
|
27
37
|
return shownOptions.reduce((memo, option) => {
|
|
28
38
|
const newOptions = processInjectableOption({
|
|
29
39
|
option,
|
|
@@ -40,6 +50,7 @@ export default function useFormElementOptions({ element, value, onChange, condit
|
|
|
40
50
|
}, [
|
|
41
51
|
elements,
|
|
42
52
|
formSubmissionModel,
|
|
53
|
+
hasInjectableOptions,
|
|
43
54
|
parent,
|
|
44
55
|
shownOptions,
|
|
45
56
|
taskContext,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormElementOptions.js","sourceRoot":"","sources":["../../src/hooks/useFormElementOptions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAA;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"useFormElementOptions.js","sourceRoot":"","sources":["../../src/hooks/useFormElementOptions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAA;AAC5E,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAA;AAClF,OAAO,uBAAuB,MAAM,+BAA+B,CAAA;AACnE,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,4BAA4B,MAAM,gCAAgC,CAAA;AAEzE,SAAS,gBAAgB,CAAC,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OAAO,EAAE;oBAChB,KAAK,EAAE,aAA8B;oBACrC,eAAe,EAAE,IAAI;iBACtB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC,EAAE;QACD,OAAO;QACP,QAAQ;QACR,KAAK;QACL,gCAAgC,aAAhC,gCAAgC,uBAAhC,gCAAgC,CAAE,mBAAmB;QACrD,eAAe;KAChB,CAAC,CAAA;IAEF,2BAA2B,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAA;IAE1D,OAAO,eAAe,CAAA;AACxB,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport {\n FormElementValueChangeHandler,\n FormElementConditionallyShownElement,\n UpdateFormElementsHandler,\n} from '../types/form'\nimport { useLoadDynamicOptionsEffect } from './useDynamicOptionsLoaderState'\nimport { useFormSubmissionModelWithParent } from './useFormSubmissionModelContext'\nimport processInjectableOption from '../services/injectableOptions'\nimport useTaskContext from './useTaskContext'\nimport useUserProfileForInjectables from './useUserProfileForInjectables'\n\nfunction isInjectableText(text: unknown) {\n return typeof text === 'string' && text.includes('{')\n}\n\nexport default function useFormElementOptions<T>({\n element,\n value,\n onChange,\n conditionallyShownOptionsElement,\n onFilter,\n onUpdateFormElements,\n}: {\n element: FormTypes.FormElementWithOptions\n value: unknown | undefined\n onChange: FormElementValueChangeHandler<T>\n conditionallyShownOptionsElement:\n | FormElementConditionallyShownElement\n | undefined\n onFilter?: (choiceElementOption: FormTypes.ChoiceElementOption) => boolean\n onUpdateFormElements: UpdateFormElementsHandler\n}) {\n const taskContext = useTaskContext()\n const userProfileForInjectables = useUserProfileForInjectables()\n\n const hasInjectableOptions = React.useMemo(\n () =>\n !!element.options?.some(\n (option) =>\n isInjectableText(option.label) || isInjectableText(option.value),\n ),\n [element.options],\n )\n const { formSubmissionModel, elements, parent } =\n useFormSubmissionModelWithParent(hasInjectableOptions)\n const conditionallyShownOptions = conditionallyShownOptionsElement?.options\n //options that are shown due to conditional logic\n const shownOptions = React.useMemo<FormTypes.ChoiceElementOption[]>(() => {\n if (!element.options) {\n return []\n }\n if (!conditionallyShownOptions && !onFilter) {\n return element.options\n }\n return element.options.filter((option) => {\n return (\n !conditionallyShownOptions ||\n conditionallyShownOptions.some(({ id }) => id === option.id)\n )\n })\n }, [conditionallyShownOptions, element.options, onFilter])\n\n //\n const withInjectedOptions = React.useMemo(() => {\n if (!hasInjectableOptions) {\n return shownOptions\n }\n return shownOptions.reduce<FormTypes.ChoiceElementOption[]>(\n (memo, option) => {\n const newOptions = processInjectableOption({\n option,\n submission: formSubmissionModel,\n formElements: elements,\n contextSubmission: parent?.formSubmissionModel || {},\n contextElements: parent?.elements || [],\n taskContext,\n userProfile: userProfileForInjectables,\n })\n memo.push(...newOptions)\n\n return memo\n },\n [],\n )\n }, [\n elements,\n formSubmissionModel,\n hasInjectableOptions,\n parent,\n shownOptions,\n taskContext,\n userProfileForInjectables,\n ])\n\n //options that are shown based on conditional logic, attributes, and user input\n const filteredOptions = React.useMemo<FormTypes.ChoiceElementOption[]>(() => {\n const reducedOptions = withInjectedOptions.filter(\n (option) => !onFilter || (onFilter(option) && !option.displayAlways),\n )\n if (element.type === 'autocomplete') {\n const alwaysShownOptions = withInjectedOptions.filter(\n (option) => option.displayAlways,\n )\n reducedOptions.push(...alwaysShownOptions)\n }\n return reducedOptions\n }, [withInjectedOptions, element.type, onFilter])\n\n React.useEffect(() => {\n if (\n !element.options ||\n conditionallyShownOptionsElement?.dependencyIsLoading\n ) {\n return\n }\n\n if (\n typeof value === 'string' &&\n !filteredOptions.some((option) => value === option.value)\n ) {\n onChange(element, {\n value: undefined,\n isDerivedChange: true,\n })\n return\n }\n\n if (Array.isArray(value)) {\n const newValue = value.filter((selectedValue) =>\n filteredOptions.some((option) => selectedValue === option.value),\n )\n if (newValue.length !== value.length) {\n const newValueArray = newValue.length ? newValue : undefined\n onChange(element, {\n value: newValueArray as T | undefined,\n isDerivedChange: true,\n })\n }\n }\n }, [\n element,\n onChange,\n value,\n conditionallyShownOptionsElement?.dependencyIsLoading,\n filteredOptions,\n ])\n\n useLoadDynamicOptionsEffect(element, onUpdateFormElements)\n\n return filteredOptions\n}\n"]}
|
|
@@ -3,15 +3,33 @@ import { FormElement } from '@oneblink/types/typescript/forms';
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { FormElementsConditionallyShown } from '../types/form';
|
|
5
5
|
export type FormSubmissionModelContextValue = {
|
|
6
|
+
/**
|
|
7
|
+
* Must not be mutated in place, the same object is cached and shared between
|
|
8
|
+
* every provider and consumer rendered with the same submission.
|
|
9
|
+
*/
|
|
6
10
|
formSubmissionModel: SubmissionTypes.S3SubmissionData['submission'];
|
|
7
11
|
parent?: FormSubmissionModelContextValue;
|
|
8
12
|
elements: FormElement[];
|
|
9
13
|
};
|
|
14
|
+
type LocalFormSubmissionModelContextValue = Omit<FormSubmissionModelContextValue, 'parent'>;
|
|
10
15
|
export declare function FormSubmissionModelContextProvider({ children, model, elements, formElementsConditionallyShown, }: {
|
|
11
16
|
model: SubmissionTypes.S3SubmissionData['submission'];
|
|
12
17
|
elements: FormTypes.FormElement[];
|
|
13
18
|
formElementsConditionallyShown: FormElementsConditionallyShown | undefined;
|
|
14
19
|
children: React.ReactNode;
|
|
15
20
|
}): import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The cleaned submission model and elements for the closest
|
|
23
|
+
* `FormSubmissionModelContextProvider`, without access to parent models.
|
|
24
|
+
*/
|
|
25
|
+
export default function useFormSubmissionModel(): LocalFormSubmissionModelContextValue;
|
|
26
|
+
/**
|
|
27
|
+
* The same as `useFormSubmissionModel()`, but also includes the parent models.
|
|
28
|
+
* Pass `includeParent: false` to avoid re-rendering when values outside of the
|
|
29
|
+
* closest `FormSubmissionModelContextProvider` change.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useFormSubmissionModelWithParent(includeParent: boolean): LocalFormSubmissionModelContextValue & {
|
|
32
|
+
parent?: FormSubmissionModelContextValue;
|
|
33
|
+
};
|
|
17
34
|
export declare function useFormSubmissionModelParent(): FormSubmissionModelContextValue;
|
|
35
|
+
export {};
|
|
@@ -1,32 +1,78 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { weakMapMemoize } from 'reselect';
|
|
3
4
|
import cleanFormSubmissionModel from '../services/cleanFormSubmissionModel';
|
|
5
|
+
// The local value is kept separate from the context that includes `parent` so
|
|
6
|
+
// that consumers inside a repeatable set entry do not re-render whenever a value
|
|
7
|
+
// outside of the entry changes. A separate context is used for each level of
|
|
8
|
+
// nesting because React re-renders every consumer of a context below a provider
|
|
9
|
+
// whose value changed, even consumers below a nested provider of the same
|
|
10
|
+
// context.
|
|
11
|
+
const LocalFormSubmissionModelContexts = [];
|
|
12
|
+
function getLocalFormSubmissionModelContext(depth) {
|
|
13
|
+
let context = LocalFormSubmissionModelContexts[depth];
|
|
14
|
+
if (!context) {
|
|
15
|
+
context = React.createContext(undefined);
|
|
16
|
+
LocalFormSubmissionModelContexts[depth] = context;
|
|
17
|
+
}
|
|
18
|
+
return context;
|
|
19
|
+
}
|
|
20
|
+
const FormSubmissionModelDepthContext = React.createContext(-1);
|
|
21
|
+
function useLocalFormSubmissionModelContext() {
|
|
22
|
+
const depth = React.useContext(FormSubmissionModelDepthContext);
|
|
23
|
+
return getLocalFormSubmissionModelContext(depth);
|
|
24
|
+
}
|
|
4
25
|
const FormSubmissionModelContext = React.createContext(undefined);
|
|
26
|
+
// Every page and section provider cleans the same root submission, so the
|
|
27
|
+
// result is shared between providers rendered with the same arguments. This
|
|
28
|
+
// relies on nothing mutating the submission, elements or cleaned models in
|
|
29
|
+
// place.
|
|
30
|
+
const getCleanFormSubmissionModel = weakMapMemoize((model, elements, formElementsConditionallyShown) => cleanFormSubmissionModel(model, elements, formElementsConditionallyShown, true).model);
|
|
5
31
|
export function FormSubmissionModelContextProvider({ children, model, elements, formElementsConditionallyShown, }) {
|
|
6
32
|
const formSubmissionModelContext = React.useContext(FormSubmissionModelContext);
|
|
33
|
+
const depth = React.useContext(FormSubmissionModelDepthContext) + 1;
|
|
34
|
+
const LocalFormSubmissionModelContext = getLocalFormSubmissionModelContext(depth);
|
|
35
|
+
const localValue = React.useMemo(() => {
|
|
36
|
+
return {
|
|
37
|
+
formSubmissionModel: getCleanFormSubmissionModel(model, elements, formElementsConditionallyShown),
|
|
38
|
+
elements,
|
|
39
|
+
};
|
|
40
|
+
}, [model, elements, formElementsConditionallyShown]);
|
|
7
41
|
const value = React.useMemo(() => {
|
|
8
42
|
return {
|
|
9
|
-
|
|
43
|
+
...localValue,
|
|
10
44
|
parent: formSubmissionModelContext,
|
|
11
|
-
elements,
|
|
12
45
|
};
|
|
13
|
-
}, [
|
|
14
|
-
|
|
15
|
-
elements,
|
|
16
|
-
formElementsConditionallyShown,
|
|
17
|
-
formSubmissionModelContext,
|
|
18
|
-
]);
|
|
19
|
-
return (_jsx(FormSubmissionModelContext.Provider, { value: value, children: children }));
|
|
46
|
+
}, [localValue, formSubmissionModelContext]);
|
|
47
|
+
return (_jsx(FormSubmissionModelContext.Provider, { value: value, children: _jsx(FormSubmissionModelDepthContext.Provider, { value: depth, children: _jsx(LocalFormSubmissionModelContext.Provider, { value: localValue, children: children }) }) }));
|
|
20
48
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!formSubmissionModelContext) {
|
|
49
|
+
function assertContextValue(value) {
|
|
50
|
+
if (!value) {
|
|
24
51
|
throw new Error('"FormSubmissionModelContext" does not have a value in this context');
|
|
25
52
|
}
|
|
26
|
-
return
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The cleaned submission model and elements for the closest
|
|
57
|
+
* `FormSubmissionModelContextProvider`, without access to parent models.
|
|
58
|
+
*/
|
|
59
|
+
export default function useFormSubmissionModel() {
|
|
60
|
+
const LocalFormSubmissionModelContext = useLocalFormSubmissionModelContext();
|
|
61
|
+
return assertContextValue(React.use(LocalFormSubmissionModelContext));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The same as `useFormSubmissionModel()`, but also includes the parent models.
|
|
65
|
+
* Pass `includeParent: false` to avoid re-rendering when values outside of the
|
|
66
|
+
* closest `FormSubmissionModelContextProvider` change.
|
|
67
|
+
*/
|
|
68
|
+
export function useFormSubmissionModelWithParent(includeParent) {
|
|
69
|
+
const LocalFormSubmissionModelContext = useLocalFormSubmissionModelContext();
|
|
70
|
+
return assertContextValue(React.use(includeParent
|
|
71
|
+
? FormSubmissionModelContext
|
|
72
|
+
: LocalFormSubmissionModelContext));
|
|
27
73
|
}
|
|
28
74
|
export function useFormSubmissionModelParent() {
|
|
29
|
-
let formSubmissionModelContext =
|
|
75
|
+
let formSubmissionModelContext = assertContextValue(React.useContext(FormSubmissionModelContext));
|
|
30
76
|
while (formSubmissionModelContext.parent) {
|
|
31
77
|
formSubmissionModelContext = formSubmissionModelContext.parent;
|
|
32
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormSubmissionModelContext.js","sourceRoot":"","sources":["../../src/hooks/useFormSubmissionModelContext.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,wBAAwB,MAAM,sCAAsC,CAAA;
|
|
1
|
+
{"version":3,"file":"useFormSubmissionModelContext.js","sourceRoot":"","sources":["../../src/hooks/useFormSubmissionModelContext.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,wBAAwB,MAAM,sCAAsC,CAAA;AAkB3E,8EAA8E;AAC9E,iFAAiF;AACjF,6EAA6E;AAC7E,gFAAgF;AAChF,0EAA0E;AAC1E,WAAW;AACX,MAAM,gCAAgC,GAElC,EAAE,CAAA;AACN,SAAS,kCAAkC,CAAC,KAAa;IACvD,I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AA0B,CAAC,MAAM,EAAE,CAAC;QACzC,0BAA0B,GAAG,0BAA0B,CAAC,MAAM,CAAA;IAChE,CAAC;IACD,OAAO,0BAA0B,CAAA;AACnC,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormElement } from '@oneblink/types/typescript/forms'\nimport * as React from 'react'\nimport { weakMapMemoize } from 'reselect'\nimport cleanFormSubmissionModel from '../services/cleanFormSubmissionModel'\nimport { FormElementsConditionallyShown } from '../types/form'\n\nexport type FormSubmissionModelContextValue = {\n /**\n * Must not be mutated in place, the same object is cached and shared between\n * every provider and consumer rendered with the same submission.\n */\n formSubmissionModel: SubmissionTypes.S3SubmissionData['submission']\n parent?: FormSubmissionModelContextValue\n elements: FormElement[]\n}\n\ntype LocalFormSubmissionModelContextValue = Omit<\n FormSubmissionModelContextValue,\n 'parent'\n>\n\n// The local value is kept separate from the context that includes `parent` so\n// that consumers inside a repeatable set entry do not re-render whenever a value\n// outside of the entry changes. A separate context is used for each level of\n// nesting because React re-renders every consumer of a context below a provider\n// whose value changed, even consumers below a nested provider of the same\n// context.\nconst LocalFormSubmissionModelContexts: Array<\n React.Context<LocalFormSubmissionModelContextValue | undefined>\n> = []\nfunction getLocalFormSubmissionModelContext(depth: number) {\n let context = LocalFormSubmissionModelContexts[depth]\n if (!context) {\n context = React.createContext<\n LocalFormSubmissionModelContextValue | undefined\n >(undefined)\n LocalFormSubmissionModelContexts[depth] = context\n }\n return context\n}\nconst FormSubmissionModelDepthContext = React.createContext(-1)\n\nfunction useLocalFormSubmissionModelContext() {\n const depth = React.useContext(FormSubmissionModelDepthContext)\n return getLocalFormSubmissionModelContext(depth)\n}\n\nconst FormSubmissionModelContext = React.createContext<\n FormSubmissionModelContextValue | undefined\n>(undefined)\n\n// Every page and section provider cleans the same root submission, so the\n// result is shared between providers rendered with the same arguments. This\n// relies on nothing mutating the submission, elements or cleaned models in\n// place.\nconst getCleanFormSubmissionModel = weakMapMemoize(\n (\n model: SubmissionTypes.S3SubmissionData['submission'],\n elements: FormTypes.FormElement[],\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined,\n ) =>\n cleanFormSubmissionModel(\n model,\n elements,\n formElementsConditionallyShown,\n true,\n ).model,\n)\n\nexport function FormSubmissionModelContextProvider({\n children,\n model,\n elements,\n formElementsConditionallyShown,\n}: {\n model: SubmissionTypes.S3SubmissionData['submission']\n elements: FormTypes.FormElement[]\n formElementsConditionallyShown: FormElementsConditionallyShown | undefined\n children: React.ReactNode\n}) {\n const formSubmissionModelContext = React.useContext(\n FormSubmissionModelContext,\n )\n const depth = React.useContext(FormSubmissionModelDepthContext) + 1\n const LocalFormSubmissionModelContext =\n getLocalFormSubmissionModelContext(depth)\n const localValue = React.useMemo(() => {\n return {\n formSubmissionModel: getCleanFormSubmissionModel(\n model,\n elements,\n formElementsConditionallyShown,\n ),\n elements,\n }\n }, [model, elements, formElementsConditionallyShown])\n const value = React.useMemo(() => {\n return {\n ...localValue,\n parent: formSubmissionModelContext,\n }\n }, [localValue, formSubmissionModelContext])\n return (\n <FormSubmissionModelContext.Provider value={value}>\n <FormSubmissionModelDepthContext.Provider value={depth}>\n <LocalFormSubmissionModelContext.Provider value={localValue}>\n {children}\n </LocalFormSubmissionModelContext.Provider>\n </FormSubmissionModelDepthContext.Provider>\n </FormSubmissionModelContext.Provider>\n )\n}\n\nfunction assertContextValue<T>(value: T | undefined): T {\n if (!value) {\n throw new Error(\n '\"FormSubmissionModelContext\" does not have a value in this context',\n )\n }\n return value\n}\n\n/**\n * The cleaned submission model and elements for the closest\n * `FormSubmissionModelContextProvider`, without access to parent models.\n */\nexport default function useFormSubmissionModel() {\n const LocalFormSubmissionModelContext = useLocalFormSubmissionModelContext()\n return assertContextValue(React.use(LocalFormSubmissionModelContext))\n}\n\n/**\n * The same as `useFormSubmissionModel()`, but also includes the parent models.\n * Pass `includeParent: false` to avoid re-rendering when values outside of the\n * closest `FormSubmissionModelContextProvider` change.\n */\nexport function useFormSubmissionModelWithParent(\n includeParent: boolean,\n): LocalFormSubmissionModelContextValue & {\n parent?: FormSubmissionModelContextValue\n} {\n const LocalFormSubmissionModelContext = useLocalFormSubmissionModelContext()\n return assertContextValue(\n React.use(\n includeParent\n ? FormSubmissionModelContext\n : LocalFormSubmissionModelContext,\n ),\n )\n}\n\nexport function useFormSubmissionModelParent() {\n let formSubmissionModelContext = assertContextValue(\n React.useContext(FormSubmissionModelContext),\n )\n while (formSubmissionModelContext.parent) {\n formSubmissionModelContext = formSubmissionModelContext.parent\n }\n return formSubmissionModelContext\n}\n"]}
|