@arquimedes.co/eureka-forms 3.0.67 → 3.0.68-test
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 +1 -33
- package/dist/@Types/FormStep.d.ts +2 -7
- package/dist/@Types/FormStep.js +1 -2
- package/dist/App/App.stories.d.ts +0 -10
- package/dist/App/App.stories.js +0 -189
- package/dist/App/AppHooks.js +0 -8
- package/dist/App/AppHooks.test.js +0 -8
- package/dist/Form/Form.js +6 -7
- package/dist/Form/FormFunctions.d.ts +0 -17
- package/dist/Form/FormFunctions.js +0 -22
- package/dist/Form/FormFunctions.test.js +1 -28
- package/dist/FormSteps/CheckBoxStep/CheckBoxStep.mobileLabel.test.js +12 -20
- package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.js +13 -6
- package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.module.css +13 -2
- package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +1 -3
- package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +26 -26
- package/dist/FormSteps/Step.js +0 -16
- package/dist/FormSteps/StepFunctions.js +0 -14
- package/dist/FormSteps/StepFunctions.test.js +0 -54
- package/dist/FormSteps/StepHooks.d.ts +0 -21
- package/dist/FormSteps/StepHooks.js +8 -55
- package/dist/Shared/ErkDatePicker/ErkDatePicker.js +12 -4
- package/dist/Shared/ErkDatePicker/ErkDatePicker.locale.test.js +39 -0
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +3 -2
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +16 -11
- package/dist/Shared/ErkSelect/ErkSelect.js +9 -1
- package/dist/Shared/ErkSelect/ErkSelect.test.d.ts +2 -0
- package/dist/Shared/ErkSelect/ErkSelect.test.js +53 -0
- package/dist/Shared/ErkTimePicker/ErkTimePicker.js +8 -1
- package/dist/Shared/ErkTimePicker/ErkTimePicker.test.d.ts +2 -0
- package/dist/Shared/ErkTimePicker/ErkTimePicker.test.js +24 -0
- package/dist/Utils/AxiosWidget.js +1 -9
- package/dist/Utils/LocaleUtils.d.ts +1 -0
- package/dist/Utils/LocaleUtils.js +10 -3
- package/dist/constants/FormStepTypes.d.ts +1 -5
- package/dist/constants/FormStepTypes.js +0 -4
- package/dist/index.lib.d.ts +2 -4
- package/dist/index.lib.js +1 -3
- package/package.json +1 -2
- package/dist/@Types/AvailabilityFormStep.d.ts +0 -48
- package/dist/@Types/AvailabilityFormStep.js +0 -24
- package/dist/@Types/BankAccountFormStep.d.ts +0 -67
- package/dist/@Types/BankAccountFormStep.js +0 -14
- package/dist/@Types/BookingFormStep.d.ts +0 -187
- package/dist/@Types/BookingFormStep.js +0 -44
- package/dist/@Types/CalendarFormStep.d.ts +0 -209
- package/dist/@Types/CalendarFormStep.js +0 -55
- package/dist/@Types/CommunicationChannelFormStep.d.ts +0 -51
- package/dist/@Types/CommunicationChannelFormStep.js +0 -15
- package/dist/@Types/ConsentFormStep.d.ts +0 -36
- package/dist/@Types/ConsentFormStep.js +0 -8
- package/dist/@Types/EntityFormFormStep.d.ts +0 -66
- package/dist/@Types/EntityFormFormStep.js +0 -20
- package/dist/@Types/EventFormStep.d.ts +0 -52
- package/dist/@Types/EventFormStep.js +0 -13
- package/dist/@Types/ExternalReferenceFormStep.d.ts +0 -74
- package/dist/@Types/ExternalReferenceFormStep.js +0 -20
- package/dist/@Types/LocationFormStep.d.ts +0 -159
- package/dist/@Types/LocationFormStep.js +0 -46
- package/dist/@Types/NumericFormSteps.d.ts +0 -108
- package/dist/@Types/NumericFormSteps.js +0 -20
- package/dist/@Types/PredefinedSelectorFormStep.d.ts +0 -51
- package/dist/@Types/PredefinedSelectorFormStep.js +0 -39
- package/dist/@Types/StepRef.d.ts +0 -135
- package/dist/@Types/StepRef.js +0 -49
- package/dist/FormSteps/AvailabilityStep/AvailabilityStep.d.ts +0 -7
- package/dist/FormSteps/AvailabilityStep/AvailabilityStep.js +0 -14
- package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.d.ts +0 -8
- package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.js +0 -32
- package/dist/FormSteps/BookingStep/BookingStep.d.ts +0 -17
- package/dist/FormSteps/BookingStep/BookingStep.js +0 -14
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.d.ts +0 -7
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.js +0 -32
- package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.js +0 -70
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.d.ts +0 -12
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.js +0 -35
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.d.ts +0 -1
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.js +0 -31
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.d.ts +0 -27
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.js +0 -64
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.d.ts +0 -1
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.js +0 -95
- package/dist/FormSteps/LocationStep/LocationStep.d.ts +0 -10
- package/dist/FormSteps/LocationStep/LocationStep.js +0 -14
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.d.ts +0 -3
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.js +0 -54
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.module.css +0 -18
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.d.ts +0 -3
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.js +0 -170
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.module.css +0 -96
- package/dist/FormSteps/NumberStep/NumberStep.d.ts +0 -10
- package/dist/FormSteps/NumberStep/NumberStep.js +0 -14
- package/dist/FormSteps/StepHooks.test.d.ts +0 -1
- package/dist/FormSteps/StepHooks.test.js +0 -92
- package/dist/FormSteps/isStepHiddenByCondition.test.d.ts +0 -1
- package/dist/FormSteps/isStepHiddenByCondition.test.js +0 -42
- package/dist/Icons/AddIcon.d.ts +0 -3
- package/dist/Icons/AddIcon.js +0 -7
- package/dist/Icons/EditIcon.d.ts +0 -3
- package/dist/Icons/EditIcon.js +0 -7
- package/dist/Icons/RemoveIcon.d.ts +0 -3
- package/dist/Icons/RemoveIcon.js +0 -7
- package/dist/Icons/ViewDayIcon.d.ts +0 -3
- package/dist/Icons/ViewDayIcon.js +0 -7
- package/dist/Icons/ViewWeekIcon.d.ts +0 -3
- package/dist/Icons/ViewWeekIcon.js +0 -7
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.d.ts +0 -19
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.js +0 -80
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.module.css +0 -88
- package/dist/Shared/ErkAddressAutocomplete/googlePlaces.d.ts +0 -29
- package/dist/Shared/ErkAddressAutocomplete/googlePlaces.js +0 -139
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.d.ts +0 -25
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.js +0 -112
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.module.css +0 -88
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.d.ts +0 -1
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.js +0 -73
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.d.ts +0 -31
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.js +0 -228
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.module.css +0 -608
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.d.ts +0 -28
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.js +0 -117
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.d.ts +0 -1
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.js +0 -49
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.d.ts +0 -1
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.js +0 -107
- package/dist/Shared/ErkIconButton/ErkIconButton.d.ts +0 -17
- package/dist/Shared/ErkIconButton/ErkIconButton.js +0 -11
- package/dist/Shared/ErkIconButton/ErkIconButton.module.css +0 -41
- package/dist/Shared/ErkLocationField/ErkLocationField.d.ts +0 -24
- package/dist/Shared/ErkLocationField/ErkLocationField.js +0 -128
- package/dist/Shared/ErkLocationField/ErkLocationField.module.css +0 -164
- package/dist/Shared/ErkLocationField/ErkLocationField.test.d.ts +0 -1
- package/dist/Shared/ErkLocationField/ErkLocationField.test.js +0 -82
- package/dist/Shared/ErkLocationField/addressFields.d.ts +0 -12
- package/dist/Shared/ErkLocationField/addressFields.js +0 -34
- package/dist/Shared/ErkLocationField/locationRestrictions.d.ts +0 -6
- package/dist/Shared/ErkLocationField/locationRestrictions.js +0 -51
- package/dist/Shared/ErkLocationInput/ErkLocationInput.d.ts +0 -15
- package/dist/Shared/ErkLocationInput/ErkLocationInput.js +0 -502
- package/dist/Shared/ErkLocationInput/ErkLocationInput.module.css +0 -128
- package/dist/Shared/ErkNumberField/ErkNumberField.d.ts +0 -42
- package/dist/Shared/ErkNumberField/ErkNumberField.js +0 -169
- /package/dist/{FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.d.ts → Shared/ErkDatePicker/ErkDatePicker.locale.test.d.ts} +0 -0
|
@@ -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 {
|
|
8
|
+
import { 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,8 +13,6 @@ 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';
|
|
18
16
|
function EntityValuePickerStep({ step, editable }) {
|
|
19
17
|
const form = useContext(FormContext);
|
|
20
18
|
const subscribe = useApiSubscribe();
|
|
@@ -27,23 +25,8 @@ function EntityValuePickerStep({ step, editable }) {
|
|
|
27
25
|
}))) ?? []);
|
|
28
26
|
}, [subscribe, idForm]);
|
|
29
27
|
const getOptions = useCallback(async (step, dependencyStore, ids) => {
|
|
30
|
-
return await getEntityValueOptions(step, dependencyStore, ids, fetchFilterIntegration
|
|
31
|
-
}, [fetchFilterIntegration
|
|
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]);
|
|
28
|
+
return await getEntityValueOptions(step, dependencyStore, ids, fetchFilterIntegration);
|
|
29
|
+
}, [fetchFilterIntegration]);
|
|
47
30
|
const [dialogs, setDialogs] = useState();
|
|
48
31
|
const dialogsIdStepDeps = useMemo(() => {
|
|
49
32
|
const ids = [];
|
|
@@ -128,7 +111,7 @@ function EntityValuePickerStep({ step, editable }) {
|
|
|
128
111
|
} }) })] }));
|
|
129
112
|
}
|
|
130
113
|
export default EntityValuePickerStep;
|
|
131
|
-
const getEntityValueOptions = async (step, dependencyStore, { idOrganization, idCurrentAgent, }, fetchFilterIntegration
|
|
114
|
+
const getEntityValueOptions = async (step, dependencyStore, { idOrganization, idCurrentAgent, }, fetchFilterIntegration) => {
|
|
132
115
|
if (!idOrganization)
|
|
133
116
|
return null;
|
|
134
117
|
let urlPath = '';
|
|
@@ -190,12 +173,14 @@ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, id
|
|
|
190
173
|
break;
|
|
191
174
|
}
|
|
192
175
|
case EntityValueDataTypes.STEP: {
|
|
193
|
-
const currentValue =
|
|
194
|
-
if (currentValue
|
|
195
|
-
|
|
176
|
+
const currentValue = dependencyStore[filter.idStep]?.value;
|
|
177
|
+
if (currentValue) {
|
|
178
|
+
if (typeof currentValue === 'string')
|
|
179
|
+
params.set(filter.idProperty, currentValue);
|
|
180
|
+
else
|
|
181
|
+
params.set(filter.idProperty, currentValue._id ?? currentValue.id);
|
|
196
182
|
}
|
|
197
|
-
else if (filter.required
|
|
198
|
-
// A required filter blocks only while its step can still be answered.
|
|
183
|
+
else if (filter.required) {
|
|
199
184
|
return null;
|
|
200
185
|
}
|
|
201
186
|
break;
|
|
@@ -216,3 +201,18 @@ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, id
|
|
|
216
201
|
});
|
|
217
202
|
return response.data.filter((option) => step.options[option._id]?.type !== EntityValueOptionTypes.HIDE);
|
|
218
203
|
};
|
|
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
|
+
};
|
package/dist/FormSteps/Step.js
CHANGED
|
@@ -24,10 +24,6 @@ import CustomContext from '../Contexts/CustomContext';
|
|
|
24
24
|
import { selectOriginalValue, useCondition } from './StepHooks';
|
|
25
25
|
import TimePickerStep from './TimePickerStep/TimePickerStep';
|
|
26
26
|
import PhoneInputStep from './PhoneInputStep/PhoneInputStep';
|
|
27
|
-
import LocationStepComponent from './LocationStep/LocationStep';
|
|
28
|
-
import NumberStepComponent from './NumberStep/NumberStep';
|
|
29
|
-
import BookingStepComponent from './BookingStep/BookingStep';
|
|
30
|
-
import AvailabilityStepComponent from './AvailabilityStep/AvailabilityStep';
|
|
31
27
|
function StepComponent({ step, ...props }) {
|
|
32
28
|
const { postview, partial } = useAppSelector((state) => state.global);
|
|
33
29
|
const { customSteps, customClientInfoStep } = useContext(CustomContext);
|
|
@@ -79,18 +75,6 @@ function StepComponent({ step, ...props }) {
|
|
|
79
75
|
case FormStepTypes.DATEPICKER: {
|
|
80
76
|
return _jsx(DatePickerStep, { ...props, step: step, editable: editable });
|
|
81
77
|
}
|
|
82
|
-
case FormStepTypes.LOCATION: {
|
|
83
|
-
return _jsx(LocationStepComponent, { ...props, step: step, editable: editable });
|
|
84
|
-
}
|
|
85
|
-
case FormStepTypes.NUMBER: {
|
|
86
|
-
return _jsx(NumberStepComponent, { ...props, step: step, editable: editable });
|
|
87
|
-
}
|
|
88
|
-
case FormStepTypes.BOOKING: {
|
|
89
|
-
return _jsx(BookingStepComponent, { ...props, step: step, editable: editable });
|
|
90
|
-
}
|
|
91
|
-
case FormStepTypes.AVAILABILITY: {
|
|
92
|
-
return _jsx(AvailabilityStepComponent, { ...props, step: step, editable: editable });
|
|
93
|
-
}
|
|
94
78
|
case FormStepTypes.DATEPICKER_RANGE: {
|
|
95
79
|
return _jsx(DatePickerRangeStep, { ...props, step: step, editable: editable });
|
|
96
80
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { NumberStepType, } from '../@Types/FormStep';
|
|
2
1
|
import FormStepTypes, { ApiSelectorOptionTypes, ClassifierOptionTypes, EntityValueDataTypes, EntityValueOptionTypes, OptionTypes, } from '../constants/FormStepTypes';
|
|
3
2
|
import CBRFormStepTypes from '../constants/CBRFormStepTypes';
|
|
4
3
|
import AYFFormStepTypes from '../constants/AYFFormStepTypes';
|
|
@@ -88,8 +87,6 @@ function recursivelyCheckOpenSize(idStep, steps, values) {
|
|
|
88
87
|
return size;
|
|
89
88
|
}
|
|
90
89
|
case FormStepTypes.DATEPICKER:
|
|
91
|
-
case FormStepTypes.LOCATION:
|
|
92
|
-
case FormStepTypes.NUMBER:
|
|
93
90
|
case FormStepTypes.TEXTINPUT: {
|
|
94
91
|
return step.size;
|
|
95
92
|
}
|
|
@@ -178,17 +175,6 @@ export const calcDefaultValue = (step) => {
|
|
|
178
175
|
return getRawText();
|
|
179
176
|
else
|
|
180
177
|
return '';
|
|
181
|
-
case FormStepTypes.LOCATION:
|
|
182
|
-
return step.defaultValue ?? null;
|
|
183
|
-
case FormStepTypes.NUMBER: {
|
|
184
|
-
const numStep = step;
|
|
185
|
-
if (numStep.numberType === NumberStepType.MONEY ||
|
|
186
|
-
numStep.numberType === NumberStepType.MEASURE ||
|
|
187
|
-
numStep.numberType === NumberStepType.UNIT_PRICE) {
|
|
188
|
-
return numStep.defaultValue ?? null;
|
|
189
|
-
}
|
|
190
|
-
return numStep.defaultValue ?? '';
|
|
191
|
-
}
|
|
192
178
|
case FormStepTypes.RATING:
|
|
193
179
|
case FormStepTypes.DATEPICKER:
|
|
194
180
|
case FormStepTypes.DATEPICKER_RANGE:
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as Steps from '../@Types/FormStep';
|
|
2
1
|
import AYFFormStepTypes from '../constants/AYFFormStepTypes';
|
|
3
2
|
import CBRFormStepTypes from '../constants/CBRFormStepTypes';
|
|
4
3
|
import FormStepTypes, { ApiSelectorOptionTypes, ClassifierOptionTypes, EntityValueOptionTypes, OptionTypes, } from '../constants/FormStepTypes';
|
|
@@ -528,13 +527,6 @@ describe('StepFunctions', function () {
|
|
|
528
527
|
const defaultValue = calcDefaultValue(step);
|
|
529
528
|
expect(defaultValue).toBe(null);
|
|
530
529
|
});
|
|
531
|
-
test('Location step type', async () => {
|
|
532
|
-
const step = {
|
|
533
|
-
type: FormStepTypes.LOCATION,
|
|
534
|
-
};
|
|
535
|
-
const defaultValue = calcDefaultValue(step);
|
|
536
|
-
expect(defaultValue).toBe(null);
|
|
537
|
-
});
|
|
538
530
|
test('Mapper, FileUpload, CBRFormStep types', async () => {
|
|
539
531
|
const step1 = {
|
|
540
532
|
type: FormStepTypes.MAPPER,
|
|
@@ -566,52 +558,6 @@ describe('StepFunctions', function () {
|
|
|
566
558
|
const defaultValue = calcDefaultValue(step);
|
|
567
559
|
expect(defaultValue).toBeUndefined();
|
|
568
560
|
});
|
|
569
|
-
test('Number step type without defaultValue', async () => {
|
|
570
|
-
const step1 = {
|
|
571
|
-
type: FormStepTypes.NUMBER,
|
|
572
|
-
numberType: Steps.NumberStepType.INTEGER,
|
|
573
|
-
};
|
|
574
|
-
const step2 = {
|
|
575
|
-
type: FormStepTypes.NUMBER,
|
|
576
|
-
numberType: Steps.NumberStepType.DECIMAL,
|
|
577
|
-
};
|
|
578
|
-
const step3 = {
|
|
579
|
-
type: FormStepTypes.NUMBER,
|
|
580
|
-
numberType: Steps.NumberStepType.PERCENTAGE,
|
|
581
|
-
};
|
|
582
|
-
const step4 = {
|
|
583
|
-
type: FormStepTypes.NUMBER,
|
|
584
|
-
numberType: Steps.NumberStepType.MONEY,
|
|
585
|
-
};
|
|
586
|
-
const step5 = {
|
|
587
|
-
type: FormStepTypes.NUMBER,
|
|
588
|
-
numberType: Steps.NumberStepType.MEASURE,
|
|
589
|
-
};
|
|
590
|
-
const step6 = {
|
|
591
|
-
type: FormStepTypes.NUMBER,
|
|
592
|
-
numberType: Steps.NumberStepType.UNIT_PRICE,
|
|
593
|
-
};
|
|
594
|
-
expect(calcDefaultValue(step1)).toBe('');
|
|
595
|
-
expect(calcDefaultValue(step2)).toBe('');
|
|
596
|
-
expect(calcDefaultValue(step3)).toBe('');
|
|
597
|
-
expect(calcDefaultValue(step4)).toBe(null);
|
|
598
|
-
expect(calcDefaultValue(step5)).toBe(null);
|
|
599
|
-
expect(calcDefaultValue(step6)).toBe(null);
|
|
600
|
-
});
|
|
601
|
-
test('Number step type with defaultValue', async () => {
|
|
602
|
-
const step1 = {
|
|
603
|
-
type: FormStepTypes.NUMBER,
|
|
604
|
-
numberType: Steps.NumberStepType.INTEGER,
|
|
605
|
-
defaultValue: 42,
|
|
606
|
-
};
|
|
607
|
-
const step2 = {
|
|
608
|
-
type: FormStepTypes.NUMBER,
|
|
609
|
-
numberType: Steps.NumberStepType.MONEY,
|
|
610
|
-
defaultValue: { value: 100, currency: 'USD' },
|
|
611
|
-
};
|
|
612
|
-
expect(calcDefaultValue(step1)).toBe(42);
|
|
613
|
-
expect(calcDefaultValue(step2)).toEqual({ value: 100, currency: 'USD' });
|
|
614
|
-
});
|
|
615
561
|
});
|
|
616
562
|
describe('iterateNestedSteps', function () {
|
|
617
563
|
test('should iterate over nested steps', async () => {
|
|
@@ -34,13 +34,6 @@ export interface StepDependency {
|
|
|
34
34
|
handleStepDep: (value: any) => void;
|
|
35
35
|
}
|
|
36
36
|
export declare const useStepDependency: (step: GBaseStep, defaultValue?: any) => StepDependency;
|
|
37
|
-
/**
|
|
38
|
-
* Whether `idStep` is currently kept off the form by its own visibility condition. A step that is not
|
|
39
|
-
* shown cannot be answered, so nothing may wait for it: a required entity filter pointing at it does
|
|
40
|
-
* not apply, and it never reads as a missing dependency. When the condition cannot be decided yet (a
|
|
41
|
-
* step it reads is not in the store) the step counts as shown, keeping the conservative behaviour.
|
|
42
|
-
*/
|
|
43
|
-
export declare const isStepHiddenByCondition: (idStep: string, form: Form, dependencies: DependencyStore) => boolean;
|
|
44
37
|
export declare const selectStepDependencies: ((state: RootState, _step: GBaseStep, form: Form) => {
|
|
45
38
|
invalids: string[];
|
|
46
39
|
emptyDep: boolean;
|
|
@@ -74,20 +67,6 @@ export declare const selectStepDependencies: ((state: RootState, _step: GBaseSte
|
|
|
74
67
|
memoize: typeof import("reselect").weakMapMemoize;
|
|
75
68
|
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
76
69
|
};
|
|
77
|
-
/**
|
|
78
|
-
* The steps `idStep` depends on, transitively: every dependency's own dependencies come before it,
|
|
79
|
-
* and every id is answered exactly once. `idStep` itself is never listed — a step is not a
|
|
80
|
-
* dependency of itself, even when a draft points it back at itself.
|
|
81
|
-
*
|
|
82
|
-
* A saved form is a DAG: the backend recomputes and validates `step.dependencies` on save. The
|
|
83
|
-
* editor's live preview renders unsaved drafts though, where a filter or a path hop can still point
|
|
84
|
-
* at the step that holds it, or close a cycle with another step. The walk must therefore terminate
|
|
85
|
-
* on any graph, cyclic included: a step is marked visited before it is walked and is never walked
|
|
86
|
-
* or listed twice, so every edge is followed at most once.
|
|
87
|
-
*
|
|
88
|
-
* Exported for the unit test; it is internal to this module and not part of the package's surface.
|
|
89
|
-
*/
|
|
90
|
-
export declare const calcDeepDependencies: (idStep: string, form: Form) => string[];
|
|
91
70
|
export interface UseFormStepOptions<ValueType> {
|
|
92
71
|
defaultValue: ValueType;
|
|
93
72
|
/** If true, will not trigger onChange until the user has finished typing */
|
|
@@ -8,7 +8,6 @@ import { useController } from 'react-hook-form';
|
|
|
8
8
|
import ConditionTypes from '../constants/ConditionTypes';
|
|
9
9
|
import FormStepTypes, { ApiSelectorOptionTypes, ClassifierOptionTypes, EntityValueOptionTypes, } from '../constants/FormStepTypes';
|
|
10
10
|
import { SizeChangeContext } from './Utils/@StepFiller/StepFillerContext';
|
|
11
|
-
import { entityValuePickerBlockingSteps } from './EntityValueStep/entityValuePickerWatchedSteps';
|
|
12
11
|
const selectIsDependency = createSelector([
|
|
13
12
|
(state) => state.site.dependencies,
|
|
14
13
|
(_state, step) => step,
|
|
@@ -48,20 +47,6 @@ export const useStepDependency = (step, defaultValue) => {
|
|
|
48
47
|
originalValue: originalValue ?? defaultValue ?? calcDefaultValue(step),
|
|
49
48
|
};
|
|
50
49
|
};
|
|
51
|
-
/**
|
|
52
|
-
* Whether `idStep` is currently kept off the form by its own visibility condition. A step that is not
|
|
53
|
-
* shown cannot be answered, so nothing may wait for it: a required entity filter pointing at it does
|
|
54
|
-
* not apply, and it never reads as a missing dependency. When the condition cannot be decided yet (a
|
|
55
|
-
* step it reads is not in the store) the step counts as shown, keeping the conservative behaviour.
|
|
56
|
-
*/
|
|
57
|
-
export const isStepHiddenByCondition = (idStep, form, dependencies) => {
|
|
58
|
-
const target = form.steps[idStep];
|
|
59
|
-
if (!target?.condition)
|
|
60
|
-
return false;
|
|
61
|
-
if (recursivelyCalcConditionSteps(target.condition).some((id) => dependencies[id] === undefined))
|
|
62
|
-
return false;
|
|
63
|
-
return !evaluateCondition(target.condition, dependencies);
|
|
64
|
-
};
|
|
65
50
|
export const selectStepDependencies = createSelector([
|
|
66
51
|
(state) => state.site.dependencies,
|
|
67
52
|
(_state, step) => step,
|
|
@@ -71,8 +56,6 @@ export const selectStepDependencies = createSelector([
|
|
|
71
56
|
let emptyDep = false;
|
|
72
57
|
/** Show deep error changes even if not in dependencies */
|
|
73
58
|
for (const idDep of calcDeepDependencies(step.id, form)) {
|
|
74
|
-
if (isStepHiddenByCondition(idDep, form, dependencies))
|
|
75
|
-
continue;
|
|
76
59
|
const dependency = dependencies[idDep];
|
|
77
60
|
if (dependency?.value === null && form.steps[idDep]) {
|
|
78
61
|
invalids.push(idDep);
|
|
@@ -82,45 +65,15 @@ export const selectStepDependencies = createSelector([
|
|
|
82
65
|
}
|
|
83
66
|
return { invalids, emptyDep };
|
|
84
67
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* at the step that holds it, or close a cycle with another step. The walk must therefore terminate
|
|
93
|
-
* on any graph, cyclic included: a step is marked visited before it is walked and is never walked
|
|
94
|
-
* or listed twice, so every edge is followed at most once.
|
|
95
|
-
*
|
|
96
|
-
* Exported for the unit test; it is internal to this module and not part of the package's surface.
|
|
97
|
-
*/
|
|
98
|
-
export const calcDeepDependencies = (idStep, form) => {
|
|
99
|
-
const deps = [];
|
|
100
|
-
/** `idStep` starts out visited so a cycle back to it stops there and never lists it. */
|
|
101
|
-
const visited = new Set([idStep]);
|
|
102
|
-
const walk = (id) => {
|
|
103
|
-
const step = form.steps[id];
|
|
104
|
-
if (!step)
|
|
105
|
-
return;
|
|
106
|
-
/**
|
|
107
|
-
* An entity picker also gives up (its options resolve to null) while a path hop or a
|
|
108
|
-
* required STEP filter holds no value. Those are in `step.dependencies` once the form has
|
|
109
|
-
* been saved, but not in an unsaved draft, so they are added here to read as a missing
|
|
110
|
-
* dependency instead of as a failed load.
|
|
111
|
-
*/
|
|
112
|
-
const idDeps = step.type === FormStepTypes.ENTITYVALUEPICKER
|
|
113
|
-
? [...(step.dependencies ?? []), ...entityValuePickerBlockingSteps(step)]
|
|
114
|
-
: step.dependencies;
|
|
115
|
-
for (const dep of idDeps ?? []) {
|
|
116
|
-
if (visited.has(dep))
|
|
117
|
-
continue;
|
|
118
|
-
visited.add(dep);
|
|
119
|
-
walk(dep);
|
|
120
|
-
deps.push(dep);
|
|
68
|
+
const calcDeepDependencies = (idStep, form, deps = []) => {
|
|
69
|
+
const step = form.steps[idStep];
|
|
70
|
+
if (step?.dependencies) {
|
|
71
|
+
for (const dep of step.dependencies) {
|
|
72
|
+
if (!deps.includes(dep)) {
|
|
73
|
+
deps.push(...calcDeepDependencies(dep, form, deps), dep);
|
|
74
|
+
}
|
|
121
75
|
}
|
|
122
|
-
}
|
|
123
|
-
walk(idStep);
|
|
76
|
+
}
|
|
124
77
|
return deps;
|
|
125
78
|
};
|
|
126
79
|
export const useFormStep = (step, { rules, debounce, sizeChange, defaultValue }) => {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useMemo } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { isValid } from 'date-fns';
|
|
4
4
|
import { InputAdornment, styled, Dialog as MuiDialog } from '@mui/material';
|
|
5
|
-
import { MobileDatePicker as MuiDatePicker, MobileDateTimePicker as MuiDateTimePicker, DatePickerToolbar as MuiDatePickerToolbar, DateTimePickerToolbar as MuiDateTimePickerToolbar, usePickerContext,
|
|
5
|
+
import { MobileDatePicker as MuiDatePicker, MobileDateTimePicker as MuiDateTimePicker, DatePickerToolbar as MuiDatePickerToolbar, DateTimePickerToolbar as MuiDateTimePickerToolbar, usePickerContext, usePickerAdapter, } from '@mui/x-date-pickers';
|
|
6
|
+
import { PickerDay as MuiPickerDay } from '@mui/x-date-pickers/PickerDay';
|
|
6
7
|
import { StyledTextField } from '../ErkTextField/ErkTextField';
|
|
7
8
|
import CalendarIcon from '../../Icons/CalendarIcon';
|
|
9
|
+
import { renderTimeViewClock } from '@mui/x-date-pickers/timeViewRenderers';
|
|
8
10
|
const StyledDateTimePicker = styled(MuiDateTimePicker, {
|
|
9
11
|
shouldForwardProp: (propName) => propName !== 'size',
|
|
10
12
|
})(({ disabled, readOnly, size }) => ({
|
|
@@ -138,18 +140,24 @@ const StyledDay = styled(MuiPickerDay)(({ theme }) => ({
|
|
|
138
140
|
}));
|
|
139
141
|
function CustomPickerField({ error, required, helperText, size = 'small', labelMargin = 5, inputRef, fullWidth = true, }) {
|
|
140
142
|
const { value, fieldFormat, setOpen, disabled, readOnly, label } = usePickerContext();
|
|
143
|
+
// Format through the adapter so the LocalizationProvider locale applies (a bare date-fns
|
|
144
|
+
// `format` always used en-US, so Spanish users saw MM/dd/yyyy).
|
|
145
|
+
const adapter = usePickerAdapter();
|
|
141
146
|
const { displayValue, isInvalid } = useMemo(() => {
|
|
142
147
|
if (!value)
|
|
143
148
|
return { displayValue: '', isInvalid: false };
|
|
144
149
|
if (!isValid(value))
|
|
145
150
|
return { displayValue: '', isInvalid: true };
|
|
146
151
|
try {
|
|
147
|
-
return {
|
|
152
|
+
return {
|
|
153
|
+
displayValue: adapter.formatByString(value, fieldFormat ?? adapter.formats.keyboardDate),
|
|
154
|
+
isInvalid: false,
|
|
155
|
+
};
|
|
148
156
|
}
|
|
149
157
|
catch {
|
|
150
158
|
return { displayValue: '', isInvalid: true };
|
|
151
159
|
}
|
|
152
|
-
}, [value, fieldFormat]);
|
|
160
|
+
}, [value, fieldFormat, adapter]);
|
|
153
161
|
const handleClick = () => {
|
|
154
162
|
if (!disabled && !readOnly) {
|
|
155
163
|
setOpen((prev) => !prev);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import MaterialProviders from '../../Utils/MaterialProviders';
|
|
6
|
+
import InternalFormStyle from '../../constants/InternalFormStyle';
|
|
7
|
+
import ErkDatePicker from './ErkDatePicker';
|
|
8
|
+
import ErkDateRangePicker from '../ErkDateRangePicker/ErkDateRangePicker';
|
|
9
|
+
/**
|
|
10
|
+
* The field text used to be built with a bare date-fns `format`, which ignores the
|
|
11
|
+
* LocalizationProvider locale and always printed en-US dates (MM/dd/yyyy).
|
|
12
|
+
*/
|
|
13
|
+
const setLanguages = (languages) => {
|
|
14
|
+
vi.spyOn(navigator, 'languages', 'get').mockReturnValue(languages);
|
|
15
|
+
};
|
|
16
|
+
const date = new Date(2026, 2, 9, 14, 5); // 9 de marzo de 2026, 14:05
|
|
17
|
+
describe('date pickers follow the browser locale', () => {
|
|
18
|
+
afterEach(() => vi.restoreAllMocks());
|
|
19
|
+
it('shows dd/MM/yyyy for a Spanish browser', () => {
|
|
20
|
+
setLanguages(['es-CO', 'es']);
|
|
21
|
+
render(_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(ErkDatePicker, { label: "Fecha", value: date, onChange: vi.fn() }) }));
|
|
22
|
+
expect(document.querySelector('input')?.value).toBe('09/03/2026');
|
|
23
|
+
});
|
|
24
|
+
it('shows MM/dd/yyyy for a US browser', () => {
|
|
25
|
+
setLanguages(['en-US', 'en']);
|
|
26
|
+
render(_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(ErkDatePicker, { label: "Fecha", value: date, onChange: vi.fn() }) }));
|
|
27
|
+
expect(document.querySelector('input')?.value).toBe('03/09/2026');
|
|
28
|
+
});
|
|
29
|
+
it('shows a localized date-time for a Spanish browser', () => {
|
|
30
|
+
setLanguages(['es']);
|
|
31
|
+
render(_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(ErkDatePicker, { pickTime: true, label: "Fecha y hora", value: date, onChange: vi.fn() }) }));
|
|
32
|
+
expect(document.querySelector('input')?.value).toMatch(/^09\/03\/2026 02:05 (p\. ?m\.|PM)$/i);
|
|
33
|
+
});
|
|
34
|
+
it('shows a dd/MM/yyyy range for a Spanish browser', () => {
|
|
35
|
+
setLanguages(['es-MX']);
|
|
36
|
+
render(_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(ErkDateRangePicker, { label: "Rango", value: [date, new Date(2026, 2, 20)], onChange: vi.fn() }) }));
|
|
37
|
+
expect(document.querySelector('input')?.value).toBe('09/03/2026 – 20/03/2026');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { MobileDateRangePickerProps as MuiDateRangePickerProps } from '@mui/x-date-pickers-pro/MobileDateRangePicker';
|
|
3
|
+
import { DateRange } from '@mui/x-date-pickers-pro';
|
|
4
|
+
import { PickersShortcutsItem } from '@mui/x-date-pickers/PickersShortcuts';
|
|
4
5
|
import { ErkTextFieldProps } from '../ErkTextField/ErkTextField';
|
|
5
6
|
interface ErkDateRangePickerProps extends Omit<MuiDateRangePickerProps, 'ref' | 'onChange' | 'value' | 'slotProps'>, Pick<ErkTextFieldProps, 'error' | 'required' | 'helperText' | 'size'> {
|
|
6
7
|
onChange?: (dateRange: DateRange<Date>) => void;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useMemo } from 'react';
|
|
3
3
|
import { InputAdornment, styled, Dialog as MuiDialog } from '@mui/material';
|
|
4
|
-
import { DatePickerToolbar as MuiDatePickerToolbar, usePickerContext, } from '@mui/x-date-pickers';
|
|
5
|
-
import { MobileDateRangePicker as MuiDateRangePicker,
|
|
6
|
-
import {
|
|
4
|
+
import { DatePickerToolbar as MuiDatePickerToolbar, usePickerContext, usePickerAdapter, } from '@mui/x-date-pickers';
|
|
5
|
+
import { MobileDateRangePicker as MuiDateRangePicker, } from '@mui/x-date-pickers-pro/MobileDateRangePicker';
|
|
6
|
+
import { DateRangePickerDay as MuiDateRangePickerDay } from '@mui/x-date-pickers-pro';
|
|
7
|
+
import { isValid } from 'date-fns';
|
|
7
8
|
import { StyledTextField } from '../ErkTextField/ErkTextField';
|
|
8
9
|
import CalendarIcon from '../../Icons/CalendarIcon';
|
|
9
10
|
const StyledDateRangePicker = styled(MuiDateRangePicker, {
|
|
@@ -85,6 +86,9 @@ const StyledDay = styled(MuiDateRangePickerDay)(({ theme }) => ({
|
|
|
85
86
|
}));
|
|
86
87
|
const CustomRangePickerField = React.forwardRef(function CustomRangePickerField({ error, required, helperText, size = 'small', labelMargin = 5, fullWidth = true, inputRef }, ref) {
|
|
87
88
|
const { value, fieldFormat, setOpen, disabled, readOnly, label } = usePickerContext();
|
|
89
|
+
// Format through the adapter so the LocalizationProvider locale applies (a bare date-fns
|
|
90
|
+
// `format` always used en-US, so Spanish users saw MM/dd/yyyy).
|
|
91
|
+
const adapter = usePickerAdapter();
|
|
88
92
|
const { displayValue, isInvalid } = useMemo(() => {
|
|
89
93
|
const [startDate, endDate] = value ?? [null, null];
|
|
90
94
|
if (!startDate)
|
|
@@ -94,15 +98,15 @@ const CustomRangePickerField = React.forwardRef(function CustomRangePickerField(
|
|
|
94
98
|
if (endDate && !isValid(endDate))
|
|
95
99
|
return { displayValue: '', isInvalid: true };
|
|
96
100
|
try {
|
|
97
|
-
const fmt = fieldFormat ??
|
|
98
|
-
const start =
|
|
99
|
-
const end = endDate ?
|
|
101
|
+
const fmt = fieldFormat ?? adapter.formats.keyboardDate;
|
|
102
|
+
const start = adapter.formatByString(startDate, fmt);
|
|
103
|
+
const end = endDate ? adapter.formatByString(endDate, fmt) : '';
|
|
100
104
|
return { displayValue: end ? `${start} – ${end}` : start, isInvalid: false };
|
|
101
105
|
}
|
|
102
106
|
catch {
|
|
103
107
|
return { displayValue: '', isInvalid: true };
|
|
104
108
|
}
|
|
105
|
-
}, [value, fieldFormat]);
|
|
109
|
+
}, [value, fieldFormat, adapter]);
|
|
106
110
|
const handleClick = () => {
|
|
107
111
|
if (!disabled && !readOnly) {
|
|
108
112
|
setOpen((prev) => !prev);
|
|
@@ -118,10 +122,10 @@ const CustomRangePickerField = React.forwardRef(function CustomRangePickerField(
|
|
|
118
122
|
},
|
|
119
123
|
} }));
|
|
120
124
|
});
|
|
121
|
-
const formatDate = (date, showYear) => {
|
|
125
|
+
const formatDate = (adapter, date, showYear) => {
|
|
122
126
|
if (!date || !isValid(date))
|
|
123
127
|
return '';
|
|
124
|
-
return
|
|
128
|
+
return adapter.formatByString(date, showYear ? adapter.formats.fullDate : 'dd MMM');
|
|
125
129
|
};
|
|
126
130
|
function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = 'small', labelMargin = 5, value, onChange, inputRef, shortcuts, label, required, ...others }) {
|
|
127
131
|
// MUI X v9 no longer forwards `required` to the field-slot label when the field is a Material
|
|
@@ -129,6 +133,7 @@ function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = '
|
|
|
129
133
|
// The picker's `label` does propagate to the field via the picker context, so bake the marker
|
|
130
134
|
// into the label to keep the required indicator visible.
|
|
131
135
|
const displayLabel = required && typeof label === 'string' ? `${label} *` : label;
|
|
136
|
+
const adapter = usePickerAdapter();
|
|
132
137
|
const [startDate, endDate] = value ?? [null, null];
|
|
133
138
|
const hasCompleteRange = Boolean(startDate) && Boolean(endDate);
|
|
134
139
|
const showYear = startDate &&
|
|
@@ -136,8 +141,8 @@ function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = '
|
|
|
136
141
|
isValid(startDate) &&
|
|
137
142
|
isValid(endDate) &&
|
|
138
143
|
startDate.getFullYear() !== endDate.getFullYear();
|
|
139
|
-
const formattedStartDate = formatDate(startDate, Boolean(showYear));
|
|
140
|
-
const formattedEndDate = formatDate(endDate, Boolean(showYear));
|
|
144
|
+
const formattedStartDate = formatDate(adapter, startDate, Boolean(showYear));
|
|
145
|
+
const formattedEndDate = formatDate(adapter, endDate, Boolean(showYear));
|
|
141
146
|
const toolbarText = hasCompleteRange ? `${formattedStartDate} – ${formattedEndDate}` : '– –';
|
|
142
147
|
return (_jsx(StyledDateRangePicker, { ...others, label: displayLabel, value: value, onChange: onChange, size: size, disabled: disabled, readOnly: readOnly, reduceAnimations: true, showDaysOutsideCurrentMonth: true, slots: {
|
|
143
148
|
field: CustomRangePickerField,
|
|
@@ -109,7 +109,15 @@ function CustomSelect({ label, error, value, loading, onChange, children, requir
|
|
|
109
109
|
setOpen((open) => !open);
|
|
110
110
|
}
|
|
111
111
|
}, children: _jsx(IconComponent, { size: size === 'small' ? 22 : 26 }) })) : undefined, onFocus: (e) => {
|
|
112
|
-
|
|
112
|
+
// Open only when focus arrives by keyboard from another control. A focus with no
|
|
113
|
+
// relatedTarget is either a mouse press (MUI's own mousedown already opens the menu)
|
|
114
|
+
// or the focus trap handing focus back after the menu closed; opening on that one
|
|
115
|
+
// reopened the menu right after a backdrop click and kept it stuck open.
|
|
116
|
+
const from = e.relatedTarget;
|
|
117
|
+
const cameFromAnotherControl = from !== null &&
|
|
118
|
+
from.closest('.Erk-MuiPaper-root') === null &&
|
|
119
|
+
!e.currentTarget.parentElement?.contains(from);
|
|
120
|
+
if (cameFromAnotherControl) {
|
|
113
121
|
setOpen(true);
|
|
114
122
|
}
|
|
115
123
|
others.onFocus?.(e);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen, fireEvent, act } from '@testing-library/react';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import '../../Utils/MuiClassnameSetup';
|
|
6
|
+
import MaterialProviders from '../../Utils/MaterialProviders';
|
|
7
|
+
import InternalFormStyle from '../../constants/InternalFormStyle';
|
|
8
|
+
import ErkSelect from './ErkSelect';
|
|
9
|
+
import ErkMenuItem from '../ErkMenuItem';
|
|
10
|
+
function renderSelect() {
|
|
11
|
+
render(_jsxs(MaterialProviders, { formStyle: InternalFormStyle, children: [_jsx("input", { "data-testid": "before" }), _jsxs(ErkSelect, { label: "Opci\u00F3n", onChange: vi.fn(), children: [_jsx(ErkMenuItem, { value: "a", children: "A" }), _jsx(ErkMenuItem, { value: "b", children: "B" })] })] }));
|
|
12
|
+
}
|
|
13
|
+
// The inline (disablePortal) menu marks the rest of the tree aria-hidden while open, so the
|
|
14
|
+
// combobox is read from the raw DOM; the paper also stays mounted through its exit transition,
|
|
15
|
+
// so the open state comes from aria-expanded rather than from the listbox being present.
|
|
16
|
+
const combobox = () => document.querySelector('[role=combobox]');
|
|
17
|
+
const isOpen = () => combobox().getAttribute('aria-expanded') === 'true';
|
|
18
|
+
const openSelect = () => {
|
|
19
|
+
fireEvent.mouseDown(combobox());
|
|
20
|
+
};
|
|
21
|
+
const flush = () => act(() => new Promise((resolve) => setTimeout(resolve, 50)));
|
|
22
|
+
describe('ErkSelect open/close', () => {
|
|
23
|
+
it('opens on mouse down', () => {
|
|
24
|
+
renderSelect();
|
|
25
|
+
openSelect();
|
|
26
|
+
expect(isOpen()).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('stays closed after clicking the backdrop (does not reopen on focus restore)', async () => {
|
|
29
|
+
renderSelect();
|
|
30
|
+
openSelect();
|
|
31
|
+
const backdrop = document.querySelector('.Erk-MuiBackdrop-root');
|
|
32
|
+
fireEvent.click(backdrop);
|
|
33
|
+
await flush();
|
|
34
|
+
// The focus trap gives focus back to the combobox with no relatedTarget (the mouse left focus on body).
|
|
35
|
+
fireEvent.focus(combobox(), { relatedTarget: null });
|
|
36
|
+
await flush();
|
|
37
|
+
expect(isOpen()).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
it('stays closed after picking an option', async () => {
|
|
40
|
+
renderSelect();
|
|
41
|
+
openSelect();
|
|
42
|
+
fireEvent.click(document.querySelector('[role=option][data-value=b]'));
|
|
43
|
+
await flush();
|
|
44
|
+
expect(isOpen()).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
it('opens when reached by keyboard from another field', () => {
|
|
47
|
+
renderSelect();
|
|
48
|
+
const before = screen.getByTestId('before');
|
|
49
|
+
before.focus();
|
|
50
|
+
fireEvent.focus(combobox(), { relatedTarget: before });
|
|
51
|
+
expect(isOpen()).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -62,7 +62,14 @@ function CustomSelect({ value, onChange, label, error, required, pickDays, helpe
|
|
|
62
62
|
if (!readOnly && !disabled)
|
|
63
63
|
setOpen(!open);
|
|
64
64
|
}, children: _jsx(ClockIcon, { size: size === 'small' ? 22 : 26 }) }), onFocus: (e) => {
|
|
65
|
-
|
|
65
|
+
// Same rule as ErkSelect: open only when focus arrives from another control. A focus
|
|
66
|
+
// with no relatedTarget is the hidden menu handing focus back on close, and opening on
|
|
67
|
+
// it reopened the popper right after every click away.
|
|
68
|
+
const from = e.relatedTarget;
|
|
69
|
+
const cameFromAnotherControl = from !== null &&
|
|
70
|
+
from.closest('.Erk-MuiPaper-root') === null &&
|
|
71
|
+
!e.currentTarget.parentElement?.contains(from);
|
|
72
|
+
if (cameFromAnotherControl && !readOnly && !disabled) {
|
|
66
73
|
setOpen(true);
|
|
67
74
|
}
|
|
68
75
|
}, onOpen: () => {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { render, fireEvent, act } from '@testing-library/react';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import '../../Utils/MuiClassnameSetup';
|
|
6
|
+
import MaterialProviders from '../../Utils/MaterialProviders';
|
|
7
|
+
import InternalFormStyle from '../../constants/InternalFormStyle';
|
|
8
|
+
import ErkTimePicker from './ErkTimePicker';
|
|
9
|
+
const combobox = () => document.querySelector('[role=combobox]');
|
|
10
|
+
const isOpen = () => combobox().getAttribute('aria-expanded') === 'true';
|
|
11
|
+
const flush = () => act(() => new Promise((resolve) => setTimeout(resolve, 50)));
|
|
12
|
+
describe('ErkTimePicker open/close', () => {
|
|
13
|
+
it('closes on click away and stays closed when focus returns to the trigger', async () => {
|
|
14
|
+
render(_jsxs(MaterialProviders, { formStyle: InternalFormStyle, children: [_jsx("button", { "data-testid": "outside", children: "fuera" }), _jsx(ErkTimePicker, { label: "Tiempo", pickHours: true, pickMinutes: true, onChange: vi.fn() })] }));
|
|
15
|
+
fireEvent.mouseDown(combobox());
|
|
16
|
+
await flush();
|
|
17
|
+
expect(isOpen()).toBe(true);
|
|
18
|
+
fireEvent.mouseDown(document.querySelector('[data-testid=outside]'));
|
|
19
|
+
await flush();
|
|
20
|
+
fireEvent.focus(combobox(), { relatedTarget: null });
|
|
21
|
+
await flush();
|
|
22
|
+
expect(isOpen()).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|