@oneblink/apps-react 13.0.0-beta.1 → 13.0.0-beta.11
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 +351 -193
- 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/apps/approvals-service.d.ts +2 -60
- package/dist/apps/approvals-service.js +1 -181
- package/dist/apps/approvals-service.js.map +1 -1
- package/dist/apps/services/api/submissions.d.ts +3 -2
- package/dist/apps/services/api/submissions.js +3 -6
- package/dist/apps/services/api/submissions.js.map +1 -1
- package/dist/apps/submission-service.d.ts +11 -5
- package/dist/apps/submission-service.js +9 -4
- package/dist/apps/submission-service.js.map +1 -1
- package/dist/components/renderer/LookupButton.d.ts +1 -2
- package/dist/components/renderer/LookupButton.js +7 -6
- package/dist/components/renderer/LookupButton.js.map +1 -1
- package/dist/components/renderer/LookupNotification.js +31 -24
- 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/PageFormElements.js +8 -3
- package/dist/components/renderer/PageFormElements.js.map +1 -1
- package/dist/components/renderer/ReverseGeocode.js +6 -11
- package/dist/components/renderer/ReverseGeocode.js.map +1 -1
- package/dist/form-elements/FormElementABN.js +1 -1
- package/dist/form-elements/FormElementABN.js.map +1 -1
- package/dist/form-elements/FormElementBSB.js +1 -1
- package/dist/form-elements/FormElementBSB.js.map +1 -1
- package/dist/form-elements/FormElementBarcodeScanner.js +1 -1
- package/dist/form-elements/FormElementBarcodeScanner.js.map +1 -1
- package/dist/form-elements/FormElementCalculation.js +1 -0
- package/dist/form-elements/FormElementCalculation.js.map +1 -1
- package/dist/form-elements/FormElementCheckBoxes.js +1 -1
- package/dist/form-elements/FormElementCheckBoxes.js.map +1 -1
- package/dist/form-elements/FormElementDate.js +1 -1
- package/dist/form-elements/FormElementDate.js.map +1 -1
- package/dist/form-elements/FormElementDateTime.js +1 -1
- package/dist/form-elements/FormElementDateTime.js.map +1 -1
- package/dist/form-elements/FormElementEmail.js +1 -1
- package/dist/form-elements/FormElementEmail.js.map +1 -1
- package/dist/form-elements/FormElementForm.d.ts +8 -9
- package/dist/form-elements/FormElementForm.js +4 -3
- package/dist/form-elements/FormElementForm.js.map +1 -1
- package/dist/form-elements/FormElementLookupButton.js +4 -3
- package/dist/form-elements/FormElementLookupButton.js.map +1 -1
- package/dist/form-elements/FormElementNumber.js +1 -1
- package/dist/form-elements/FormElementNumber.js.map +1 -1
- package/dist/form-elements/FormElementRepeatableSet.d.ts +4 -4
- package/dist/form-elements/FormElementRepeatableSet.js +6 -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 +2 -2
- package/dist/form-elements/FormElementSection.js.map +1 -1
- package/dist/form-elements/FormElementSelect.js +1 -1
- package/dist/form-elements/FormElementSelect.js.map +1 -1
- package/dist/form-elements/FormElementSummary.js +2 -0
- package/dist/form-elements/FormElementSummary.js.map +1 -1
- package/dist/form-elements/FormElementTelephone.js +1 -1
- package/dist/form-elements/FormElementTelephone.js.map +1 -1
- package/dist/form-elements/FormElementText.js +1 -1
- package/dist/form-elements/FormElementText.js.map +1 -1
- package/dist/form-elements/FormElementTextarea.js +1 -1
- package/dist/form-elements/FormElementTextarea.js.map +1 -1
- package/dist/form-elements/FormElementTime.js +1 -1
- package/dist/form-elements/FormElementTime.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/useFormElementOptions.js +2 -0
- package/dist/hooks/useFormElementOptions.js.map +1 -1
- package/dist/hooks/useFormIsDirty.d.ts +56 -0
- package/dist/hooks/useFormIsDirty.js +121 -0
- package/dist/hooks/useFormIsDirty.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/useFormSubmissionAutoSaveState.d.ts +2 -9
- package/dist/hooks/useFormSubmissionAutoSaveState.js +4 -2
- package/dist/hooks/useFormSubmissionAutoSaveState.js.map +1 -1
- 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/useInjectPages.d.ts +2 -1
- package/dist/hooks/useInjectPages.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/hooks/useLookupNotification.d.ts +23 -2
- package/dist/hooks/useLookupNotification.js +2 -1
- package/dist/hooks/useLookupNotification.js.map +1 -1
- package/dist/hooks/useLookups.d.ts +3 -3
- package/dist/hooks/useLookups.js +7 -4
- package/dist/hooks/useLookups.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -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/services/getFlowInstanceNodesWithMeta.d.ts +70 -0
- package/dist/services/getFlowInstanceNodesWithMeta.js +247 -0
- package/dist/services/getFlowInstanceNodesWithMeta.js.map +1 -0
- package/dist/types/form.d.ts +17 -3
- package/dist/types/form.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 +4 -3
- 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
|
@@ -60,7 +60,7 @@ function FormElementDate({ id, element, readOnly, value, onChange, validationMes
|
|
|
60
60
|
}, [value]);
|
|
61
61
|
const { isLookingUp } = React.useContext(LookupNotificationContext);
|
|
62
62
|
const isDisplayingValidationMessage = (displayValidationMessage || isDirty) && !!validationMessage && !isLookingUp;
|
|
63
|
-
return (_jsx("div", { className: "cypress-date-element", children: _jsxs(FormElementLabelContainer, { className: "ob-date", id: id, element: element, required: element.required, children: [_jsxs("div", { className: "field has-addons", children: [_jsx(DatePicker, { label: element.label, format: shortDateFormat, ...commonProps }), !readOnly && (_jsx(PickerInputButton, { tooltip: "Select date", onClick: openDatePicker, icon: "event" })), !!readOnly && !!text && (_jsx("div", { className: "control", children: _jsx(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }) })), _jsx(LookupButton, {
|
|
63
|
+
return (_jsx("div", { className: "cypress-date-element", children: _jsxs(FormElementLabelContainer, { className: "ob-date", id: id, element: element, required: element.required, children: [_jsxs("div", { className: "field has-addons", children: [_jsx(DatePicker, { label: element.label, format: shortDateFormat, ...commonProps }), !readOnly && (_jsx(PickerInputButton, { tooltip: "Select date", onClick: openDatePicker, icon: "event" })), !!readOnly && !!text && (_jsx("div", { className: "control", children: _jsx(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }) })), _jsx(LookupButton, { isInputButton: true, value: value, validationMessage: validationMessage, lookupButtonConfig: element.lookupButton, overrideRequiredMessage: undefined })] }), isDisplayingValidationMessage && (_jsx(FormElementValidationMessage, { message: validationMessage }))] }) }));
|
|
64
64
|
}
|
|
65
65
|
export default React.memo(FormElementDate);
|
|
66
66
|
//# sourceMappingURL=FormElementDate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElementDate.js","sourceRoot":"","sources":["../../src/form-elements/FormElementDate.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,qBAAqB,MAAM,8CAA8C,CAAA;AAChF,OAAO,YAAY,MAAM,qCAAqC,CAAA;AAE9D,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAElE,OAAO,wBAAwB,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,yBAAyB,MAAM,oCAAoC,CAAA;AAC1E,OAAO,sBAAsB,EAAE,EAC7B,iBAAiB,GAClB,MAAM,kDAAkD,CAAA;AACzD,OAAO,4BAA4B,MAAM,qDAAqD,CAAA;AAY9F,SAAS,eAAe,CAAC,EACvB,EAAE,EACF,OAAO,EACP,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,EACP,UAAU,GACJ;IACN,MAAM,eAAe,GAAG,yBAAyB,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SAAS,GAClC,IACE,EAEL,6BAA6B,IAAI,CAChC,KAAC,4BAA4B,IAAC,OAAO,EAAE,iBAAiB,GAAI,CAC7D,IACyB,GACxB,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { localisationService } from '../apps'\nimport { FormTypes } from '@oneblink/types'\nimport { DatePicker } from '@mui/x-date-pickers'\nimport { format } from 'date-fns'\n\nimport CopyToClipboardButton from '../components/renderer/CopyToClipboardButton'\nimport LookupButton from '../components/renderer/LookupButton'\n\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport { parseDateValue } from '../services/generate-default-data'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport useFormElementDateFromTo from '../hooks/useFormElementDateFromTo'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport useFormDatePickerProps, {\n PickerInputButton,\n} from '../hooks/form-date-picker/useFormDatePickerProps'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype Props = {\n id: string\n element: FormTypes.DateElement\n readOnly: boolean\n value: unknown | undefined\n onChange: FormElementValueChangeHandler<string>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n} & IsDirtyProps\n\nfunction FormElementDate({\n id,\n element,\n readOnly,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n\n const { fromDate, fromDaysOffset, toDate, toDaysOffset } =\n useFormElementDateFromTo(element)\n\n const shortDateFormat = localisationService.getDateFnsFormats().shortDate\n\n const maxDate = React.useMemo(() => {\n return parseDateValue({\n dateOnly: true,\n daysOffset: toDaysOffset,\n value: toDate,\n })\n }, [toDate, toDaysOffset])\n\n const minDate = React.useMemo(() => {\n return parseDateValue({\n dateOnly: true,\n daysOffset: fromDaysOffset,\n value: fromDate,\n })\n }, [fromDate, fromDaysOffset])\n\n const isoValue = React.useMemo(\n () => parseDateValue({ dateOnly: false, daysOffset: 0, value }),\n [value],\n )\n\n const [commonProps, openDatePicker] = useFormDatePickerProps({\n id,\n value: isoValue,\n maxDate,\n minDate,\n ariaDescribedby,\n placeholder: element.placeholderValue,\n className: 'cypress-date-control',\n onBlur: setIsDirty,\n disabled: readOnly,\n required: element.required,\n onChange: (newDate) =>\n onChange(element, {\n value: newDate ? format(newDate, 'yyyy-MM-dd') : undefined,\n }),\n })\n\n const text = React.useMemo(() => {\n if (typeof value === 'string') {\n const date = localisationService.generateDate({\n daysOffset: undefined,\n value,\n })\n if (date) {\n return localisationService.formatDate(date)\n }\n }\n return null\n }, [value])\n\n const { isLookingUp } = React.useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (displayValidationMessage || isDirty) && !!validationMessage && !isLookingUp\n\n return (\n <div className=\"cypress-date-element\">\n <FormElementLabelContainer\n className=\"ob-date\"\n id={id}\n element={element}\n required={element.required}\n >\n <div className=\"field has-addons\">\n <DatePicker\n label={element.label}\n format={shortDateFormat}\n {...commonProps}\n />\n {!readOnly && (\n <PickerInputButton\n tooltip=\"Select date\"\n onClick={openDatePicker}\n icon=\"event\"\n />\n )}\n {!!readOnly && !!text && (\n <div className=\"control\">\n <CopyToClipboardButton\n className=\"button is-input-addon copy-button cypress-copy-to-clipboard-button\"\n text={text}\n />\n </div>\n )}\n <LookupButton\n isInputButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n overrideRequiredMessage={undefined}\n />\n </div>\n\n {isDisplayingValidationMessage && (\n <FormElementValidationMessage message={validationMessage} />\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nexport default React.memo(FormElementDate)\n"]}
|
|
@@ -54,7 +54,7 @@ function FormElementDateTime({ id, element, readOnly, value, onChange, validatio
|
|
|
54
54
|
}, [value]);
|
|
55
55
|
const { isLookingUp } = React.useContext(LookupNotificationContext);
|
|
56
56
|
const isDisplayingValidationMessage = (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp;
|
|
57
|
-
return (_jsx("div", { className: "cypress-datetime-element", children: _jsxs(FormElementLabelContainer, { className: "ob-datetime", id: id, element: element, required: element.required, children: [_jsxs("div", { className: "field has-addons", children: [_jsx(DateTimePicker, { label: element.label, format: shortDateTimeFormat, ...commonProps, timeSteps: { minutes: 1 } }), !readOnly && (_jsx(PickerInputButton, { tooltip: "Select date and time", onClick: openDateTimePicker, icon: "date_range" })), !!readOnly && !!text && (_jsx("div", { className: "control", children: _jsx(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }) })), _jsx(LookupButton, {
|
|
57
|
+
return (_jsx("div", { className: "cypress-datetime-element", children: _jsxs(FormElementLabelContainer, { className: "ob-datetime", id: id, element: element, required: element.required, children: [_jsxs("div", { className: "field has-addons", children: [_jsx(DateTimePicker, { label: element.label, format: shortDateTimeFormat, ...commonProps, timeSteps: { minutes: 1 } }), !readOnly && (_jsx(PickerInputButton, { tooltip: "Select date and time", onClick: openDateTimePicker, icon: "date_range" })), !!readOnly && !!text && (_jsx("div", { className: "control", children: _jsx(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }) })), _jsx(LookupButton, { isInputButton: true, value: value, validationMessage: validationMessage, lookupButtonConfig: element.lookupButton, overrideRequiredMessage: undefined })] }), isDisplayingValidationMessage && (_jsx(FormElementValidationMessage, { message: validationMessage }))] }) }));
|
|
58
58
|
}
|
|
59
59
|
export default React.memo(FormElementDateTime);
|
|
60
60
|
//# sourceMappingURL=FormElementDateTime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElementDateTime.js","sourceRoot":"","sources":["../../src/form-elements/FormElementDateTime.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS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KAAC,qBAAqB,IACpB,SAAS,EAAC,oEAAoE,EAC9E,IAAI,EAAE,IAAI,GACV,GACE,CACP,EACD,KAAC,YAAY,IACX,aAAa,QACb,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAE,iBAAiB,EACpC,kBAAkB,EAAE,OAAO,CAAC,YAAY,EACxC,uBAAuB,EAAE,SAAS,GAClC,IACE,EAEL,6BAA6B,IAAI,CAChC,KAAC,4BAA4B,IAAC,OAAO,EAAE,iBAAiB,GAAI,CAC7D,IACyB,GACxB,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { localisationService } from '../apps'\nimport { FormTypes } from '@oneblink/types'\nimport { DateTimePicker } from '@mui/x-date-pickers'\n\nimport CopyToClipboardButton from '../components/renderer/CopyToClipboardButton'\nimport LookupButton from '../components/renderer/LookupButton'\n\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport { parseDateValue } from '../services/generate-default-data'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport useFormElementDateFromTo from '../hooks/useFormElementDateFromTo'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport useFormDatePickerProps, {\n PickerInputButton,\n} from '../hooks/form-date-picker/useFormDatePickerProps'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype Props = {\n id: string\n element: FormTypes.DateTimeElement\n readOnly: boolean\n value: unknown | undefined\n onChange: FormElementValueChangeHandler<string>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n} & IsDirtyProps\n\nfunction FormElementDateTime({\n id,\n element,\n readOnly,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n\n const { fromDate, fromDaysOffset, toDate, toDaysOffset } =\n useFormElementDateFromTo(element)\n\n const shortDateTimeFormat =\n localisationService.getDateFnsFormats().shortDateTime\n\n const maxDate = React.useMemo(() => {\n return parseDateValue({\n dateOnly: true,\n daysOffset: toDaysOffset,\n value: toDate,\n })\n }, [toDate, toDaysOffset])\n\n const minDate = React.useMemo(() => {\n return parseDateValue({\n dateOnly: true,\n daysOffset: fromDaysOffset,\n value: fromDate,\n })\n }, [fromDate, fromDaysOffset])\n\n const [commonProps, openDateTimePicker] = useFormDatePickerProps({\n id,\n value: typeof value === 'string' ? value : undefined,\n maxDate,\n minDate,\n ariaDescribedby,\n placeholder: element.placeholderValue,\n className: 'cypress-date-time-control',\n disabled: readOnly,\n required: element.required,\n onBlur: setIsDirty,\n onChange: (newDate) => {\n onChange(element, {\n value: newDate?.toISOString(),\n })\n },\n })\n\n const text = React.useMemo(() => {\n if (typeof value !== 'string') {\n return null\n }\n return localisationService.formatDatetime(new Date(value))\n }, [value])\n\n const { isLookingUp } = React.useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp\n\n return (\n <div className=\"cypress-datetime-element\">\n <FormElementLabelContainer\n className=\"ob-datetime\"\n id={id}\n element={element}\n required={element.required}\n >\n <div className=\"field has-addons\">\n <DateTimePicker\n label={element.label}\n format={shortDateTimeFormat}\n {...commonProps}\n timeSteps={{ minutes: 1 }}\n />\n {!readOnly && (\n <PickerInputButton\n tooltip=\"Select date and time\"\n onClick={openDateTimePicker}\n icon=\"date_range\"\n />\n )}\n {!!readOnly && !!text && (\n <div className=\"control\">\n <CopyToClipboardButton\n className=\"button is-input-addon copy-button cypress-copy-to-clipboard-button\"\n text={text}\n />\n </div>\n )}\n <LookupButton\n isInputButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n overrideRequiredMessage={undefined}\n />\n </div>\n\n {isDisplayingValidationMessage && (\n <FormElementValidationMessage message={validationMessage} />\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nexport default React.memo(FormElementDateTime)\n"]}
|
|
@@ -14,7 +14,7 @@ function FormElementEmail({ id, element, readOnly, value, onChange, validationMe
|
|
|
14
14
|
const text = typeof value === 'string' ? value : '';
|
|
15
15
|
return (_jsx("div", { className: "cypress-email-element", children: _jsxs(FormElementLabelContainer, { className: "ob-email", id: id, element: element, required: element.required, children: [_jsxs("div", { className: "field has-addons", children: [_jsxs("div", { className: "control is-expanded has-icons-right", children: [_jsx("input", { type: "email", placeholder: element.placeholderValue, id: id, name: element.name, className: "input ob-input cypress-email-control", value: text, onChange: (e) => onChange(element, {
|
|
16
16
|
value: e.target.value || undefined,
|
|
17
|
-
}), required: element.required, disabled: readOnly, onBlur: setIsDirty, "aria-describedby": ariaDescribedby, autoComplete: autocompleteAttributes, "aria-required": element.required }), _jsx("span", { className: "ob-input-icon icon is-small is-right", children: _jsx(MaterialIcon, { className: "is-size-5", children: "email" }) })] }), !!readOnly && !!value && (_jsx("div", { className: "control", children: _jsx(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }) })), _jsx(LookupButton, {
|
|
17
|
+
}), required: element.required, disabled: readOnly, onBlur: setIsDirty, "aria-describedby": ariaDescribedby, autoComplete: autocompleteAttributes, "aria-required": element.required }), _jsx("span", { className: "ob-input-icon icon is-small is-right", children: _jsx(MaterialIcon, { className: "is-size-5", children: "email" }) })] }), !!readOnly && !!value && (_jsx("div", { className: "control", children: _jsx(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }) })), _jsx(LookupButton, { isInputButton: true, value: value, validationMessage: validationMessage, lookupButtonConfig: element.lookupButton, overrideRequiredMessage: undefined })] }), isDisplayingValidationMessage && (_jsx(FormElementValidationMessage, { message: validationMessage }))] }) }));
|
|
18
18
|
}
|
|
19
19
|
export default React.memo(FormElementEmail);
|
|
20
20
|
//# sourceMappingURL=FormElementEmail.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElement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B,GACnD,IACH,EACL,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CACxB,cAAK,SAAS,EAAC,SAAS,YACtB,KAAC,qBAAqB,IACpB,SAAS,EAAC,oEAAoE,EAC9E,IAAI,EAAE,IAAI,GACV,GACE,CACP,EACD,KAAC,YAAY,IACX,aAAa,QACb,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAE,iBAAiB,EACpC,kBAAkB,EAAE,OAAO,CAAC,YAAY,EACxC,uBAAuB,EAAE,SAAS,GAClC,IACE,EAEL,6BAA6B,IAAI,CAChC,KAAC,4BAA4B,IAAC,OAAO,EAAE,iBAAiB,GAAI,CAC7D,IACyB,GACxB,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\n\nimport CopyToClipboardButton from '../components/renderer/CopyToClipboardButton'\nimport LookupButton from '../components/renderer/LookupButton'\nimport { FormTypes } from '@oneblink/types'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport MaterialIcon from '../components/MaterialIcon'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype Props = {\n id: string\n element: FormTypes.EmailElement\n readOnly: boolean\n value: unknown\n onChange: FormElementValueChangeHandler<string>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n autocompleteAttributes?: string\n} & IsDirtyProps\n\nfunction FormElementEmail({\n id,\n element,\n readOnly,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n autocompleteAttributes,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const { isLookingUp } = React.useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp\n\n const text = typeof value === 'string' ? value : ''\n return (\n <div className=\"cypress-email-element\">\n <FormElementLabelContainer\n className=\"ob-email\"\n id={id}\n element={element}\n required={element.required}\n >\n <div className=\"field has-addons\">\n <div className=\"control is-expanded has-icons-right\">\n <input\n type=\"email\"\n placeholder={element.placeholderValue}\n id={id}\n name={element.name}\n className=\"input ob-input cypress-email-control\"\n value={text}\n onChange={(e) =>\n onChange(element, {\n value: e.target.value || undefined,\n })\n }\n required={element.required}\n disabled={readOnly}\n onBlur={setIsDirty}\n aria-describedby={ariaDescribedby}\n autoComplete={autocompleteAttributes}\n aria-required={element.required}\n />\n <span className=\"ob-input-icon icon is-small is-right\">\n <MaterialIcon className=\"is-size-5\">email</MaterialIcon>\n </span>\n </div>\n {!!readOnly && !!value && (\n <div className=\"control\">\n <CopyToClipboardButton\n className=\"button is-input-addon copy-button cypress-copy-to-clipboard-button\"\n text={text}\n />\n </div>\n )}\n <LookupButton\n isInputButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n overrideRequiredMessage={undefined}\n />\n </div>\n\n {isDisplayingValidationMessage && (\n <FormElementValidationMessage message={validationMessage} />\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nexport default React.memo(FormElementEmail)\n"]}
|
|
@@ -6,23 +6,22 @@ export type Props = {
|
|
|
6
6
|
id: string;
|
|
7
7
|
element: FormTypes.FormFormElement;
|
|
8
8
|
/**
|
|
9
|
-
* Whether this nested form is locked
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Whether this nested form is locked. Used as `readOnlyOverride` for
|
|
10
|
+
* synthetic children when `readOnlyOverrideChildren` is set. Nested fields do
|
|
11
|
+
* not inherit this value as a blanket lock so a child included in
|
|
12
|
+
* `editableFormElementIds` can stay editable.
|
|
13
13
|
*/
|
|
14
14
|
readOnly: boolean;
|
|
15
15
|
/**
|
|
16
16
|
* Lock to apply to nested fields (`OneBlinkFormElements.readOnly` /
|
|
17
17
|
* `parentReadOnly`). True when the whole form is read-only, a parent is
|
|
18
|
-
* read-only, or this element’s definition has `readOnly: true`.
|
|
19
|
-
* include this nested form’s audience lock.
|
|
18
|
+
* read-only, or this element’s definition has `readOnly: true`.
|
|
20
19
|
*/
|
|
21
20
|
childrenReadOnly: boolean;
|
|
22
21
|
/**
|
|
23
|
-
* When true, nested fields use this element’s `readOnly`
|
|
24
|
-
*
|
|
25
|
-
*
|
|
22
|
+
* When true, nested fields use this element’s `readOnly` as
|
|
23
|
+
* `readOnlyOverride` instead of calculating their own. Used by Civica name
|
|
24
|
+
* records and Freshdesk dependent fields.
|
|
26
25
|
*/
|
|
27
26
|
readOnlyOverrideChildren?: boolean;
|
|
28
27
|
value: SubmissionTypes.S3SubmissionData['submission'] | undefined;
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import OneBlinkFormElements from '../components/renderer/OneBlinkFormElements';
|
|
4
4
|
import ElementDOMId from '../utils/elementDOMIds';
|
|
5
5
|
function FormElementForm({ formId, element, readOnly, childrenReadOnly, readOnlyOverrideChildren, value, id, formElementValidation, displayValidationMessages, formElementConditionallyShown, onChange, onLookup, onUpdateFormElements, sectionState, }) {
|
|
6
|
-
const handleNestedChange = React.useCallback((nestedElement, { value: nestedElementValue, executedLookups: nestedExecutedLookups, sectionState, }, idPrefix) => {
|
|
6
|
+
const handleNestedChange = React.useCallback((nestedElement, { value: nestedElementValue, executedLookups: nestedExecutedLookups, sectionState, isDerivedChange, }, idPrefix) => {
|
|
7
7
|
if (nestedElement.type === 'section') {
|
|
8
8
|
// trigger onChange to update sectionState
|
|
9
9
|
onChange({
|
|
@@ -33,9 +33,10 @@ function FormElementForm({ formId, element, readOnly, childrenReadOnly, readOnly
|
|
|
33
33
|
};
|
|
34
34
|
},
|
|
35
35
|
sectionState,
|
|
36
|
+
isDerivedChange,
|
|
36
37
|
});
|
|
37
38
|
}, [element, onChange]);
|
|
38
|
-
const handleLookup = React.useCallback((mergeLookupResults) => {
|
|
39
|
+
const handleLookup = React.useCallback((mergeLookupResults, options) => {
|
|
39
40
|
onLookup((currentFormSubmission) => {
|
|
40
41
|
var _a;
|
|
41
42
|
let model = currentFormSubmission.submission[element.name];
|
|
@@ -74,7 +75,7 @@ function FormElementForm({ formId, element, readOnly, childrenReadOnly, readOnly
|
|
|
74
75
|
},
|
|
75
76
|
sectionState: currentFormSubmission.sectionState,
|
|
76
77
|
};
|
|
77
|
-
});
|
|
78
|
+
}, options);
|
|
78
79
|
}, [element.name, onLookup]);
|
|
79
80
|
const validation = React.useMemo(() => {
|
|
80
81
|
return !!formElementValidation &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElementForm.js","sourceRoot":"","sources":["../../src/form-elements/FormElementForm.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAU9E,OAAO,YAAY,MAAM,wBAAwB,CAAA;AAsCjD,SAAS,eAAe,CAAC,EACvB,MAAM,EACN,OAAO,EACP,QAAQ,EACR,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,EACL,EAAE,EACF,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,YAAY,GACN;IACN,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAC1C,CACE,aAAoC,EACpC,EACE,KAAK,EAAE,kBAAkB,EACzB,eAAe,EAAE,qBAAqB,EACtC,YAAY,GACuC,EACrD,QAAiB,EACjB,EAAE;QACF,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACrC,0CAA0C;YAC1C,QAAQ,CACN;gBACE,GAAG,aAAa;gBAChB,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE;a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AC;gBACD,OAAO,WAAW,CAAA;YACpB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,EACD,CAAC,OAAO,CAAC,EAAE,EAAE,oBAAoB,CAAC,CACnC,CAAA;IAEH,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAEpE,OAAO,CACL,KAAC,oBAAoB,IACnB,MAAM,EAAE,MAAM,EACd,sBAAsB,EAAE,UAAU,EAClC,yBAAyB,EAAE,yBAAyB,EACpD,QAAQ,EAAE,aAAa,CAAC,QAAQ,EAChC,QAAQ,EAAE,kBAAkB,EAC5B,QAAQ,EAAE,YAAY,EACtB,8BAA8B,EAAE,8BAA8B,EAC9D,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,gBAAgB,EAC1B,gBAAgB,EAAE,wBAAwB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EACjE,QAAQ,EAAE,YAAY,CAAC,kBAAkB,EACzC,oBAAoB,EAAE,8BAA8B,EACpD,YAAY,EAAE,YAAY,GAC1B,CACH,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport OneBlinkFormElements from '../components/renderer/OneBlinkFormElements'\nimport {\n ExecutedLookups,\n FormElementConditionallyShown,\n FormElementLookupHandler,\n FormElementValidation,\n NestedFormElementValueChangeHandler,\n SectionState,\n UpdateFormElementsHandler,\n} from '../types/form'\nimport ElementDOMId from '../utils/elementDOMIds'\n\nexport type Props = {\n formId: number\n id: string\n element: FormTypes.FormFormElement\n /**\n * Whether this nested form is locked for the current audience or inherited\n * read-only state. Used as `readOnlyOverride` for synthetic children when\n * `readOnlyOverrideChildren` is set. Nested fields do not inherit this\n * value as a blanket lock so an `ALL_STEPS` child can stay editable.\n */\n readOnly: boolean\n /**\n * Lock to apply to nested fields (`OneBlinkFormElements.readOnly` /\n * `parentReadOnly`). True when the whole form is read-only, a parent is\n * read-only, or this element’s definition has `readOnly: true`. Does not\n * include this nested form’s audience lock.\n */\n childrenReadOnly: boolean\n /**\n * When true, nested fields use this element’s `readOnly` (including\n * audience lock) as `readOnlyOverride` instead of calculating their own.\n * Used by Civica name records and Freshdesk dependent fields.\n */\n readOnlyOverrideChildren?: boolean\n value: SubmissionTypes.S3SubmissionData['submission'] | undefined\n onChange: NestedFormElementValueChangeHandler<\n SubmissionTypes.S3SubmissionData['submission']\n >\n onLookup: FormElementLookupHandler\n formElementValidation: FormElementValidation | undefined\n displayValidationMessages: boolean\n formElementConditionallyShown: FormElementConditionallyShown | undefined\n onUpdateFormElements: UpdateFormElementsHandler\n sectionState: SectionState\n}\n\nfunction FormElementForm({\n formId,\n element,\n readOnly,\n childrenReadOnly,\n readOnlyOverrideChildren,\n value,\n id,\n formElementValidation,\n displayValidationMessages,\n formElementConditionallyShown,\n onChange,\n onLookup,\n onUpdateFormElements,\n sectionState,\n}: Props) {\n const handleNestedChange = React.useCallback(\n (\n nestedElement: FormTypes.FormElement,\n {\n value: nestedElementValue,\n executedLookups: nestedExecutedLookups,\n sectionState,\n }: Parameters<NestedFormElementValueChangeHandler>[1],\n idPrefix?: string,\n ) => {\n if (nestedElement.type === 'section') {\n // trigger onChange to update sectionState\n onChange(\n {\n ...nestedElement,\n id: idPrefix ? `${idPrefix}${nestedElement.id}` : nestedElement.id,\n },\n { executedLookups: undefined, sectionState },\n )\n }\n if (!('name' in nestedElement)) return\n onChange(element, {\n value: (existingValue) => ({\n ...existingValue,\n [nestedElement.name]:\n typeof nestedElementValue === 'function'\n ? nestedElementValue(\n existingValue ? existingValue[nestedElement.name] : undefined,\n )\n : nestedElementValue,\n }),\n executedLookups: (existingExecutedLookups) => {\n if (\n typeof existingExecutedLookups === 'boolean' ||\n Array.isArray(existingExecutedLookups)\n ) {\n return {}\n }\n return {\n ...existingExecutedLookups,\n [nestedElement.name]:\n typeof nestedExecutedLookups === 'function'\n ? nestedExecutedLookups(\n existingExecutedLookups?.[\n nestedElement.name\n ] as ExecutedLookups,\n )\n : nestedExecutedLookups,\n }\n },\n sectionState,\n })\n },\n [element, onChange],\n )\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults) => {\n onLookup((currentFormSubmission) => {\n let model = currentFormSubmission.submission[\n element.name\n ] as SubmissionTypes.S3SubmissionData['submission']\n let newExecutedLookups = currentFormSubmission.executedLookups?.[\n element.name\n ] as ExecutedLookups\n\n const elements = currentFormSubmission.elements.map((formElement) => {\n if (\n formElement.type === 'form' &&\n formElement.name === element.name &&\n Array.isArray(formElement.elements)\n ) {\n const { elements, submission, executedLookups } =\n mergeLookupResults({\n elements: formElement.elements,\n submission: model,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: newExecutedLookups,\n sectionState: currentFormSubmission.sectionState,\n })\n model = submission\n newExecutedLookups = executedLookups as ExecutedLookups\n return {\n ...formElement,\n elements,\n }\n }\n return formElement\n })\n\n const submission = {\n ...currentFormSubmission.submission,\n [element.name]: model,\n }\n\n return {\n elements,\n submission,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: {\n ...currentFormSubmission.executedLookups,\n [element.name]: newExecutedLookups,\n },\n sectionState: currentFormSubmission.sectionState,\n }\n })\n },\n [element.name, onLookup],\n )\n\n const validation = React.useMemo(() => {\n return !!formElementValidation &&\n typeof formElementValidation !== 'string' &&\n formElementValidation.type === 'formElements'\n ? formElementValidation.formElements\n : undefined\n }, [formElementValidation])\n\n const formElementsConditionallyShown = React.useMemo(() => {\n return formElementConditionallyShown &&\n formElementConditionallyShown.type === 'formElements'\n ? formElementConditionallyShown.formElements\n : undefined\n }, [formElementConditionallyShown])\n\n const parentElement = React.useMemo(\n () => ({\n elements: Array.isArray(element.elements) ? element.elements : [],\n }),\n [element.elements],\n )\n\n const handleUpdateNestedFormElements =\n React.useCallback<UpdateFormElementsHandler>(\n (setter) => {\n onUpdateFormElements((formElements) => {\n return formElements.map((formElement) => {\n if (\n formElement.id === element.id &&\n formElement.type === 'form' &&\n Array.isArray(formElement.elements)\n ) {\n return {\n ...formElement,\n elements: setter(formElement.elements),\n }\n }\n return formElement\n })\n })\n },\n [element.id, onUpdateFormElements],\n )\n\n const elementDOMId = React.useMemo(() => new ElementDOMId(id), [id])\n\n return (\n <OneBlinkFormElements\n formId={formId}\n formElementsValidation={validation}\n displayValidationMessages={displayValidationMessages}\n elements={parentElement.elements}\n onChange={handleNestedChange}\n onLookup={handleLookup}\n formElementsConditionallyShown={formElementsConditionallyShown}\n model={value || {}}\n parentElement={parentElement}\n readOnly={childrenReadOnly}\n readOnlyOverride={readOnlyOverrideChildren ? readOnly : undefined}\n idPrefix={elementDOMId.subFormDOMIdPrefix}\n onUpdateFormElements={handleUpdateNestedFormElements}\n sectionState={sectionState}\n />\n )\n}\n\nexport default React.memo(FormElementForm)\n"]}
|
|
1
|
+
{"version":3,"file":"FormElementForm.js","sourceRoot":"","sources":["../../src/form-elements/FormElementForm.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAU9E,OAAO,YAAY,MAAM,wBAAwB,CAAA;AAqCjD,SAAS,eAAe,CAAC,EACvB,MAAM,EACN,OAAO,EACP,QAAQ,EACR,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,EACL,EAAE,EACF,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,YAAY,GACN;IACN,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAC1C,CACE,aAAoC,EACpC,EACE,KAAK,EAAE,kBAAkB,EACzB,eAAe,EAAE,qBAAqB,E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'react'\nimport OneBlinkFormElements from '../components/renderer/OneBlinkFormElements'\nimport {\n ExecutedLookups,\n FormElementConditionallyShown,\n FormElementLookupHandler,\n FormElementValidation,\n NestedFormElementValueChangeHandler,\n SectionState,\n UpdateFormElementsHandler,\n} from '../types/form'\nimport ElementDOMId from '../utils/elementDOMIds'\n\nexport type Props = {\n formId: number\n id: string\n element: FormTypes.FormFormElement\n /**\n * Whether this nested form is locked. Used as `readOnlyOverride` for\n * synthetic children when `readOnlyOverrideChildren` is set. Nested fields do\n * not inherit this value as a blanket lock so a child included in\n * `editableFormElementIds` can stay editable.\n */\n readOnly: boolean\n /**\n * Lock to apply to nested fields (`OneBlinkFormElements.readOnly` /\n * `parentReadOnly`). True when the whole form is read-only, a parent is\n * read-only, or this element’s definition has `readOnly: true`.\n */\n childrenReadOnly: boolean\n /**\n * When true, nested fields use this element’s `readOnly` as\n * `readOnlyOverride` instead of calculating their own. Used by Civica name\n * records and Freshdesk dependent fields.\n */\n readOnlyOverrideChildren?: boolean\n value: SubmissionTypes.S3SubmissionData['submission'] | undefined\n onChange: NestedFormElementValueChangeHandler<\n SubmissionTypes.S3SubmissionData['submission']\n >\n onLookup: FormElementLookupHandler\n formElementValidation: FormElementValidation | undefined\n displayValidationMessages: boolean\n formElementConditionallyShown: FormElementConditionallyShown | undefined\n onUpdateFormElements: UpdateFormElementsHandler\n sectionState: SectionState\n}\n\nfunction FormElementForm({\n formId,\n element,\n readOnly,\n childrenReadOnly,\n readOnlyOverrideChildren,\n value,\n id,\n formElementValidation,\n displayValidationMessages,\n formElementConditionallyShown,\n onChange,\n onLookup,\n onUpdateFormElements,\n sectionState,\n}: Props) {\n const handleNestedChange = React.useCallback(\n (\n nestedElement: FormTypes.FormElement,\n {\n value: nestedElementValue,\n executedLookups: nestedExecutedLookups,\n sectionState,\n isDerivedChange,\n }: Parameters<NestedFormElementValueChangeHandler>[1],\n idPrefix?: string,\n ) => {\n if (nestedElement.type === 'section') {\n // trigger onChange to update sectionState\n onChange(\n {\n ...nestedElement,\n id: idPrefix ? `${idPrefix}${nestedElement.id}` : nestedElement.id,\n },\n { executedLookups: undefined, sectionState },\n )\n }\n if (!('name' in nestedElement)) return\n onChange(element, {\n value: (existingValue) => ({\n ...existingValue,\n [nestedElement.name]:\n typeof nestedElementValue === 'function'\n ? nestedElementValue(\n existingValue ? existingValue[nestedElement.name] : undefined,\n )\n : nestedElementValue,\n }),\n executedLookups: (existingExecutedLookups) => {\n if (\n typeof existingExecutedLookups === 'boolean' ||\n Array.isArray(existingExecutedLookups)\n ) {\n return {}\n }\n return {\n ...existingExecutedLookups,\n [nestedElement.name]:\n typeof nestedExecutedLookups === 'function'\n ? nestedExecutedLookups(\n existingExecutedLookups?.[\n nestedElement.name\n ] as ExecutedLookups,\n )\n : nestedExecutedLookups,\n }\n },\n sectionState,\n isDerivedChange,\n })\n },\n [element, onChange],\n )\n\n const handleLookup = React.useCallback<FormElementLookupHandler>(\n (mergeLookupResults, options) => {\n onLookup((currentFormSubmission) => {\n let model = currentFormSubmission.submission[\n element.name\n ] as SubmissionTypes.S3SubmissionData['submission']\n let newExecutedLookups = currentFormSubmission.executedLookups?.[\n element.name\n ] as ExecutedLookups\n\n const elements = currentFormSubmission.elements.map((formElement) => {\n if (\n formElement.type === 'form' &&\n formElement.name === element.name &&\n Array.isArray(formElement.elements)\n ) {\n const { elements, submission, executedLookups } =\n mergeLookupResults({\n elements: formElement.elements,\n submission: model,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: newExecutedLookups,\n sectionState: currentFormSubmission.sectionState,\n })\n model = submission\n newExecutedLookups = executedLookups as ExecutedLookups\n return {\n ...formElement,\n elements,\n }\n }\n return formElement\n })\n\n const submission = {\n ...currentFormSubmission.submission,\n [element.name]: model,\n }\n\n return {\n elements,\n submission,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n executedLookups: {\n ...currentFormSubmission.executedLookups,\n [element.name]: newExecutedLookups,\n },\n sectionState: currentFormSubmission.sectionState,\n }\n }, options)\n },\n [element.name, onLookup],\n )\n\n const validation = React.useMemo(() => {\n return !!formElementValidation &&\n typeof formElementValidation !== 'string' &&\n formElementValidation.type === 'formElements'\n ? formElementValidation.formElements\n : undefined\n }, [formElementValidation])\n\n const formElementsConditionallyShown = React.useMemo(() => {\n return formElementConditionallyShown &&\n formElementConditionallyShown.type === 'formElements'\n ? formElementConditionallyShown.formElements\n : undefined\n }, [formElementConditionallyShown])\n\n const parentElement = React.useMemo(\n () => ({\n elements: Array.isArray(element.elements) ? element.elements : [],\n }),\n [element.elements],\n )\n\n const handleUpdateNestedFormElements =\n React.useCallback<UpdateFormElementsHandler>(\n (setter) => {\n onUpdateFormElements((formElements) => {\n return formElements.map((formElement) => {\n if (\n formElement.id === element.id &&\n formElement.type === 'form' &&\n Array.isArray(formElement.elements)\n ) {\n return {\n ...formElement,\n elements: setter(formElement.elements),\n }\n }\n return formElement\n })\n })\n },\n [element.id, onUpdateFormElements],\n )\n\n const elementDOMId = React.useMemo(() => new ElementDOMId(id), [id])\n\n return (\n <OneBlinkFormElements\n formId={formId}\n formElementsValidation={validation}\n displayValidationMessages={displayValidationMessages}\n elements={parentElement.elements}\n onChange={handleNestedChange}\n onLookup={handleLookup}\n formElementsConditionallyShown={formElementsConditionallyShown}\n model={value || {}}\n parentElement={parentElement}\n readOnly={childrenReadOnly}\n readOnlyOverride={readOnlyOverrideChildren ? readOnly : undefined}\n idPrefix={elementDOMId.subFormDOMIdPrefix}\n onUpdateFormElements={handleUpdateNestedFormElements}\n sectionState={sectionState}\n />\n )\n}\n\nexport default React.memo(FormElementForm)\n"]}
|
|
@@ -25,12 +25,12 @@ function FormElementLookupButton({ id, element, readOnly, onChange, onLookup, va
|
|
|
25
25
|
const { isAutoLookup, data } = useMemo(() => {
|
|
26
26
|
return generateLookupButtonValue(element.elementDependencies, elements, formSubmissionModel);
|
|
27
27
|
}, [element.elementDependencies, elements, formSubmissionModel]);
|
|
28
|
-
const handleLookup = useCallback((setter) => {
|
|
28
|
+
const handleLookup = useCallback((setter, options) => {
|
|
29
29
|
onLookup((data) => {
|
|
30
30
|
const dataAfterSetting = setter(data);
|
|
31
31
|
dataAfterSetting.submission[element.name] = true;
|
|
32
32
|
return dataAfterSetting;
|
|
33
|
-
});
|
|
33
|
+
}, options);
|
|
34
34
|
}, [element.name, onLookup]);
|
|
35
35
|
const stringifyData = useMemo(() => {
|
|
36
36
|
if (!data) {
|
|
@@ -44,6 +44,7 @@ function FormElementLookupButton({ id, element, readOnly, onChange, onLookup, va
|
|
|
44
44
|
}
|
|
45
45
|
onChange(element, {
|
|
46
46
|
value: false,
|
|
47
|
+
isDerivedChange: true,
|
|
47
48
|
});
|
|
48
49
|
}, [element, onChange, readOnly, stringifyData]);
|
|
49
50
|
const value = useMemo(() => {
|
|
@@ -54,7 +55,7 @@ function FormElementLookupButton({ id, element, readOnly, onChange, onLookup, va
|
|
|
54
55
|
}
|
|
55
56
|
return undefined;
|
|
56
57
|
}, [data, element.elementDependencies.length]);
|
|
57
|
-
return (_jsx(LookupNotification, { autoLookupValue: isAutoLookup ? stringifyData : undefined, element: element, onLookup: handleLookup, stringifyAutoLookupValue: stringifyLookupButtonValue, children: _jsx("div", { className: "cypress-lookup-button-element", children: _jsxs(FormElementLabelContainer, { className: "ob-lookup-button", id: id, element: element, required: false, children: [_jsx(LookupButton, {
|
|
58
|
+
return (_jsx(LookupNotification, { autoLookupValue: isAutoLookup ? stringifyData : undefined, element: element, onLookup: handleLookup, stringifyAutoLookupValue: stringifyLookupButtonValue, children: _jsx("div", { className: "cypress-lookup-button-element", children: _jsxs(FormElementLabelContainer, { className: "ob-lookup-button", id: id, element: element, required: false, children: [_jsx(LookupButton, { value: value, validationMessage: validationMessage, lookupButtonConfig: element.lookupButton, overrideRequiredMessage: element.requiredMessage }), _jsx(FormElementLookupButtonValidationMessage, { validationMessage: validationMessage, ...validationMessageProps })] }) }) }));
|
|
58
59
|
}
|
|
59
60
|
export default memo(FormElementLookupButton);
|
|
60
61
|
function generateLookupButtonValue(elementDependencies, elements, formSubmissionModel) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElementLookupButton.js","sourceRoot":"","sources":["../../src/form-elements/FormElementLookupButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACzE,OAAO,YAAY,MAAM,qCAAqC,CAAA;AAE9D,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AAMxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,kBAAkB,MAAM,2CAA2C,CAAA;AAC1E,OAAO,sBAAsB,MAAM,wCAAwC,CAAA;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,4BAA4B,MAAM,qDAAqD,CAAA;AAa9F,SAAS,0BAA0B,CAAC,CAAU;IAC5C,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAW,CAAA;AACpC,CAAC;AAED,MAAM,wCAAwC,GAAG,IAAI,CACnD,SAAS,iDAAiD,CAAC,EACzD,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,GACgB;IACvB,MAAM,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC,yBAAyB,CAAC,CAAA;IAC7D,MAAM,6BAA6B,GACjC,CAAC,OAAO,IAAI,wBAAwB,CAAC;QACrC,CAAC,CAAC,iBAAiB;QACnB,CAAC,WAAW,CAAA;IAEd,IAAI,CAAC,6BAA6B,EAAE,CAAC;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,KAAC,4BAA4B,IAAC,OAAO,EAAE,iBAAiB,GAAI,CAAA;AACrE,CAAC,CACF,CAAA;AAED,SAAS,uBAAuB,CAAC,EAC/B,EAAE,EACF,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,iBAAiB,EACjB,GAAG,sBAAs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,SAAS,EAAE,KAAK;IAChB,cAAc,EAAE,KAAK;IACrB,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,KAAK;IACjB,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK;IAC5E,YAAY,EAAE,IAAI;IAClB,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,KAAK;IACX,QAAQ,EAAE,KAAK;IACf,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,KAAK;IACb,aAAa,EAAE,KAAK;IACpB,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,KAAK;IAClB,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,IAAI;IACrB,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,KAAK;IACpB,gBAAgB,EAAE,IAAI;IACtB,gBAAgB,EAAE,KAAK;IACvB,OAAO,EAAE,KAAK;IACd,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,uBAAuB,EAAE,KAAK;IAC9B,mBAAmB,EAAE,IAAI;IACzB,YAAY,EAAE,IAAI;IAClB,oBAAoB,EAAE,IAAI;IAC1B,YAAY,EAAE,KAAK;CACpB,CAAA","sourcesContent":["import { memo, useCallback, useContext, useEffect, useMemo } from 'react'\nimport LookupButton from '../components/renderer/LookupButton'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport {\n FormElementLookupHandler,\n FormElementValueChangeHandler,\n IsDirtyProps,\n} from '../types/form'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport LookupNotification from '../components/renderer/LookupNotification'\nimport useFormSubmissionModel from '../hooks/useFormSubmissionModelContext'\nimport { formElementsService } from '@oneblink/sdk-core'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype ValidationMessageProps = {\n displayValidationMessage: boolean\n validationMessage: string | undefined\n} & IsDirtyProps\n\ntype Props = {\n id: string\n element: FormTypes.LookupButtonFormElement\n readOnly: boolean\n} & ValidationMessageProps\n\nfunction stringifyLookupButtonValue(v: unknown): string {\n return JSON.stringify(v) as string\n}\n\nconst FormElementLookupButtonValidationMessage = memo(\n function FormElementLookupButtonValidationMessageComponent({\n validationMessage,\n displayValidationMessage,\n isDirty,\n }: ValidationMessageProps) {\n const { isLookingUp } = useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (isDirty || displayValidationMessage) &&\n !!validationMessage &&\n !isLookingUp\n\n if (!isDisplayingValidationMessage) {\n return null\n }\n\n return <FormElementValidationMessage message={validationMessage} />\n },\n)\n\nfunction FormElementLookupButton({\n id,\n element,\n readOnly,\n onChange,\n onLookup,\n validationMessage,\n ...validationMessageProps\n}: Props & {\n onChange: FormElementValueChangeHandler\n onLookup: FormElementLookupHandler\n}) {\n const { formSubmissionModel, elements } = useFormSubmissionModel()\n const { isAutoLookup, data } = useMemo(() => {\n return generateLookupButtonValue(\n element.elementDependencies,\n elements,\n formSubmissionModel,\n )\n }, [element.elementDependencies, elements, formSubmissionModel])\n\n const handleLookup = useCallback<FormElementLookupHandler>(\n (setter) => {\n onLookup((data) => {\n const dataAfterSetting = setter(data)\n dataAfterSetting.submission[element.name] = true\n return dataAfterSetting\n })\n },\n [element.name, onLookup],\n )\n\n const stringifyData = useMemo(() => {\n if (!data) {\n return undefined\n }\n return stringifyLookupButtonValue(data)\n }, [data])\n\n useEffect(() => {\n if (readOnly) {\n return\n }\n onChange(element, {\n value: false,\n })\n }, [element, onChange, readOnly, stringifyData])\n\n const value = useMemo(() => {\n // Want the value to be `true` if there is data or if there are\n // no element dependencies i.e. the lookup can be run at any time.\n if (!element.elementDependencies.length || data) {\n return true\n }\n return undefined\n }, [data, element.elementDependencies.length])\n\n return (\n <LookupNotification\n autoLookupValue={isAutoLookup ? stringifyData : undefined}\n element={element}\n onLookup={handleLookup}\n stringifyAutoLookupValue={stringifyLookupButtonValue}\n >\n <div className=\"cypress-lookup-button-element\">\n <FormElementLabelContainer\n className=\"ob-lookup-button\"\n id={id}\n element={element}\n required={false}\n >\n <LookupButton\n readOnly={readOnly}\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n overrideRequiredMessage={element.requiredMessage}\n />\n <FormElementLookupButtonValidationMessage\n validationMessage={validationMessage}\n {...validationMessageProps}\n />\n </FormElementLabelContainer>\n </div>\n </LookupNotification>\n )\n}\n\nexport default memo(FormElementLookupButton)\n\nfunction generateLookupButtonValue(\n elementDependencies: FormTypes.LookupButtonFormElement['elementDependencies'],\n elements: FormTypes.FormElement[],\n formSubmissionModel:\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined,\n): {\n isAutoLookup: boolean\n data: SubmissionTypes.S3SubmissionData['submission'] | undefined\n} {\n if (!formSubmissionModel) {\n return {\n isAutoLookup: false,\n data: undefined,\n }\n }\n\n // \"data\" should be `undefined` if there are no dependent elements with a value.\n // If a least one dependent element has a value, we will enable to lookup to run.\n return elementDependencies.reduce<{\n isAutoLookup: boolean\n data: SubmissionTypes.S3SubmissionData['submission'] | undefined\n }>(\n (memo, elementDependency) => {\n const formElement = formElementsService.findFormElement(\n elements,\n (formElement) => formElement.id === elementDependency.elementId,\n )\n if (!formElement || !('name' in formElement)) {\n return memo\n }\n\n const formElementValue = formSubmissionModel[formElement.name]\n\n switch (elementDependency.type) {\n case 'FORM_FORM_ELEMENT': {\n if (\n formElement.type === 'form' &&\n Array.isArray(formElement.elements)\n ) {\n const nestedLookupButtonValue = generateLookupButtonValue(\n [elementDependency.elementDependency],\n formElement.elements,\n formElementValue as SubmissionTypes.S3SubmissionData['submission'],\n )\n return {\n isAutoLookup:\n memo.isAutoLookup && nestedLookupButtonValue.isAutoLookup,\n data:\n nestedLookupButtonValue.data !== undefined\n ? {\n ...memo.data,\n [formElement.name]: {\n ...(memo?.data?.[formElement.name] || {}),\n ...nestedLookupButtonValue.data,\n },\n }\n : memo.data,\n }\n }\n break\n }\n case 'REPEATABLE_SET_FORM_ELEMENT': {\n if (formElement.type === 'repeatableSet') {\n const entries: {\n isAutoLookup: boolean\n data: Record<\n number,\n SubmissionTypes.S3SubmissionData['submission'] | undefined\n >\n } = {\n isAutoLookup: memo.isAutoLookup,\n data: {},\n }\n let hasAnEntry = false\n const existingEntries =\n (memo.data?.[formElement.name] as object[]) || undefined\n if (Array.isArray(formElementValue)) {\n for (const entry of formElementValue) {\n const index = formElementValue.indexOf(entry)\n const nestedLookupButtonValue = generateLookupButtonValue(\n [elementDependency.elementDependency],\n formElement.elements,\n entry as SubmissionTypes.S3SubmissionData['submission'],\n )\n entries.isAutoLookup =\n entries.isAutoLookup && nestedLookupButtonValue.isAutoLookup\n if (nestedLookupButtonValue.data || existingEntries?.[index]) {\n entries.data[index] = {\n ...existingEntries?.[index],\n ...nestedLookupButtonValue.data,\n }\n hasAnEntry = true\n } else {\n entries.data[index] = undefined\n }\n }\n }\n\n return {\n isAutoLookup: memo.isAutoLookup && entries.isAutoLookup,\n data: hasAnEntry\n ? {\n ...memo.data,\n [formElement.name]: entries.data,\n }\n : memo.data,\n }\n }\n break\n }\n default: {\n if (formElement && 'name' in formElement) {\n let dependencyValue = formSubmissionModel[formElement.name]\n // If the dependency is a compliance element, we need to get the value of the compliance element\n // and not trigger the lookup if the notes or files are changing.\n if (\n formElement.type === 'compliance' &&\n typeof dependencyValue === 'object' &&\n dependencyValue !== null &&\n 'value' in dependencyValue\n ) {\n dependencyValue = dependencyValue.value\n }\n const isAutoLookupChecker = autoLookupElementMap[formElement.type]\n const isFormElementAutoLookup =\n typeof isAutoLookupChecker === 'function'\n ? isAutoLookupChecker(formElement)\n : isAutoLookupChecker\n return {\n isAutoLookup: memo.isAutoLookup && isFormElementAutoLookup,\n data:\n dependencyValue !== undefined && dependencyValue !== null\n ? {\n ...memo.data,\n [formElement.name]: dependencyValue,\n }\n : memo.data,\n }\n }\n break\n }\n }\n\n return memo\n },\n {\n isAutoLookup: true,\n data: undefined,\n },\n )\n}\n\n// Creating an object here so we get a Typescript error when adding a\n// new element type and forgetting to add to the array of allowed types\nconst autoLookupElementMap: Record<\n Exclude<FormTypes.FormElement['type'], 'page'>,\n boolean | ((element: FormTypes.FormElement) => boolean)\n> = {\n text: false,\n textarea: false,\n number: false,\n email: false,\n telephone: false,\n barcodeScanner: false,\n radio: true,\n checkboxes: false,\n select: (formElement) => formElement.type === 'select' && !formElement.multi,\n autocomplete: true,\n boolean: true,\n date: false,\n datetime: false,\n time: false,\n heading: false,\n html: false,\n image: false,\n infoPage: false,\n camera: false,\n repeatableSet: false,\n draw: false,\n calculation: false,\n location: true,\n files: true,\n captcha: false,\n form: false,\n summary: false,\n compliance: true,\n geoscapeAddress: true,\n pointAddress: true,\n pointAddressV3: true,\n googleAddress: false,\n civicaStreetName: true,\n civicaNameRecord: false,\n section: false,\n bsb: false,\n abn: false,\n freshdeskDependentField: false,\n apiNSWLiquorLicence: true,\n arcGISWebMap: true,\n pointCadastralParcel: true,\n lookupButton: false,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FormElementLookupButton.js","sourceRoot":"","sources":["../../src/form-elements/FormElementLookupButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACzE,OAAO,YAAY,MAAM,qCAAqC,CAAA;AAE9D,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AAMxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,kBAAkB,MAAM,2CAA2C,CAAA;AAC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ACf,MAAM,EAAE,KAAK;IACb,aAAa,EAAE,KAAK;IACpB,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,KAAK;IAClB,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,IAAI;IACrB,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,KAAK;IACpB,gBAAgB,EAAE,IAAI;IACtB,gBAAgB,EAAE,KAAK;IACvB,OAAO,EAAE,KAAK;IACd,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,uBAAuB,EAAE,KAAK;IAC9B,mBAAmB,EAAE,IAAI;IACzB,YAAY,EAAE,IAAI;IAClB,oBAAoB,EAAE,IAAI;IAC1B,YAAY,EAAE,KAAK;CACpB,CAAA","sourcesContent":["import { memo, useCallback, useContext, useEffect, useMemo } from 'react'\nimport LookupButton from '../components/renderer/LookupButton'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport {\n FormElementLookupHandler,\n FormElementValueChangeHandler,\n IsDirtyProps,\n} from '../types/form'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport LookupNotification from '../components/renderer/LookupNotification'\nimport useFormSubmissionModel from '../hooks/useFormSubmissionModelContext'\nimport { formElementsService } from '@oneblink/sdk-core'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype ValidationMessageProps = {\n displayValidationMessage: boolean\n validationMessage: string | undefined\n} & IsDirtyProps\n\ntype Props = {\n id: string\n element: FormTypes.LookupButtonFormElement\n readOnly: boolean\n} & ValidationMessageProps\n\nfunction stringifyLookupButtonValue(v: unknown): string {\n return JSON.stringify(v) as string\n}\n\nconst FormElementLookupButtonValidationMessage = memo(\n function FormElementLookupButtonValidationMessageComponent({\n validationMessage,\n displayValidationMessage,\n isDirty,\n }: ValidationMessageProps) {\n const { isLookingUp } = useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (isDirty || displayValidationMessage) &&\n !!validationMessage &&\n !isLookingUp\n\n if (!isDisplayingValidationMessage) {\n return null\n }\n\n return <FormElementValidationMessage message={validationMessage} />\n },\n)\n\nfunction FormElementLookupButton({\n id,\n element,\n readOnly,\n onChange,\n onLookup,\n validationMessage,\n ...validationMessageProps\n}: Props & {\n onChange: FormElementValueChangeHandler\n onLookup: FormElementLookupHandler\n}) {\n const { formSubmissionModel, elements } = useFormSubmissionModel()\n const { isAutoLookup, data } = useMemo(() => {\n return generateLookupButtonValue(\n element.elementDependencies,\n elements,\n formSubmissionModel,\n )\n }, [element.elementDependencies, elements, formSubmissionModel])\n\n const handleLookup = useCallback<FormElementLookupHandler>(\n (setter, options) => {\n onLookup((data) => {\n const dataAfterSetting = setter(data)\n dataAfterSetting.submission[element.name] = true\n return dataAfterSetting\n }, options)\n },\n [element.name, onLookup],\n )\n\n const stringifyData = useMemo(() => {\n if (!data) {\n return undefined\n }\n return stringifyLookupButtonValue(data)\n }, [data])\n\n useEffect(() => {\n if (readOnly) {\n return\n }\n onChange(element, {\n value: false,\n isDerivedChange: true,\n })\n }, [element, onChange, readOnly, stringifyData])\n\n const value = useMemo(() => {\n // Want the value to be `true` if there is data or if there are\n // no element dependencies i.e. the lookup can be run at any time.\n if (!element.elementDependencies.length || data) {\n return true\n }\n return undefined\n }, [data, element.elementDependencies.length])\n\n return (\n <LookupNotification\n autoLookupValue={isAutoLookup ? stringifyData : undefined}\n element={element}\n onLookup={handleLookup}\n stringifyAutoLookupValue={stringifyLookupButtonValue}\n >\n <div className=\"cypress-lookup-button-element\">\n <FormElementLabelContainer\n className=\"ob-lookup-button\"\n id={id}\n element={element}\n required={false}\n >\n <LookupButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n overrideRequiredMessage={element.requiredMessage}\n />\n <FormElementLookupButtonValidationMessage\n validationMessage={validationMessage}\n {...validationMessageProps}\n />\n </FormElementLabelContainer>\n </div>\n </LookupNotification>\n )\n}\n\nexport default memo(FormElementLookupButton)\n\nfunction generateLookupButtonValue(\n elementDependencies: FormTypes.LookupButtonFormElement['elementDependencies'],\n elements: FormTypes.FormElement[],\n formSubmissionModel:\n | SubmissionTypes.S3SubmissionData['submission']\n | undefined,\n): {\n isAutoLookup: boolean\n data: SubmissionTypes.S3SubmissionData['submission'] | undefined\n} {\n if (!formSubmissionModel) {\n return {\n isAutoLookup: false,\n data: undefined,\n }\n }\n\n // \"data\" should be `undefined` if there are no dependent elements with a value.\n // If a least one dependent element has a value, we will enable to lookup to run.\n return elementDependencies.reduce<{\n isAutoLookup: boolean\n data: SubmissionTypes.S3SubmissionData['submission'] | undefined\n }>(\n (memo, elementDependency) => {\n const formElement = formElementsService.findFormElement(\n elements,\n (formElement) => formElement.id === elementDependency.elementId,\n )\n if (!formElement || !('name' in formElement)) {\n return memo\n }\n\n const formElementValue = formSubmissionModel[formElement.name]\n\n switch (elementDependency.type) {\n case 'FORM_FORM_ELEMENT': {\n if (\n formElement.type === 'form' &&\n Array.isArray(formElement.elements)\n ) {\n const nestedLookupButtonValue = generateLookupButtonValue(\n [elementDependency.elementDependency],\n formElement.elements,\n formElementValue as SubmissionTypes.S3SubmissionData['submission'],\n )\n return {\n isAutoLookup:\n memo.isAutoLookup && nestedLookupButtonValue.isAutoLookup,\n data:\n nestedLookupButtonValue.data !== undefined\n ? {\n ...memo.data,\n [formElement.name]: {\n ...(memo?.data?.[formElement.name] || {}),\n ...nestedLookupButtonValue.data,\n },\n }\n : memo.data,\n }\n }\n break\n }\n case 'REPEATABLE_SET_FORM_ELEMENT': {\n if (formElement.type === 'repeatableSet') {\n const entries: {\n isAutoLookup: boolean\n data: Record<\n number,\n SubmissionTypes.S3SubmissionData['submission'] | undefined\n >\n } = {\n isAutoLookup: memo.isAutoLookup,\n data: {},\n }\n let hasAnEntry = false\n const existingEntries =\n (memo.data?.[formElement.name] as object[]) || undefined\n if (Array.isArray(formElementValue)) {\n for (const entry of formElementValue) {\n const index = formElementValue.indexOf(entry)\n const nestedLookupButtonValue = generateLookupButtonValue(\n [elementDependency.elementDependency],\n formElement.elements,\n entry as SubmissionTypes.S3SubmissionData['submission'],\n )\n entries.isAutoLookup =\n entries.isAutoLookup && nestedLookupButtonValue.isAutoLookup\n if (nestedLookupButtonValue.data || existingEntries?.[index]) {\n entries.data[index] = {\n ...existingEntries?.[index],\n ...nestedLookupButtonValue.data,\n }\n hasAnEntry = true\n } else {\n entries.data[index] = undefined\n }\n }\n }\n\n return {\n isAutoLookup: memo.isAutoLookup && entries.isAutoLookup,\n data: hasAnEntry\n ? {\n ...memo.data,\n [formElement.name]: entries.data,\n }\n : memo.data,\n }\n }\n break\n }\n default: {\n if (formElement && 'name' in formElement) {\n let dependencyValue = formSubmissionModel[formElement.name]\n // If the dependency is a compliance element, we need to get the value of the compliance element\n // and not trigger the lookup if the notes or files are changing.\n if (\n formElement.type === 'compliance' &&\n typeof dependencyValue === 'object' &&\n dependencyValue !== null &&\n 'value' in dependencyValue\n ) {\n dependencyValue = dependencyValue.value\n }\n const isAutoLookupChecker = autoLookupElementMap[formElement.type]\n const isFormElementAutoLookup =\n typeof isAutoLookupChecker === 'function'\n ? isAutoLookupChecker(formElement)\n : isAutoLookupChecker\n return {\n isAutoLookup: memo.isAutoLookup && isFormElementAutoLookup,\n data:\n dependencyValue !== undefined && dependencyValue !== null\n ? {\n ...memo.data,\n [formElement.name]: dependencyValue,\n }\n : memo.data,\n }\n }\n break\n }\n }\n\n return memo\n },\n {\n isAutoLookup: true,\n data: undefined,\n },\n )\n}\n\n// Creating an object here so we get a Typescript error when adding a\n// new element type and forgetting to add to the array of allowed types\nconst autoLookupElementMap: Record<\n Exclude<FormTypes.FormElement['type'], 'page'>,\n boolean | ((element: FormTypes.FormElement) => boolean)\n> = {\n text: false,\n textarea: false,\n number: false,\n email: false,\n telephone: false,\n barcodeScanner: false,\n radio: true,\n checkboxes: false,\n select: (formElement) => formElement.type === 'select' && !formElement.multi,\n autocomplete: true,\n boolean: true,\n date: false,\n datetime: false,\n time: false,\n heading: false,\n html: false,\n image: false,\n infoPage: false,\n camera: false,\n repeatableSet: false,\n draw: false,\n calculation: false,\n location: true,\n files: true,\n captcha: false,\n form: false,\n summary: false,\n compliance: true,\n geoscapeAddress: true,\n pointAddress: true,\n pointAddressV3: true,\n googleAddress: false,\n civicaStreetName: true,\n civicaNameRecord: false,\n section: false,\n bsb: false,\n abn: false,\n freshdeskDependentField: false,\n apiNSWLiquorLicence: true,\n arcGISWebMap: true,\n pointCadastralParcel: true,\n lookupButton: false,\n}\n"]}
|
|
@@ -43,7 +43,7 @@ function FormElementNumber({ id, element, readOnly, value, onChange, validationM
|
|
|
43
43
|
}, []);
|
|
44
44
|
const { isLookingUp } = React.useContext(LookupNotificationContext);
|
|
45
45
|
const isDisplayingValidationMessage = (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp;
|
|
46
|
-
return (_jsx("div", { className: "cypress-number-element", children: _jsxs(FormElementLabelContainer, { className: "ob-number", id: id, element: element, required: element.required, children: [!element.isSlider ? (_jsxs("div", { className: "field has-addons", children: [_jsxs("div", { className: "control is-expanded has-icons-right", children: [_jsx("input", { type: "number", placeholder: element.placeholderValue, id: id, value: typeof value === 'number' ? value : '', name: element.name, className: "input ob-input cypress-number-control", onChange: handleChange, required: element.required, disabled: readOnly, onBlur: setIsDirty, ref: htmlInputElementRef, onWheel: handleWheel, "aria-describedby": ariaDescribedby, autoComplete: autocompleteAttributes, "aria-required": element.required }), _jsx("span", { className: "ob-input-icon icon is-small is-right", children: _jsx(MaterialIcon, { className: "is-size-5", children: element.displayAsCurrency ? 'attach_money' : 'tag' }) })] }), !!readOnly && !!text && (_jsx("div", { className: "control", children: _jsx(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }) })), _jsx(LookupButton, {
|
|
46
|
+
return (_jsx("div", { className: "cypress-number-element", children: _jsxs(FormElementLabelContainer, { className: "ob-number", id: id, element: element, required: element.required, children: [!element.isSlider ? (_jsxs("div", { className: "field has-addons", children: [_jsxs("div", { className: "control is-expanded has-icons-right", children: [_jsx("input", { type: "number", placeholder: element.placeholderValue, id: id, value: typeof value === 'number' ? value : '', name: element.name, className: "input ob-input cypress-number-control", onChange: handleChange, required: element.required, disabled: readOnly, onBlur: setIsDirty, ref: htmlInputElementRef, onWheel: handleWheel, "aria-describedby": ariaDescribedby, autoComplete: autocompleteAttributes, "aria-required": element.required }), _jsx("span", { className: "ob-input-icon icon is-small is-right", children: _jsx(MaterialIcon, { className: "is-size-5", children: element.displayAsCurrency ? 'attach_money' : 'tag' }) })] }), !!readOnly && !!text && (_jsx("div", { className: "control", children: _jsx(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }) })), _jsx(LookupButton, { isInputButton: true, value: value, validationMessage: validationMessage, lookupButtonConfig: element.lookupButton, overrideRequiredMessage: undefined })] })) : isPageVisible ? (_jsx(SliderControl, { id: id, text: text, value: value, element: element, readOnly: readOnly, onChange: handleChange, onBlur: setIsDirty, ariaDescribedby: ariaDescribedby })) : undefined, isDisplayingValidationMessage && (_jsx(FormElementValidationMessage, { message: validationMessage }))] }) }));
|
|
47
47
|
}
|
|
48
48
|
const sliderBubbleWidthInPixels = 24;
|
|
49
49
|
const SliderControl = React.memo(function SliderControl({ id, text, value, element, readOnly, onChange, onBlur, ariaDescribedby, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormElementNumber.js","sourceRoot":"","sources":["../../src/form-elements/FormElementNumber.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,qBAAqB,MAAM,8CAA8C,CAAA;AAChF,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,YAAY,MAAM,qCAAqC,CAAA;AAE9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AI,EAAC,OAAO,EACZ,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ,sBACR,eAAe,mBAClB,OAAO,CAAC,QAAQ,EAC/B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACd,IACE,CACP,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,eAAe,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport CopyToClipboardButton from '../components/renderer/CopyToClipboardButton'\nimport _debounce from 'lodash.debounce'\nimport LookupButton from '../components/renderer/LookupButton'\nimport { FormTypes } from '@oneblink/types'\nimport { localisationService } from '../apps'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport useIsPageVisible from '../hooks/useIsPageVisible'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport MaterialIcon from '../components/MaterialIcon'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype Props = {\n id: string\n element: FormTypes.NumberElement\n readOnly: boolean\n value: unknown\n onChange: FormElementValueChangeHandler<number>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n autocompleteAttributes?: string\n} & IsDirtyProps\n\nfunction FormElementNumber({\n id,\n element,\n readOnly,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n autocompleteAttributes,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const isPageVisible = useIsPageVisible()\n\n const text = React.useMemo(() => {\n if (typeof value !== 'number') {\n return ''\n }\n if (element.displayAsCurrency) {\n return localisationService.formatCurrency(value)\n }\n return value.toString()\n }, [value, element.displayAsCurrency])\n const handleChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = parseFloat(event.target.value)\n onChange(element, {\n value: isNaN(newValue) ? undefined : newValue,\n })\n },\n [element, onChange],\n )\n const htmlInputElementRef = React.useRef<HTMLInputElement>(null)\n\n //this onWheel callback prevents numbers changing while scrolling\n const handleWheel = React.useCallback(() => {\n if (htmlInputElementRef.current !== document.activeElement) {\n return\n }\n htmlInputElementRef.current?.blur()\n setTimeout(() => {\n htmlInputElementRef.current?.focus()\n })\n }, [])\n\n const { isLookingUp } = React.useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp\n\n return (\n <div className=\"cypress-number-element\">\n <FormElementLabelContainer\n className=\"ob-number\"\n id={id}\n element={element}\n required={element.required}\n >\n {!element.isSlider ? (\n <div className=\"field has-addons\">\n <div className=\"control is-expanded has-icons-right\">\n <input\n type=\"number\"\n placeholder={element.placeholderValue}\n id={id}\n value={typeof value === 'number' ? value : ''}\n name={element.name}\n className=\"input ob-input cypress-number-control\"\n onChange={handleChange}\n required={element.required}\n disabled={readOnly}\n onBlur={setIsDirty}\n ref={htmlInputElementRef}\n onWheel={handleWheel}\n aria-describedby={ariaDescribedby}\n autoComplete={autocompleteAttributes}\n aria-required={element.required}\n />\n <span className=\"ob-input-icon icon is-small is-right\">\n <MaterialIcon className=\"is-size-5\">\n {element.displayAsCurrency ? 'attach_money' : 'tag'}\n </MaterialIcon>\n </span>\n </div>\n {!!readOnly && !!text && (\n <div className=\"control\">\n <CopyToClipboardButton\n className=\"button is-input-addon copy-button cypress-copy-to-clipboard-button\"\n text={text}\n />\n </div>\n )}\n <LookupButton\n readOnly={readOnly}\n isInputButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n overrideRequiredMessage={undefined}\n />\n </div>\n ) : isPageVisible ? (\n <SliderControl\n id={id}\n text={text}\n value={value}\n element={element}\n readOnly={readOnly}\n onChange={handleChange}\n onBlur={setIsDirty}\n ariaDescribedby={ariaDescribedby}\n />\n ) : undefined}\n\n {isDisplayingValidationMessage && (\n <FormElementValidationMessage message={validationMessage} />\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nconst sliderBubbleWidthInPixels = 24\n\nconst SliderControl = React.memo(function SliderControl({\n id,\n text,\n value,\n element,\n readOnly,\n onChange,\n onBlur,\n ariaDescribedby,\n}: {\n id: string\n text: string\n value: unknown\n element: FormTypes.NumberElement\n readOnly: boolean\n ariaDescribedby: string | undefined\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => unknown\n onBlur: () => void\n}) {\n const sliderOutputRef = React.useRef<HTMLOutputElement>(null)\n const sliderInputRef = React.useRef<HTMLInputElement>(null)\n\n const number = React.useMemo(\n () => (typeof value === 'number' ? value : parseFloat(value as string)),\n [value],\n )\n\n const removeIsDraggingClass = React.useMemo(\n () =>\n _debounce((outputElement: HTMLOutputElement) => {\n if (outputElement.classList.contains('is-dragging')) {\n outputElement.classList.remove('is-dragging')\n }\n }, 500),\n [],\n )\n\n React.useEffect(() => {\n if (\n Number.isNaN(number) ||\n typeof element.maxNumber !== 'number' ||\n typeof element.minNumber !== 'number'\n ) {\n return\n }\n\n const outputElement = sliderOutputRef.current\n const inputElement = sliderInputRef.current\n if (outputElement && inputElement) {\n const range = element.maxNumber - element.minNumber\n const percentage = (number - element.minNumber) / range\n const inputWidth = inputElement.getBoundingClientRect().width\n const outputWidth = outputElement.getBoundingClientRect().width\n const sliderBubbleOffSetPixels =\n (percentage - 0.5) * -sliderBubbleWidthInPixels\n\n outputElement.style.left = `${percentage * inputWidth}px`\n outputElement.style.marginLeft = `-${\n outputWidth / 2 - sliderBubbleOffSetPixels\n }px`\n\n if (!outputElement.classList.contains('is-dragging')) {\n outputElement.classList.add('is-dragging')\n }\n removeIsDraggingClass(outputElement)\n }\n }, [element.maxNumber, element.minNumber, number, removeIsDraggingClass])\n\n return (\n <div className=\"control\">\n <output\n ref={sliderOutputRef}\n className=\"ob-number__output cypress-number-output\"\n htmlFor={id}\n >\n {text}\n </output>\n <input\n ref={sliderInputRef}\n id={id}\n name={element.name}\n className=\"slider ob-input is-fullwidth cypress-slider-number-control is-large is-circle cypress-number-control\"\n step={element.sliderIncrement ? element.sliderIncrement : 1}\n min={element.minNumber}\n max={element.maxNumber}\n value={number}\n type=\"range\"\n onChange={onChange}\n required={element.required}\n aria-describedby={ariaDescribedby}\n aria-required={element.required}\n disabled={readOnly}\n onBlur={onBlur}\n />\n </div>\n )\n})\n\nexport default React.memo(FormElementNumber)\n"]}
|
|
1
|
+
{"version":3,"file":"FormElementNumber.js","sourceRoot":"","sources":["../../src/form-elements/FormElementNumber.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,qBAAqB,MAAM,8CAA8C,CAAA;AAChF,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,YAAY,MAAM,qCAAqC,CAAA;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AAExF,OAAO,gBAAgB,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,yBAAyB,MAAM,oCAAoC,CAAA;AAC1E,OAAO,YAAY,MAAM,4BAA4B,CAAA;AACrD,OAAO,4BAA4B,MAAM,qDAAqD,CAAA;AAa9F,SAAS,iBAAiB,CAAC,EACzB,EAAE,EACF,OAAO,EACP,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,EACP,UAAU,EACV,sBAAsB,GAChB;IACN,MAAM,eAAe,GAAG,yBAAyB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC9D,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,EAAE,CAAA;QACX,CAAC;Q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E,qBAAqB,CAAC,CAAC,CAAA;IAEzE,OAAO,CACL,eAAK,SAAS,EAAC,SAAS,aACtB,iBACE,GAAG,EAAE,eAAe,EACpB,SAAS,EAAC,yCAAyC,EACnD,OAAO,EAAE,EAAE,YAEV,IAAI,GACE,EACT,gBACE,GAAG,EAAE,cAAc,EACnB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,OAAO,CAAC,IAAI,EAClB,SAAS,EAAC,sGAAsG,EAChH,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAC3D,GAAG,EAAE,OAAO,CAAC,SAAS,EACtB,GAAG,EAAE,OAAO,CAAC,SAAS,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAC,OAAO,EACZ,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ,sBACR,eAAe,mBAClB,OAAO,CAAC,QAAQ,EAC/B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACd,IACE,CACP,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,eAAe,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport CopyToClipboardButton from '../components/renderer/CopyToClipboardButton'\nimport _debounce from 'lodash.debounce'\nimport LookupButton from '../components/renderer/LookupButton'\nimport { FormTypes } from '@oneblink/types'\nimport { localisationService } from '../apps'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport useIsPageVisible from '../hooks/useIsPageVisible'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport MaterialIcon from '../components/MaterialIcon'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype Props = {\n id: string\n element: FormTypes.NumberElement\n readOnly: boolean\n value: unknown\n onChange: FormElementValueChangeHandler<number>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n autocompleteAttributes?: string\n} & IsDirtyProps\n\nfunction FormElementNumber({\n id,\n element,\n readOnly,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n autocompleteAttributes,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const isPageVisible = useIsPageVisible()\n\n const text = React.useMemo(() => {\n if (typeof value !== 'number') {\n return ''\n }\n if (element.displayAsCurrency) {\n return localisationService.formatCurrency(value)\n }\n return value.toString()\n }, [value, element.displayAsCurrency])\n const handleChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = parseFloat(event.target.value)\n onChange(element, {\n value: isNaN(newValue) ? undefined : newValue,\n })\n },\n [element, onChange],\n )\n const htmlInputElementRef = React.useRef<HTMLInputElement>(null)\n\n //this onWheel callback prevents numbers changing while scrolling\n const handleWheel = React.useCallback(() => {\n if (htmlInputElementRef.current !== document.activeElement) {\n return\n }\n htmlInputElementRef.current?.blur()\n setTimeout(() => {\n htmlInputElementRef.current?.focus()\n })\n }, [])\n\n const { isLookingUp } = React.useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp\n\n return (\n <div className=\"cypress-number-element\">\n <FormElementLabelContainer\n className=\"ob-number\"\n id={id}\n element={element}\n required={element.required}\n >\n {!element.isSlider ? (\n <div className=\"field has-addons\">\n <div className=\"control is-expanded has-icons-right\">\n <input\n type=\"number\"\n placeholder={element.placeholderValue}\n id={id}\n value={typeof value === 'number' ? value : ''}\n name={element.name}\n className=\"input ob-input cypress-number-control\"\n onChange={handleChange}\n required={element.required}\n disabled={readOnly}\n onBlur={setIsDirty}\n ref={htmlInputElementRef}\n onWheel={handleWheel}\n aria-describedby={ariaDescribedby}\n autoComplete={autocompleteAttributes}\n aria-required={element.required}\n />\n <span className=\"ob-input-icon icon is-small is-right\">\n <MaterialIcon className=\"is-size-5\">\n {element.displayAsCurrency ? 'attach_money' : 'tag'}\n </MaterialIcon>\n </span>\n </div>\n {!!readOnly && !!text && (\n <div className=\"control\">\n <CopyToClipboardButton\n className=\"button is-input-addon copy-button cypress-copy-to-clipboard-button\"\n text={text}\n />\n </div>\n )}\n <LookupButton\n isInputButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n overrideRequiredMessage={undefined}\n />\n </div>\n ) : isPageVisible ? (\n <SliderControl\n id={id}\n text={text}\n value={value}\n element={element}\n readOnly={readOnly}\n onChange={handleChange}\n onBlur={setIsDirty}\n ariaDescribedby={ariaDescribedby}\n />\n ) : undefined}\n\n {isDisplayingValidationMessage && (\n <FormElementValidationMessage message={validationMessage} />\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nconst sliderBubbleWidthInPixels = 24\n\nconst SliderControl = React.memo(function SliderControl({\n id,\n text,\n value,\n element,\n readOnly,\n onChange,\n onBlur,\n ariaDescribedby,\n}: {\n id: string\n text: string\n value: unknown\n element: FormTypes.NumberElement\n readOnly: boolean\n ariaDescribedby: string | undefined\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => unknown\n onBlur: () => void\n}) {\n const sliderOutputRef = React.useRef<HTMLOutputElement>(null)\n const sliderInputRef = React.useRef<HTMLInputElement>(null)\n\n const number = React.useMemo(\n () => (typeof value === 'number' ? value : parseFloat(value as string)),\n [value],\n )\n\n const removeIsDraggingClass = React.useMemo(\n () =>\n _debounce((outputElement: HTMLOutputElement) => {\n if (outputElement.classList.contains('is-dragging')) {\n outputElement.classList.remove('is-dragging')\n }\n }, 500),\n [],\n )\n\n React.useEffect(() => {\n if (\n Number.isNaN(number) ||\n typeof element.maxNumber !== 'number' ||\n typeof element.minNumber !== 'number'\n ) {\n return\n }\n\n const outputElement = sliderOutputRef.current\n const inputElement = sliderInputRef.current\n if (outputElement && inputElement) {\n const range = element.maxNumber - element.minNumber\n const percentage = (number - element.minNumber) / range\n const inputWidth = inputElement.getBoundingClientRect().width\n const outputWidth = outputElement.getBoundingClientRect().width\n const sliderBubbleOffSetPixels =\n (percentage - 0.5) * -sliderBubbleWidthInPixels\n\n outputElement.style.left = `${percentage * inputWidth}px`\n outputElement.style.marginLeft = `-${\n outputWidth / 2 - sliderBubbleOffSetPixels\n }px`\n\n if (!outputElement.classList.contains('is-dragging')) {\n outputElement.classList.add('is-dragging')\n }\n removeIsDraggingClass(outputElement)\n }\n }, [element.maxNumber, element.minNumber, number, removeIsDraggingClass])\n\n return (\n <div className=\"control\">\n <output\n ref={sliderOutputRef}\n className=\"ob-number__output cypress-number-output\"\n htmlFor={id}\n >\n {text}\n </output>\n <input\n ref={sliderInputRef}\n id={id}\n name={element.name}\n className=\"slider ob-input is-fullwidth cypress-slider-number-control is-large is-circle cypress-number-control\"\n step={element.sliderIncrement ? element.sliderIncrement : 1}\n min={element.minNumber}\n max={element.maxNumber}\n value={number}\n type=\"range\"\n onChange={onChange}\n required={element.required}\n aria-describedby={ariaDescribedby}\n aria-required={element.required}\n disabled={readOnly}\n onBlur={onBlur}\n />\n </div>\n )\n})\n\nexport default React.memo(FormElementNumber)\n"]}
|
|
@@ -7,15 +7,15 @@ type Props = {
|
|
|
7
7
|
isEven: boolean;
|
|
8
8
|
element: FormTypes.RepeatableSetElement;
|
|
9
9
|
/**
|
|
10
|
-
* Whether this set’s own controls (add/remove entries) are locked.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Whether this set’s own controls (add/remove entries) are locked. The set
|
|
11
|
+
* itself must be listed in `editableFormElementIds` to add or remove entries;
|
|
12
|
+
* a nested field being listed is not enough.
|
|
13
13
|
*/
|
|
14
14
|
readOnly: boolean;
|
|
15
15
|
/**
|
|
16
16
|
* Lock to apply to fields inside each entry. True when the whole form is
|
|
17
17
|
* read-only, a parent is read-only, or this element’s definition has
|
|
18
|
-
* `readOnly: true`.
|
|
18
|
+
* `readOnly: true`.
|
|
19
19
|
*/
|
|
20
20
|
childrenReadOnly: boolean;
|
|
21
21
|
value: Array<SubmissionTypes.S3SubmissionData['submission']> | undefined;
|
|
@@ -130,7 +130,7 @@ function FormElementRepeatableSet({ formId, element, readOnly, childrenReadOnly,
|
|
|
130
130
|
});
|
|
131
131
|
setIsDirty();
|
|
132
132
|
}, [onChange, setIsDirty]);
|
|
133
|
-
const handleNestedChange = React.useCallback((index, nestedElement, { value, executedLookups, sectionState, }, idPrefix) => {
|
|
133
|
+
const handleNestedChange = React.useCallback((index, nestedElement, { value, executedLookups, sectionState, isDerivedChange, }, idPrefix) => {
|
|
134
134
|
if (nestedElement.type === 'section') {
|
|
135
135
|
// trigger onChange to update sectionState
|
|
136
136
|
onChange({
|
|
@@ -178,6 +178,7 @@ function FormElementRepeatableSet({ formId, element, readOnly, childrenReadOnly,
|
|
|
178
178
|
return newExecutedLookups;
|
|
179
179
|
},
|
|
180
180
|
sectionState,
|
|
181
|
+
isDerivedChange,
|
|
181
182
|
});
|
|
182
183
|
}, [element, onChange]);
|
|
183
184
|
const { minSetEntries, maxSetEntries } = useFormElementRepeatableSetEntries(element);
|
|
@@ -219,14 +220,15 @@ export default React.memo(FormElementRepeatableSet);
|
|
|
219
220
|
const RepeatableSetEntry = React.memo(function RepeatableSetEntry({ formId, id, index, isEven, entry, element, readOnly, childrenReadOnly, formElementsConditionallyShown, displayValidationMessages, formElementsValidation, onChange, onLookup, onAdd, onRemove, onUpdateFormElements, showAddButton, sectionState, }) {
|
|
220
221
|
const [isConfirmingRemove, confirmRemove, cancelRemove] = useBooleanState(false);
|
|
221
222
|
const elementDOMId = React.useMemo(() => new ElementDOMId(id), [id]);
|
|
222
|
-
const handleChange = React.useCallback((nestedElement, { value, executedLookups, sectionState }, idPrefix) => {
|
|
223
|
+
const handleChange = React.useCallback((nestedElement, { value, executedLookups, sectionState, isDerivedChange }, idPrefix) => {
|
|
223
224
|
onChange(index, nestedElement, {
|
|
224
225
|
value,
|
|
225
226
|
executedLookups,
|
|
226
227
|
sectionState,
|
|
228
|
+
isDerivedChange,
|
|
227
229
|
}, idPrefix);
|
|
228
230
|
}, [index, onChange]);
|
|
229
|
-
const handleLookup = React.useCallback((mergeLookupResults) => {
|
|
231
|
+
const handleLookup = React.useCallback((mergeLookupResults, options) => {
|
|
230
232
|
onLookup((currentFormSubmission) => {
|
|
231
233
|
var _a, _b;
|
|
232
234
|
let newEntry = {};
|
|
@@ -286,7 +288,7 @@ const RepeatableSetEntry = React.memo(function RepeatableSetEntry({ formId, id,
|
|
|
286
288
|
submission,
|
|
287
289
|
executedLookups: updatedExecutedLookups,
|
|
288
290
|
};
|
|
289
|
-
});
|
|
291
|
+
}, options);
|
|
290
292
|
}, [element.name, index, onLookup]);
|
|
291
293
|
const { validationClassName } = useValidationClass({
|
|
292
294
|
formElementsValid: !formElementsValidation,
|