@arquimedes.co/eureka-forms 3.0.71-test → 3.0.72
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/README +33 -1
- package/dist/@Types/AvailabilityFormStep.d.ts +48 -0
- package/dist/@Types/AvailabilityFormStep.js +24 -0
- package/dist/@Types/BankAccountFormStep.d.ts +67 -0
- package/dist/@Types/BankAccountFormStep.js +14 -0
- package/dist/@Types/BookingFormStep.d.ts +249 -0
- package/dist/@Types/BookingFormStep.js +65 -0
- package/dist/@Types/CalendarFormStep.d.ts +209 -0
- package/dist/@Types/CalendarFormStep.js +55 -0
- package/dist/@Types/CommunicationChannelFormStep.d.ts +51 -0
- package/dist/@Types/CommunicationChannelFormStep.js +15 -0
- package/dist/@Types/ConsentFormStep.d.ts +36 -0
- package/dist/@Types/ConsentFormStep.js +8 -0
- package/dist/@Types/EntityFormFormStep.d.ts +66 -0
- package/dist/@Types/EntityFormFormStep.js +20 -0
- package/dist/@Types/EventFormStep.d.ts +52 -0
- package/dist/@Types/EventFormStep.js +13 -0
- package/dist/@Types/ExternalReferenceFormStep.d.ts +74 -0
- package/dist/@Types/ExternalReferenceFormStep.js +20 -0
- package/dist/@Types/FormStep.d.ts +7 -2
- package/dist/@Types/FormStep.js +2 -1
- package/dist/@Types/LocationFormStep.d.ts +159 -0
- package/dist/@Types/LocationFormStep.js +46 -0
- package/dist/@Types/NumericFormSteps.d.ts +108 -0
- package/dist/@Types/NumericFormSteps.js +20 -0
- package/dist/@Types/PredefinedSelectorFormStep.d.ts +51 -0
- package/dist/@Types/PredefinedSelectorFormStep.js +39 -0
- package/dist/@Types/StepRef.d.ts +135 -0
- package/dist/@Types/StepRef.js +49 -0
- package/dist/App/App.stories.d.ts +10 -0
- package/dist/App/App.stories.js +189 -0
- package/dist/App/App.submitError.test.d.ts +1 -0
- package/dist/App/App.submitError.test.js +53 -0
- package/dist/App/AppHooks.js +8 -0
- package/dist/App/AppHooks.test.js +8 -0
- package/dist/BookingManage/AppointmentText.d.ts +5 -0
- package/dist/BookingManage/AppointmentText.js +20 -0
- package/dist/BookingManage/BookingManagePage.d.ts +17 -0
- package/dist/BookingManage/BookingManagePage.js +177 -0
- package/dist/BookingManage/BookingManagePage.module.css +115 -0
- package/dist/BookingManage/BookingManagePage.test.d.ts +1 -0
- package/dist/BookingManage/BookingManagePage.test.js +149 -0
- package/dist/Form/ConfirmationDialog/ConfirmationDialog.d.ts +14 -5
- package/dist/Form/ConfirmationDialog/ConfirmationDialog.js +8 -1
- package/dist/Form/ConfirmationDialog/ConfirmationDialog.module.css +12 -0
- package/dist/Form/ConfirmationDialog/ConfirmationDialog.test.d.ts +1 -0
- package/dist/Form/ConfirmationDialog/ConfirmationDialog.test.js +21 -0
- package/dist/Form/Form.d.ts +3 -0
- package/dist/Form/Form.js +16 -8
- package/dist/Form/FormFunctions.d.ts +17 -0
- package/dist/Form/FormFunctions.js +22 -0
- package/dist/Form/FormFunctions.test.js +28 -1
- package/dist/Form/FormTypes/ColumnForm/ColumnForm.d.ts +1 -1
- package/dist/Form/FormTypes/ColumnForm/ColumnForm.js +3 -2
- package/dist/Form/FormTypes/StepperForm/StepperForm.d.ts +1 -1
- package/dist/Form/FormTypes/StepperForm/StepperForm.js +3 -2
- package/dist/Form/SubmitError/SubmitError.d.ts +11 -0
- package/dist/Form/SubmitError/SubmitError.js +9 -0
- package/dist/Form/SubmitError/SubmitError.module.css +25 -0
- package/dist/Form/SubmitError/SubmitError.test.d.ts +1 -0
- package/dist/Form/SubmitError/SubmitError.test.js +34 -0
- package/dist/Form/SubmitError/SubmitErrorReason.d.ts +13 -0
- package/dist/Form/SubmitError/SubmitErrorReason.js +20 -0
- package/dist/FormSteps/AvailabilityStep/AvailabilityStep.d.ts +7 -0
- package/dist/FormSteps/AvailabilityStep/AvailabilityStep.js +14 -0
- package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.d.ts +8 -0
- package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.js +32 -0
- package/dist/FormSteps/BookingStep/BookingStep.d.ts +17 -0
- package/dist/FormSteps/BookingStep/BookingStep.js +14 -0
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.d.ts +21 -0
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.js +289 -0
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.test.d.ts +1 -0
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.test.js +275 -0
- package/dist/FormSteps/CheckBoxStep/CheckBoxStep.mobileLabel.test.js +20 -12
- package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.js +6 -13
- package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.module.css +2 -13
- package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.d.ts +1 -0
- package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.js +70 -0
- package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +3 -1
- package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +26 -26
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.d.ts +12 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.js +35 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.d.ts +1 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.js +31 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.d.ts +27 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.js +64 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.d.ts +1 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.js +95 -0
- package/dist/FormSteps/LocationStep/LocationStep.d.ts +10 -0
- package/dist/FormSteps/LocationStep/LocationStep.js +14 -0
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.d.ts +3 -0
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.js +54 -0
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.module.css +18 -0
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.d.ts +3 -0
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.js +170 -0
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.module.css +96 -0
- package/dist/FormSteps/NumberStep/NumberStep.d.ts +10 -0
- package/dist/FormSteps/NumberStep/NumberStep.js +14 -0
- package/dist/FormSteps/Step.js +16 -0
- package/dist/FormSteps/StepFunctions.js +14 -0
- package/dist/FormSteps/StepFunctions.test.js +54 -0
- package/dist/FormSteps/StepHooks.d.ts +21 -0
- package/dist/FormSteps/StepHooks.js +55 -8
- package/dist/FormSteps/StepHooks.test.d.ts +1 -0
- package/dist/FormSteps/StepHooks.test.js +92 -0
- package/dist/FormSteps/isStepHiddenByCondition.test.d.ts +1 -0
- package/dist/FormSteps/isStepHiddenByCondition.test.js +42 -0
- package/dist/Icons/AddIcon.d.ts +3 -0
- package/dist/Icons/AddIcon.js +7 -0
- package/dist/Icons/EditIcon.d.ts +3 -0
- package/dist/Icons/EditIcon.js +7 -0
- package/dist/Icons/RemoveIcon.d.ts +3 -0
- package/dist/Icons/RemoveIcon.js +7 -0
- package/dist/Icons/ViewDayIcon.d.ts +3 -0
- package/dist/Icons/ViewDayIcon.js +7 -0
- package/dist/Icons/ViewWeekIcon.d.ts +3 -0
- package/dist/Icons/ViewWeekIcon.js +7 -0
- package/dist/Services/BookingService.d.ts +226 -0
- package/dist/Services/BookingService.js +264 -0
- package/dist/Services/BookingService.test.d.ts +1 -0
- package/dist/Services/BookingService.test.js +178 -0
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.d.ts +19 -0
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.js +80 -0
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.module.css +88 -0
- package/dist/Shared/ErkAddressAutocomplete/googlePlaces.d.ts +29 -0
- package/dist/Shared/ErkAddressAutocomplete/googlePlaces.js +139 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.d.ts +25 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.js +112 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.module.css +88 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.d.ts +1 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.js +73 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.d.ts +105 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.js +399 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.module.css +646 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.d.ts +36 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.js +177 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.d.ts +1 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.js +47 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.d.ts +1 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.js +440 -0
- package/dist/Shared/ErkDatePicker/ErkDatePicker.js +1 -3
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +2 -3
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +1 -2
- package/dist/Shared/ErkIconButton/ErkIconButton.d.ts +17 -0
- package/dist/Shared/ErkIconButton/ErkIconButton.js +11 -0
- package/dist/Shared/ErkIconButton/ErkIconButton.module.css +41 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.d.ts +24 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.js +128 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.module.css +164 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.test.d.ts +1 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.test.js +82 -0
- package/dist/Shared/ErkLocationField/addressFields.d.ts +12 -0
- package/dist/Shared/ErkLocationField/addressFields.js +34 -0
- package/dist/Shared/ErkLocationField/locationRestrictions.d.ts +6 -0
- package/dist/Shared/ErkLocationField/locationRestrictions.js +51 -0
- package/dist/Shared/ErkLocationInput/ErkLocationInput.d.ts +15 -0
- package/dist/Shared/ErkLocationInput/ErkLocationInput.js +502 -0
- package/dist/Shared/ErkLocationInput/ErkLocationInput.module.css +128 -0
- package/dist/Shared/ErkNumberField/ErkNumberField.d.ts +42 -0
- package/dist/Shared/ErkNumberField/ErkNumberField.js +169 -0
- package/dist/Utils/AxiosWidget.js +9 -1
- package/dist/constants/FormStepTypes.d.ts +5 -1
- package/dist/constants/FormStepTypes.js +4 -0
- package/dist/index.lib.d.ts +4 -2
- package/dist/index.lib.js +3 -1
- package/dist/main.js +4 -1
- package/package.json +2 -1
|
@@ -48,7 +48,7 @@ function makeStore(currentBreakPoint) {
|
|
|
48
48
|
...defaultRootState,
|
|
49
49
|
widthStats: {
|
|
50
50
|
currentBreakPoint,
|
|
51
|
-
isMobile: currentBreakPoint <=
|
|
51
|
+
isMobile: currentBreakPoint <= 1,
|
|
52
52
|
isResponsive: true,
|
|
53
53
|
},
|
|
54
54
|
},
|
|
@@ -57,15 +57,15 @@ function makeStore(currentBreakPoint) {
|
|
|
57
57
|
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(RootApi.middleware),
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
function Harness({ currentBreakPoint }) {
|
|
60
|
+
function Harness({ currentBreakPoint, step = checkBoxStep, }) {
|
|
61
61
|
const methods = useForm({ mode: 'onTouched' });
|
|
62
|
-
return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: makeStore(currentBreakPoint), context: StoreContext, children: _jsx(IdFormContext.Provider, { value: STORY_FORM_ID, children: _jsx(FormContext.Provider, { value: form, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormProvider, { ...methods, children: _jsx(CheckBoxStep, { step:
|
|
62
|
+
return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: makeStore(currentBreakPoint), context: StoreContext, children: _jsx(IdFormContext.Provider, { value: STORY_FORM_ID, children: _jsx(FormContext.Provider, { value: { ...form, steps: { ...form.steps, [step.id]: step } }, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormProvider, { ...methods, children: _jsx(CheckBoxStep, { step: step, editable: true }) }) }) }) }) }) }));
|
|
63
63
|
}
|
|
64
64
|
function getLabelDiv() {
|
|
65
65
|
// the leaf div holding only the label text (the wrapping column also matches by textContent)
|
|
66
66
|
return screen.getByText((_, element) => element?.tagName === 'DIV' && element.children.length === 0 && element.textContent === `${LONG_LABEL}:`);
|
|
67
67
|
}
|
|
68
|
-
/** Makes every element report a
|
|
68
|
+
/** Makes every element report a 1-line-clamped overflow (jsdom has no layout). */
|
|
69
69
|
function mockLabelOverflow() {
|
|
70
70
|
Object.defineProperty(HTMLElement.prototype, 'scrollHeight', {
|
|
71
71
|
configurable: true,
|
|
@@ -76,7 +76,7 @@ function mockLabelOverflow() {
|
|
|
76
76
|
Object.defineProperty(HTMLElement.prototype, 'clientHeight', {
|
|
77
77
|
configurable: true,
|
|
78
78
|
get() {
|
|
79
|
-
return
|
|
79
|
+
return 24;
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
82
|
}
|
|
@@ -85,22 +85,30 @@ afterEach(() => {
|
|
|
85
85
|
delete HTMLElement.prototype.scrollHeight;
|
|
86
86
|
delete HTMLElement.prototype.clientHeight;
|
|
87
87
|
});
|
|
88
|
-
describe('CheckBoxStep
|
|
89
|
-
it('
|
|
88
|
+
describe('CheckBoxStep long labels', () => {
|
|
89
|
+
it('clamps the label to 1 line with a toggle instead of a plain ellipsis when the step collapses to 100% width', () => {
|
|
90
90
|
// breakpoint 1 <= size 2 → MaterialInputContainer renders the step at width: 100%
|
|
91
91
|
render(_jsx(Harness, { currentBreakPoint: 1 }));
|
|
92
92
|
const label = getLabelDiv();
|
|
93
93
|
expect(label.className).toBe(styles.clampLbl);
|
|
94
|
-
|
|
95
|
-
// the fixed desktop pixel maxWidth must not constrain the collapsed label
|
|
94
|
+
// no fixed desktop pixel maxWidth constrains the label
|
|
96
95
|
expect(label.style.maxWidth).toBe('');
|
|
97
96
|
});
|
|
98
|
-
it('
|
|
97
|
+
it('also clamps (with "ver más") when the step keeps a fixed width on a phone where 2 columns fit', () => {
|
|
98
|
+
// regression: a size-1 checkbox at breakpoint 2 used to render a single-line ellipsis with
|
|
99
|
+
// no way to read the full label
|
|
100
|
+
mockLabelOverflow();
|
|
101
|
+
render(_jsx(Harness, { currentBreakPoint: 2, step: { ...checkBoxStep, size: 1 } }));
|
|
102
|
+
const label = getLabelDiv();
|
|
103
|
+
expect(label.className).toBe(styles.clampLbl);
|
|
104
|
+
expect(label.style.maxWidth).toBe('');
|
|
105
|
+
expect(screen.getByRole('button', { name: 'ver más' })).toBeInTheDocument();
|
|
106
|
+
});
|
|
107
|
+
it('clamps on desktop widths too, without a toggle while the label fits', () => {
|
|
99
108
|
// breakpoint 4 > size 2 → the step keeps its fixed desktop width
|
|
100
109
|
render(_jsx(Harness, { currentBreakPoint: 4 }));
|
|
101
110
|
const label = getLabelDiv();
|
|
102
|
-
expect(label.className).toBe(styles.
|
|
103
|
-
expect(label.style.maxWidth).not.toBe('');
|
|
111
|
+
expect(label.className).toBe(styles.clampLbl);
|
|
104
112
|
expect(screen.queryByRole('button', { name: 'ver más' })).not.toBeInTheDocument();
|
|
105
113
|
});
|
|
106
114
|
it('shows no "ver más" toggle when the label fits in the clamp', () => {
|
|
@@ -8,7 +8,6 @@ import { useAppSelector, selectWidthStats } from '../../../hooks';
|
|
|
8
8
|
import { useFormStep } from '../../StepHooks';
|
|
9
9
|
import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
|
|
10
10
|
import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialInputContainer';
|
|
11
|
-
import { calcStepWidth, resolveStepSpan } from '../../StepFunctions';
|
|
12
11
|
function CheckBoxStep({ step, editable }) {
|
|
13
12
|
const { ref, value, onChange, error, field } = useFormStep(step, {
|
|
14
13
|
defaultValue: step.defaultValue ?? false,
|
|
@@ -20,15 +19,15 @@ function CheckBoxStep({ step, editable }) {
|
|
|
20
19
|
const { formStyle, postview } = useAppSelector((state) => state.global);
|
|
21
20
|
const form = useContext(FormContext);
|
|
22
21
|
const widthStats = useAppSelector(selectWidthStats);
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
// the
|
|
26
|
-
|
|
22
|
+
// The label is clamped to 1 line with a "ver más" toggle at every width. A plain
|
|
23
|
+
// ellipsis was used while the step kept its fixed desktop pixel width, but that left long
|
|
24
|
+
// labels unreadable wherever the step is narrow (e.g. a size-1 checkbox on a phone where 2
|
|
25
|
+
// columns fit).
|
|
27
26
|
const labelRef = useRef(null);
|
|
28
27
|
const [expanded, setExpanded] = useState(false);
|
|
29
28
|
const [clamped, setClamped] = useState(false);
|
|
30
29
|
useLayoutEffect(() => {
|
|
31
|
-
if (
|
|
30
|
+
if (expanded)
|
|
32
31
|
return;
|
|
33
32
|
const measure = () => {
|
|
34
33
|
const label = labelRef.current;
|
|
@@ -38,7 +37,7 @@ function CheckBoxStep({ step, editable }) {
|
|
|
38
37
|
measure();
|
|
39
38
|
window.addEventListener('resize', measure);
|
|
40
39
|
return () => window.removeEventListener('resize', measure);
|
|
41
|
-
}, [
|
|
40
|
+
}, [expanded, step.label, widthStats.currentBreakPoint]);
|
|
42
41
|
const renderNested = () => {
|
|
43
42
|
const steps = value ? step.steps : step.uncheckedSteps;
|
|
44
43
|
return (_jsx(React.Fragment, { children: steps?.map((idStep) => {
|
|
@@ -48,18 +47,12 @@ function CheckBoxStep({ step, editable }) {
|
|
|
48
47
|
};
|
|
49
48
|
const renderLabel = (colon = false) => {
|
|
50
49
|
const label = `${step.label}${step.required ? ' *' : ''}${colon ? ':' : ''}`;
|
|
51
|
-
if (!collapsed) {
|
|
52
|
-
return (_jsx("div", { className: span === 4 ? styles.checkboxLbl : styles.overflowLbl, style: {
|
|
53
|
-
maxWidth: calcStepWidth(span, form.size) - 45,
|
|
54
|
-
}, children: label }));
|
|
55
|
-
}
|
|
56
50
|
return (_jsxs("div", { className: styles.labelColumn, children: [_jsx("div", { ref: labelRef, className: expanded ? styles.expandedLbl : styles.clampLbl, children: label }), (clamped || expanded) && (_jsx("button", { type: "button", className: styles.toggleLbl, style: { color: formStyle.primaryColor }, onClick: (event) => {
|
|
57
51
|
event.stopPropagation();
|
|
58
52
|
setExpanded(!expanded);
|
|
59
53
|
}, children: expanded ? 'ver menos' : 'ver más' }))] }));
|
|
60
54
|
};
|
|
61
55
|
return (_jsxs(StepFillerContainer, { step: step, children: [_jsx(MaterialInputContainer, { step: step, editable: editable, maxHeight: step.size < 4, children: _jsxs("div", { className: styles.container, children: [_jsxs("div", { className: styles.labelCheckBoxContainer, style: {
|
|
62
|
-
height: span < 4 && !collapsed ? 31 : undefined,
|
|
63
56
|
minHeight: 31,
|
|
64
57
|
alignItems: step.isList ? 'start' : 'center',
|
|
65
58
|
}, children: [step.label && !step.isList && renderLabel(true), _jsx(ErkCheckBox, { ...field, padding: "0px", inputRef: ref, error: !!error, checked: value, onChange: onChange, "data-testid": step.id, readOnly: !editable || postview }), step.label && step.isList && renderLabel()] }), (step.description ?? !!error) && (_jsx("div", { className: styles.descriptionPar, style: {
|
|
@@ -3,17 +3,6 @@
|
|
|
3
3
|
flex-direction: column;
|
|
4
4
|
max-width: 100%;
|
|
5
5
|
}
|
|
6
|
-
.checkboxLbl,
|
|
7
|
-
.overflowLbl {
|
|
8
|
-
font-size: 18px;
|
|
9
|
-
margin-right: 10px;
|
|
10
|
-
margin-left: 10px;
|
|
11
|
-
}
|
|
12
|
-
.overflowLbl {
|
|
13
|
-
white-space: nowrap;
|
|
14
|
-
overflow: hidden;
|
|
15
|
-
text-overflow: ellipsis;
|
|
16
|
-
}
|
|
17
6
|
.labelColumn {
|
|
18
7
|
display: flex;
|
|
19
8
|
flex-direction: column;
|
|
@@ -30,8 +19,8 @@
|
|
|
30
19
|
.clampLbl {
|
|
31
20
|
display: -webkit-box;
|
|
32
21
|
-webkit-box-orient: vertical;
|
|
33
|
-
-webkit-line-clamp:
|
|
34
|
-
line-clamp:
|
|
22
|
+
-webkit-line-clamp: 1;
|
|
23
|
+
line-clamp: 1;
|
|
35
24
|
overflow: hidden;
|
|
36
25
|
}
|
|
37
26
|
.toggleLbl {
|
package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
6
|
+
import { Provider } from 'react-redux';
|
|
7
|
+
import { FormProvider, useForm } from 'react-hook-form';
|
|
8
|
+
import { configureStore } from '@reduxjs/toolkit';
|
|
9
|
+
import { EurekaFormsReducer, defaultRootState } from '../../Utils/store';
|
|
10
|
+
import { RootApi } from '../../Utils/_api';
|
|
11
|
+
import FormStepTypes from '../../constants/FormStepTypes';
|
|
12
|
+
import { StoreContext } from '../../Utils/StoreContext';
|
|
13
|
+
import FormContext, { IdFormContext } from '../../Contexts/FormContext';
|
|
14
|
+
import SectionContext from '../../Contexts/SectionContext';
|
|
15
|
+
import MaterialProviders from '../../Utils/MaterialProviders';
|
|
16
|
+
import InternalFormStyle from '../../constants/InternalFormStyle';
|
|
17
|
+
import ClassifierSelectorStep from './ClassifierSelectorStep';
|
|
18
|
+
const ID_FORM = 'LATE_CLASSIFIERS_FORM';
|
|
19
|
+
const step = {
|
|
20
|
+
id: 'tipo-step',
|
|
21
|
+
idSection: 'SECTION_1',
|
|
22
|
+
stepPath: ['tipo-step'],
|
|
23
|
+
type: FormStepTypes.CLASSIFIER_SELECTOR,
|
|
24
|
+
idClassifier: 'tipo',
|
|
25
|
+
label: 'Tipo de solicitud',
|
|
26
|
+
description: '',
|
|
27
|
+
searchable: true,
|
|
28
|
+
options: {},
|
|
29
|
+
required: false,
|
|
30
|
+
size: 2,
|
|
31
|
+
};
|
|
32
|
+
/** The project's classifiers, as the host resolves them (asynchronously) and passes them to the form. */
|
|
33
|
+
const classifiers = {
|
|
34
|
+
tipo: { _id: 'tipo', name: 'Tipo de solicitud', children: ['bug', 'mejora'] },
|
|
35
|
+
bug: { _id: 'bug', name: 'Error / Bug', children: [] },
|
|
36
|
+
mejora: { _id: 'mejora', name: 'Propuesta de mejora', children: [] },
|
|
37
|
+
};
|
|
38
|
+
const form = {
|
|
39
|
+
firstSection: 'SECTION_1',
|
|
40
|
+
sections: {
|
|
41
|
+
SECTION_1: { id: 'SECTION_1', name: 'Sección 1', steps: ['tipo-step'], nextSection: null },
|
|
42
|
+
},
|
|
43
|
+
steps: { 'tipo-step': step },
|
|
44
|
+
confirmationMessage: { blocks: [], entityMap: {} },
|
|
45
|
+
showLink: false,
|
|
46
|
+
size: { blockSize: 200, blockNum: 4, spacingSize: 10 },
|
|
47
|
+
};
|
|
48
|
+
function makeStore() {
|
|
49
|
+
return configureStore({
|
|
50
|
+
reducer: { forms: EurekaFormsReducer, [RootApi.reducerPath]: RootApi.reducer },
|
|
51
|
+
preloadedState: { forms: { [ID_FORM]: { ...defaultRootState } } },
|
|
52
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(RootApi.middleware),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function Harness({ store, formClassifiers, }) {
|
|
56
|
+
const methods = useForm({ mode: 'onTouched' });
|
|
57
|
+
return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: store, context: StoreContext, children: _jsx(IdFormContext.Provider, { value: ID_FORM, children: _jsx(FormContext.Provider, { value: { ...form, classifiers: formClassifiers }, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormProvider, { ...methods, children: _jsx(ClassifierSelectorStep, { step: step, editable: true }) }) }) }) }) }) }));
|
|
58
|
+
}
|
|
59
|
+
describe('ClassifierSelectorStep with classifiers that arrive after the first render', () => {
|
|
60
|
+
it('renders nothing while the classifiers are unknown, then the selector with its options', async () => {
|
|
61
|
+
const user = userEvent.setup();
|
|
62
|
+
const store = makeStore();
|
|
63
|
+
const { rerender } = render(_jsx(Harness, { store: store, formClassifiers: undefined }));
|
|
64
|
+
expect(screen.queryByRole('combobox')).not.toBeInTheDocument();
|
|
65
|
+
rerender(_jsx(Harness, { store: store, formClassifiers: classifiers }));
|
|
66
|
+
await user.click(await screen.findByRole('combobox'));
|
|
67
|
+
expect(await screen.findByRole('option', { name: 'Error / Bug' })).toBeInTheDocument();
|
|
68
|
+
expect(screen.getByRole('option', { name: 'Propuesta de mejora' })).toBeInTheDocument();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -50,8 +50,10 @@ function ClassifierSelectorStep({ step, editable }) {
|
|
|
50
50
|
};
|
|
51
51
|
}) ?? []);
|
|
52
52
|
},
|
|
53
|
+
// The classifiers dictionary can arrive after the first render (see useSetupApp), so the
|
|
54
|
+
// options must follow it, not only the dependency values.
|
|
53
55
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
-
[dependenciesValues]);
|
|
56
|
+
[dependenciesValues, classifier, form.classifiers]);
|
|
55
57
|
useEffect(() => {
|
|
56
58
|
if (value && !options?.find((option) => option.value === value?.value)) {
|
|
57
59
|
onChange('');
|
|
@@ -5,7 +5,7 @@ import SmartSelect from '../../SmartSelectStep/MaterialSmartSelectStep/MaterialS
|
|
|
5
5
|
import widgetInstance from '../../../Utils/AxiosWidget';
|
|
6
6
|
import FormContext, { IdFormContext } from '../../../Contexts/FormContext';
|
|
7
7
|
import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
|
|
8
|
-
import { recursivelyCalcConditionSteps, selectDependencies } from '../../StepHooks';
|
|
8
|
+
import { isStepHiddenByCondition, recursivelyCalcConditionSteps, selectDependencies } from '../../StepHooks';
|
|
9
9
|
import { useApiSubscribe, useAppSelector } from '../../../hooks';
|
|
10
10
|
import MaterialEntityValueDialog from './MaterialEntityValueDialog/MaterialEntityValueDialog';
|
|
11
11
|
import InputIcon from '../../../Shared/InputIcon/InputIcon';
|
|
@@ -13,6 +13,8 @@ import { evaluateCondition } from '../../StepFunctions';
|
|
|
13
13
|
import StepComponent from '../../Step';
|
|
14
14
|
import ErkValueTypes from '../../../constants/ErkValueTypes';
|
|
15
15
|
import { IntegrationsApi } from '../../../Services/IntegrationService';
|
|
16
|
+
import { entityValueDependencyValue } from '../entityValueDependencyValue';
|
|
17
|
+
import { entityValuePickerWatchedSteps } from '../entityValuePickerWatchedSteps';
|
|
16
18
|
function EntityValuePickerStep({ step, editable }) {
|
|
17
19
|
const form = useContext(FormContext);
|
|
18
20
|
const subscribe = useApiSubscribe();
|
|
@@ -25,8 +27,23 @@ function EntityValuePickerStep({ step, editable }) {
|
|
|
25
27
|
}))) ?? []);
|
|
26
28
|
}, [subscribe, idForm]);
|
|
27
29
|
const getOptions = useCallback(async (step, dependencyStore, ids) => {
|
|
28
|
-
return await getEntityValueOptions(step, dependencyStore, ids, fetchFilterIntegration);
|
|
29
|
-
}, [fetchFilterIntegration]);
|
|
30
|
+
return await getEntityValueOptions(step, dependencyStore, ids, fetchFilterIntegration, form);
|
|
31
|
+
}, [fetchFilterIntegration, form]);
|
|
32
|
+
// The visibility of a filter's step decides whether that filter applies, so the steps its condition
|
|
33
|
+
// reads must trigger a refetch too — see `isStepHiddenByCondition`.
|
|
34
|
+
const getOptionalDependencies = useCallback((picker) => {
|
|
35
|
+
const watched = entityValuePickerWatchedSteps(picker);
|
|
36
|
+
for (const idWatched of [...watched]) {
|
|
37
|
+
for (const idCondition of recursivelyCalcConditionSteps(form.steps[idWatched]?.condition)) {
|
|
38
|
+
if (idCondition === picker.id || watched.includes(idCondition))
|
|
39
|
+
continue;
|
|
40
|
+
if (picker.dependencies?.includes(idCondition))
|
|
41
|
+
continue;
|
|
42
|
+
watched.push(idCondition);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return watched;
|
|
46
|
+
}, [form]);
|
|
30
47
|
const [dialogs, setDialogs] = useState();
|
|
31
48
|
const dialogsIdStepDeps = useMemo(() => {
|
|
32
49
|
const ids = [];
|
|
@@ -111,7 +128,7 @@ function EntityValuePickerStep({ step, editable }) {
|
|
|
111
128
|
} }) })] }));
|
|
112
129
|
}
|
|
113
130
|
export default EntityValuePickerStep;
|
|
114
|
-
const getEntityValueOptions = async (step, dependencyStore, { idOrganization, idCurrentAgent, }, fetchFilterIntegration) => {
|
|
131
|
+
const getEntityValueOptions = async (step, dependencyStore, { idOrganization, idCurrentAgent, }, fetchFilterIntegration, form) => {
|
|
115
132
|
if (!idOrganization)
|
|
116
133
|
return null;
|
|
117
134
|
let urlPath = '';
|
|
@@ -173,14 +190,12 @@ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, id
|
|
|
173
190
|
break;
|
|
174
191
|
}
|
|
175
192
|
case EntityValueDataTypes.STEP: {
|
|
176
|
-
const currentValue = dependencyStore[filter.idStep]
|
|
177
|
-
if (currentValue) {
|
|
178
|
-
|
|
179
|
-
params.set(filter.idProperty, currentValue);
|
|
180
|
-
else
|
|
181
|
-
params.set(filter.idProperty, currentValue._id ?? currentValue.id);
|
|
193
|
+
const currentValue = entityValueDependencyValue(dependencyStore[filter.idStep]);
|
|
194
|
+
if (currentValue !== undefined) {
|
|
195
|
+
params.set(filter.idProperty, currentValue);
|
|
182
196
|
}
|
|
183
|
-
else if (filter.required) {
|
|
197
|
+
else if (filter.required && !isStepHiddenByCondition(filter.idStep, form, dependencyStore)) {
|
|
198
|
+
// A required filter blocks only while its step can still be answered.
|
|
184
199
|
return null;
|
|
185
200
|
}
|
|
186
201
|
break;
|
|
@@ -201,18 +216,3 @@ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, id
|
|
|
201
216
|
});
|
|
202
217
|
return response.data.filter((option) => step.options[option._id]?.type !== EntityValueOptionTypes.HIDE);
|
|
203
218
|
};
|
|
204
|
-
const getOptionalDependencies = (step) => {
|
|
205
|
-
const optional = [];
|
|
206
|
-
for (const filter of step.filters) {
|
|
207
|
-
switch (filter.type) {
|
|
208
|
-
case EntityValueDataTypes.STEP: {
|
|
209
|
-
if (filter.idStep && !filter.required && !step.dependencies?.includes(filter.idStep))
|
|
210
|
-
optional.push(filter.idStep);
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
default:
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return optional;
|
|
218
|
-
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StepDependency } from '../../Form/Form';
|
|
2
|
+
/**
|
|
3
|
+
* Serializes the current value of a dependency step into the string an entity-picker STEP filter
|
|
4
|
+
* sends as `values.<idProperty>` query param.
|
|
5
|
+
*
|
|
6
|
+
* Entity values (and any id-bearing object) resolve to their id. The answer of a Selector or
|
|
7
|
+
* Classifier step is a `{ label, value }` option: a Selector keeps `value === label`, so its `value`
|
|
8
|
+
* is the text the entity property stores; a Classifier's `value` is the classifier id, which no
|
|
9
|
+
* entity property holds, so it resolves to its `label`. Returns undefined when the dependency has
|
|
10
|
+
* no usable value, so the caller treats the filter as unresolved.
|
|
11
|
+
*/
|
|
12
|
+
export declare function entityValueDependencyValue(dependency: StepDependency | undefined): string | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import FormStepTypes from '../../constants/FormStepTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Serializes the current value of a dependency step into the string an entity-picker STEP filter
|
|
4
|
+
* sends as `values.<idProperty>` query param.
|
|
5
|
+
*
|
|
6
|
+
* Entity values (and any id-bearing object) resolve to their id. The answer of a Selector or
|
|
7
|
+
* Classifier step is a `{ label, value }` option: a Selector keeps `value === label`, so its `value`
|
|
8
|
+
* is the text the entity property stores; a Classifier's `value` is the classifier id, which no
|
|
9
|
+
* entity property holds, so it resolves to its `label`. Returns undefined when the dependency has
|
|
10
|
+
* no usable value, so the caller treats the filter as unresolved.
|
|
11
|
+
*/
|
|
12
|
+
export function entityValueDependencyValue(dependency) {
|
|
13
|
+
const currentValue = dependency?.value;
|
|
14
|
+
if (currentValue === null || currentValue === undefined || currentValue === '')
|
|
15
|
+
return undefined;
|
|
16
|
+
if (typeof currentValue === 'string')
|
|
17
|
+
return currentValue;
|
|
18
|
+
if (typeof currentValue === 'number' || typeof currentValue === 'boolean')
|
|
19
|
+
return String(currentValue);
|
|
20
|
+
if (currentValue instanceof Date)
|
|
21
|
+
return currentValue.toISOString();
|
|
22
|
+
if (typeof currentValue !== 'object')
|
|
23
|
+
return undefined;
|
|
24
|
+
const record = currentValue;
|
|
25
|
+
// A Selector's `value` is the stored text; every other step's `value` may be an id, so its `label` wins.
|
|
26
|
+
const keys = dependency?.type === FormStepTypes.SELECTOR ? ['_id', 'id', 'value', 'label'] : ['_id', 'id', 'label', 'value'];
|
|
27
|
+
for (const key of keys) {
|
|
28
|
+
const candidate = record[key];
|
|
29
|
+
if (typeof candidate === 'string' && candidate !== '')
|
|
30
|
+
return candidate;
|
|
31
|
+
if (typeof candidate === 'number')
|
|
32
|
+
return String(candidate);
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import FormStepTypes from '../../constants/FormStepTypes';
|
|
3
|
+
import { entityValueDependencyValue } from './entityValueDependencyValue';
|
|
4
|
+
const dep = (type, value) => ({
|
|
5
|
+
idOriginal: 'dep',
|
|
6
|
+
dependents: [],
|
|
7
|
+
type,
|
|
8
|
+
value,
|
|
9
|
+
});
|
|
10
|
+
describe('entityValueDependencyValue', () => {
|
|
11
|
+
test('an unanswered dependency is unresolved', () => {
|
|
12
|
+
expect(entityValueDependencyValue(undefined)).toBeUndefined();
|
|
13
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, null))).toBeUndefined();
|
|
14
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, ''))).toBeUndefined();
|
|
15
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, {}))).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
test('plain answers are sent as text', () => {
|
|
18
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.TEXTINPUT, 'Torre 3'))).toBe('Torre 3');
|
|
19
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.TEXTINPUT, 7))).toBe('7');
|
|
20
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.DATEPICKER, new Date('2026-01-02T00:00:00.000Z')))).toBe('2026-01-02T00:00:00.000Z');
|
|
21
|
+
});
|
|
22
|
+
test('an entity value resolves to its id', () => {
|
|
23
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.ENTITYVALUEPICKER, { _id: 'ev-1', label: 'Morros' }))).toBe('ev-1');
|
|
24
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.API_SELECTOR, { id: 'api-1', label: 'X' }))).toBe('api-1');
|
|
25
|
+
});
|
|
26
|
+
test('a selector option resolves to its value, a classifier option to its label', () => {
|
|
27
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, { label: 'Piso 2', value: 'Piso 2' }))).toBe('Piso 2');
|
|
28
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, { label: 'Dos', value: '2' }))).toBe('2');
|
|
29
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.CLASSIFIER_SELECTOR, { label: 'Piso 2', value: '65f0c1a2b3c4d5e6f7a8b9c0' }))).toBe('Piso 2');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EntityValuePicker } from '../../@Types/FormStep';
|
|
2
|
+
/**
|
|
3
|
+
* The steps an entity picker reads a value from that `step.dependencies` does not already list:
|
|
4
|
+
* the STEP hops of `step.path` and every STEP filter, required or not.
|
|
5
|
+
*
|
|
6
|
+
* `step.dependencies` is recomputed server-side only when the form is saved
|
|
7
|
+
* (`FormDependencyFunctions.calcStepDependencies`), so it describes the form as it was at the last
|
|
8
|
+
* save. In the editor's live preview of an unsaved draft — and in any form whose stored
|
|
9
|
+
* dependencies went stale — a path hop or a filter added since then is missing from it, and the
|
|
10
|
+
* renderer would never watch the step it points at. The picker refetches its options when a watched
|
|
11
|
+
* value changes, so a filter the picker does not watch never triggers the fetch that would honour
|
|
12
|
+
* it: a required one leaves the select stuck with no options at all, an optional one leaves it
|
|
13
|
+
* showing options the filter should have narrowed.
|
|
14
|
+
*
|
|
15
|
+
* The `required` flag is deliberately not consulted: required or not, the filter's value is what
|
|
16
|
+
* has to trigger the refetch. Steps the last save already registered are skipped because the
|
|
17
|
+
* renderer watches `step.dependencies` anyway.
|
|
18
|
+
*/
|
|
19
|
+
export declare function entityValuePickerWatchedSteps(step: EntityValuePicker): string[];
|
|
20
|
+
/**
|
|
21
|
+
* The subset of `entityValuePickerWatchedSteps` whose value the picker cannot do without: every
|
|
22
|
+
* STEP hop of the path, and the STEP filters flagged `required`. Those are exactly the cases where
|
|
23
|
+
* `getEntityValueOptions` gives up and answers `null` — its "dependency not met" contract — so
|
|
24
|
+
* while they hold no value the select has to read as a missing dependency rather than as a failed
|
|
25
|
+
* load.
|
|
26
|
+
*/
|
|
27
|
+
export declare function entityValuePickerBlockingSteps(step: EntityValuePicker): string[];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EntityValueDataTypes } from '../../constants/FormStepTypes';
|
|
2
|
+
const push = (step, idStep, into) => {
|
|
3
|
+
if (!idStep)
|
|
4
|
+
return;
|
|
5
|
+
/**
|
|
6
|
+
* A draft can point a filter or a path hop at the picker that holds it (the editor lists the
|
|
7
|
+
* step among the pickable ones before the form is saved and the backend rejects it). A step is
|
|
8
|
+
* never its own dependency, and watching itself would close a cycle in the dependency walk.
|
|
9
|
+
*/
|
|
10
|
+
if (idStep === step.id)
|
|
11
|
+
return;
|
|
12
|
+
if (step.dependencies?.includes(idStep))
|
|
13
|
+
return;
|
|
14
|
+
if (!into.includes(idStep))
|
|
15
|
+
into.push(idStep);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The steps an entity picker reads a value from that `step.dependencies` does not already list:
|
|
19
|
+
* the STEP hops of `step.path` and every STEP filter, required or not.
|
|
20
|
+
*
|
|
21
|
+
* `step.dependencies` is recomputed server-side only when the form is saved
|
|
22
|
+
* (`FormDependencyFunctions.calcStepDependencies`), so it describes the form as it was at the last
|
|
23
|
+
* save. In the editor's live preview of an unsaved draft — and in any form whose stored
|
|
24
|
+
* dependencies went stale — a path hop or a filter added since then is missing from it, and the
|
|
25
|
+
* renderer would never watch the step it points at. The picker refetches its options when a watched
|
|
26
|
+
* value changes, so a filter the picker does not watch never triggers the fetch that would honour
|
|
27
|
+
* it: a required one leaves the select stuck with no options at all, an optional one leaves it
|
|
28
|
+
* showing options the filter should have narrowed.
|
|
29
|
+
*
|
|
30
|
+
* The `required` flag is deliberately not consulted: required or not, the filter's value is what
|
|
31
|
+
* has to trigger the refetch. Steps the last save already registered are skipped because the
|
|
32
|
+
* renderer watches `step.dependencies` anyway.
|
|
33
|
+
*/
|
|
34
|
+
export function entityValuePickerWatchedSteps(step) {
|
|
35
|
+
const watched = [];
|
|
36
|
+
for (const path of step.path) {
|
|
37
|
+
if (path.type === EntityValueDataTypes.STEP)
|
|
38
|
+
push(step, path.idStep, watched);
|
|
39
|
+
}
|
|
40
|
+
for (const filter of step.filters) {
|
|
41
|
+
if (filter.type === EntityValueDataTypes.STEP)
|
|
42
|
+
push(step, filter.idStep, watched);
|
|
43
|
+
}
|
|
44
|
+
return watched;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The subset of `entityValuePickerWatchedSteps` whose value the picker cannot do without: every
|
|
48
|
+
* STEP hop of the path, and the STEP filters flagged `required`. Those are exactly the cases where
|
|
49
|
+
* `getEntityValueOptions` gives up and answers `null` — its "dependency not met" contract — so
|
|
50
|
+
* while they hold no value the select has to read as a missing dependency rather than as a failed
|
|
51
|
+
* load.
|
|
52
|
+
*/
|
|
53
|
+
export function entityValuePickerBlockingSteps(step) {
|
|
54
|
+
const blocking = [];
|
|
55
|
+
for (const path of step.path) {
|
|
56
|
+
if (path.type === EntityValueDataTypes.STEP)
|
|
57
|
+
push(step, path.idStep, blocking);
|
|
58
|
+
}
|
|
59
|
+
for (const filter of step.filters) {
|
|
60
|
+
if (filter.type === EntityValueDataTypes.STEP && filter.required)
|
|
61
|
+
push(step, filter.idStep, blocking);
|
|
62
|
+
}
|
|
63
|
+
return blocking;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import FormStepTypes, { EntityValueDataTypes } from '../../constants/FormStepTypes';
|
|
3
|
+
import { entityValuePickerBlockingSteps, entityValuePickerWatchedSteps } from './entityValuePickerWatchedSteps';
|
|
4
|
+
const picker = (picker) => ({
|
|
5
|
+
id: 'picker',
|
|
6
|
+
idSection: 'section',
|
|
7
|
+
type: FormStepTypes.ENTITYVALUEPICKER,
|
|
8
|
+
idEntity: 'entity',
|
|
9
|
+
path: [],
|
|
10
|
+
filters: [],
|
|
11
|
+
options: {},
|
|
12
|
+
...picker,
|
|
13
|
+
});
|
|
14
|
+
const stepFilter = (idStep, required) => ({
|
|
15
|
+
idProperty: 'prop-' + idStep,
|
|
16
|
+
type: EntityValueDataTypes.STEP,
|
|
17
|
+
idStep,
|
|
18
|
+
any: false,
|
|
19
|
+
required,
|
|
20
|
+
});
|
|
21
|
+
const stepPath = (idStep) => ({
|
|
22
|
+
idEntity: 'parent',
|
|
23
|
+
type: EntityValueDataTypes.STEP,
|
|
24
|
+
idStep,
|
|
25
|
+
any: false,
|
|
26
|
+
});
|
|
27
|
+
describe('entityValuePickerWatchedSteps', () => {
|
|
28
|
+
test('watches a STEP filter the saved dependencies do not list, required or not', () => {
|
|
29
|
+
const step = picker({ filters: [stepFilter('required', true), stepFilter('optional', false)] });
|
|
30
|
+
expect(entityValuePickerWatchedSteps(step)).toEqual(['required', 'optional']);
|
|
31
|
+
});
|
|
32
|
+
test('skips the steps the last save already registered', () => {
|
|
33
|
+
const step = picker({
|
|
34
|
+
dependencies: ['required'],
|
|
35
|
+
filters: [stepFilter('required', true), stepFilter('optional', false)],
|
|
36
|
+
});
|
|
37
|
+
expect(entityValuePickerWatchedSteps(step)).toEqual(['optional']);
|
|
38
|
+
});
|
|
39
|
+
test('watches the STEP hops of an unsaved path', () => {
|
|
40
|
+
const step = picker({
|
|
41
|
+
dependencies: ['saved'],
|
|
42
|
+
path: [stepPath('saved'), stepPath('added'), { idEntity: 'e', type: EntityValueDataTypes.VALUE }],
|
|
43
|
+
});
|
|
44
|
+
expect(entityValuePickerWatchedSteps(step)).toEqual(['added']);
|
|
45
|
+
});
|
|
46
|
+
test('ignores filters that read no step, and a path hop with no step picked yet', () => {
|
|
47
|
+
const step = picker({
|
|
48
|
+
path: [{ idEntity: 'e', type: EntityValueDataTypes.STEP, any: true }],
|
|
49
|
+
filters: [
|
|
50
|
+
{ idProperty: 'a', type: EntityValueDataTypes.VALUE, value: 'x' },
|
|
51
|
+
{ idProperty: 'b', type: EntityValueDataTypes.CURRENT_AGENT },
|
|
52
|
+
{ idProperty: 'c', type: EntityValueDataTypes.INTEGRATION, idIntegration: 'i', values: {} },
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
expect(entityValuePickerWatchedSteps(step)).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
test('never repeats a step read twice', () => {
|
|
58
|
+
const step = picker({
|
|
59
|
+
path: [stepPath('shared')],
|
|
60
|
+
filters: [stepFilter('shared', true)],
|
|
61
|
+
});
|
|
62
|
+
expect(entityValuePickerWatchedSteps(step)).toEqual(['shared']);
|
|
63
|
+
});
|
|
64
|
+
test('ignores a draft filter or path hop pointing back at the picker itself', () => {
|
|
65
|
+
const step = picker({
|
|
66
|
+
path: [stepPath('picker'), stepPath('hop')],
|
|
67
|
+
filters: [stepFilter('picker', true), stepFilter('picker', false), stepFilter('other', false)],
|
|
68
|
+
});
|
|
69
|
+
expect(entityValuePickerWatchedSteps(step)).toEqual(['hop', 'other']);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('entityValuePickerBlockingSteps', () => {
|
|
73
|
+
test('only the path hops and the required filters block the fetch', () => {
|
|
74
|
+
const step = picker({
|
|
75
|
+
path: [stepPath('hop')],
|
|
76
|
+
filters: [stepFilter('required', true), stepFilter('optional', false)],
|
|
77
|
+
});
|
|
78
|
+
expect(entityValuePickerBlockingSteps(step)).toEqual(['hop', 'required']);
|
|
79
|
+
});
|
|
80
|
+
test('a saved dependency is already watched deeply, so it is not repeated', () => {
|
|
81
|
+
const step = picker({
|
|
82
|
+
dependencies: ['hop', 'required'],
|
|
83
|
+
path: [stepPath('hop')],
|
|
84
|
+
filters: [stepFilter('required', true)],
|
|
85
|
+
});
|
|
86
|
+
expect(entityValuePickerBlockingSteps(step)).toEqual([]);
|
|
87
|
+
});
|
|
88
|
+
test('ignores a draft filter or path hop pointing back at the picker itself', () => {
|
|
89
|
+
const step = picker({
|
|
90
|
+
path: [stepPath('picker')],
|
|
91
|
+
filters: [stepFilter('picker', true)],
|
|
92
|
+
});
|
|
93
|
+
expect(entityValuePickerBlockingSteps(step)).toEqual([]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LocationStep } from '../../@Types/LocationFormStep';
|
|
2
|
+
import { StepProps } from '../Step';
|
|
3
|
+
export interface LocationStepProps extends StepProps {
|
|
4
|
+
/** The LocationStep to display */
|
|
5
|
+
step: LocationStep;
|
|
6
|
+
/** The icon to display */
|
|
7
|
+
IconComponent?: React.ElementType;
|
|
8
|
+
}
|
|
9
|
+
declare function LocationStepComponent(props: LocationStepProps): JSX.Element;
|
|
10
|
+
export default LocationStepComponent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FormStyleTypes } from '../../constants/FormStepTypes';
|
|
3
|
+
import MaterialLocationStep from './MaterialLocationStep/MaterialLocationStep';
|
|
4
|
+
import { useAppSelector } from '../../hooks';
|
|
5
|
+
function LocationStepComponent(props) {
|
|
6
|
+
const { formStyle } = useAppSelector((state) => state.global);
|
|
7
|
+
switch (formStyle.type) {
|
|
8
|
+
case FormStyleTypes.MATERIAL:
|
|
9
|
+
default: {
|
|
10
|
+
return _jsx(MaterialLocationStep, { ...props });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export default LocationStepComponent;
|