@arquimedes.co/eureka-forms 3.0.71-test → 3.0.71

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.
Files changed (138) hide show
  1. package/README +33 -1
  2. package/dist/@Types/AvailabilityFormStep.d.ts +48 -0
  3. package/dist/@Types/AvailabilityFormStep.js +24 -0
  4. package/dist/@Types/BankAccountFormStep.d.ts +67 -0
  5. package/dist/@Types/BankAccountFormStep.js +14 -0
  6. package/dist/@Types/BookingFormStep.d.ts +197 -0
  7. package/dist/@Types/BookingFormStep.js +44 -0
  8. package/dist/@Types/CalendarFormStep.d.ts +209 -0
  9. package/dist/@Types/CalendarFormStep.js +55 -0
  10. package/dist/@Types/CommunicationChannelFormStep.d.ts +51 -0
  11. package/dist/@Types/CommunicationChannelFormStep.js +15 -0
  12. package/dist/@Types/ConsentFormStep.d.ts +36 -0
  13. package/dist/@Types/ConsentFormStep.js +8 -0
  14. package/dist/@Types/EntityFormFormStep.d.ts +66 -0
  15. package/dist/@Types/EntityFormFormStep.js +20 -0
  16. package/dist/@Types/EventFormStep.d.ts +52 -0
  17. package/dist/@Types/EventFormStep.js +13 -0
  18. package/dist/@Types/ExternalReferenceFormStep.d.ts +74 -0
  19. package/dist/@Types/ExternalReferenceFormStep.js +20 -0
  20. package/dist/@Types/FormStep.d.ts +7 -2
  21. package/dist/@Types/FormStep.js +2 -1
  22. package/dist/@Types/LocationFormStep.d.ts +159 -0
  23. package/dist/@Types/LocationFormStep.js +46 -0
  24. package/dist/@Types/NumericFormSteps.d.ts +108 -0
  25. package/dist/@Types/NumericFormSteps.js +20 -0
  26. package/dist/@Types/PredefinedSelectorFormStep.d.ts +51 -0
  27. package/dist/@Types/PredefinedSelectorFormStep.js +39 -0
  28. package/dist/@Types/StepRef.d.ts +135 -0
  29. package/dist/@Types/StepRef.js +49 -0
  30. package/dist/App/App.stories.d.ts +10 -0
  31. package/dist/App/App.stories.js +189 -0
  32. package/dist/App/AppHooks.js +8 -0
  33. package/dist/App/AppHooks.test.js +8 -0
  34. package/dist/Form/Form.js +7 -6
  35. package/dist/Form/FormFunctions.d.ts +17 -0
  36. package/dist/Form/FormFunctions.js +22 -0
  37. package/dist/Form/FormFunctions.test.js +28 -1
  38. package/dist/FormSteps/AvailabilityStep/AvailabilityStep.d.ts +7 -0
  39. package/dist/FormSteps/AvailabilityStep/AvailabilityStep.js +14 -0
  40. package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.d.ts +8 -0
  41. package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.js +32 -0
  42. package/dist/FormSteps/BookingStep/BookingStep.d.ts +17 -0
  43. package/dist/FormSteps/BookingStep/BookingStep.js +14 -0
  44. package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.d.ts +14 -0
  45. package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.js +133 -0
  46. package/dist/FormSteps/CheckBoxStep/CheckBoxStep.mobileLabel.test.js +20 -12
  47. package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.js +6 -13
  48. package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.module.css +2 -13
  49. package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.d.ts +1 -0
  50. package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.js +70 -0
  51. package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +3 -1
  52. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +26 -26
  53. package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.d.ts +12 -0
  54. package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.js +35 -0
  55. package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.d.ts +1 -0
  56. package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.js +31 -0
  57. package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.d.ts +27 -0
  58. package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.js +64 -0
  59. package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.d.ts +1 -0
  60. package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.js +95 -0
  61. package/dist/FormSteps/LocationStep/LocationStep.d.ts +10 -0
  62. package/dist/FormSteps/LocationStep/LocationStep.js +14 -0
  63. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.d.ts +3 -0
  64. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.js +54 -0
  65. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.module.css +18 -0
  66. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.d.ts +3 -0
  67. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.js +170 -0
  68. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.module.css +96 -0
  69. package/dist/FormSteps/NumberStep/NumberStep.d.ts +10 -0
  70. package/dist/FormSteps/NumberStep/NumberStep.js +14 -0
  71. package/dist/FormSteps/Step.js +16 -0
  72. package/dist/FormSteps/StepFunctions.js +14 -0
  73. package/dist/FormSteps/StepFunctions.test.js +54 -0
  74. package/dist/FormSteps/StepHooks.d.ts +21 -0
  75. package/dist/FormSteps/StepHooks.js +55 -8
  76. package/dist/FormSteps/StepHooks.test.d.ts +1 -0
  77. package/dist/FormSteps/StepHooks.test.js +92 -0
  78. package/dist/FormSteps/isStepHiddenByCondition.test.d.ts +1 -0
  79. package/dist/FormSteps/isStepHiddenByCondition.test.js +42 -0
  80. package/dist/Icons/AddIcon.d.ts +3 -0
  81. package/dist/Icons/AddIcon.js +7 -0
  82. package/dist/Icons/EditIcon.d.ts +3 -0
  83. package/dist/Icons/EditIcon.js +7 -0
  84. package/dist/Icons/RemoveIcon.d.ts +3 -0
  85. package/dist/Icons/RemoveIcon.js +7 -0
  86. package/dist/Icons/ViewDayIcon.d.ts +3 -0
  87. package/dist/Icons/ViewDayIcon.js +7 -0
  88. package/dist/Icons/ViewWeekIcon.d.ts +3 -0
  89. package/dist/Icons/ViewWeekIcon.js +7 -0
  90. package/dist/Services/BookingService.d.ts +79 -0
  91. package/dist/Services/BookingService.js +66 -0
  92. package/dist/Services/BookingService.test.d.ts +1 -0
  93. package/dist/Services/BookingService.test.js +57 -0
  94. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.d.ts +19 -0
  95. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.js +80 -0
  96. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.module.css +88 -0
  97. package/dist/Shared/ErkAddressAutocomplete/googlePlaces.d.ts +29 -0
  98. package/dist/Shared/ErkAddressAutocomplete/googlePlaces.js +139 -0
  99. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.d.ts +25 -0
  100. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.js +112 -0
  101. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.module.css +88 -0
  102. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.d.ts +1 -0
  103. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.js +73 -0
  104. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.d.ts +54 -0
  105. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.js +294 -0
  106. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.module.css +608 -0
  107. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.d.ts +28 -0
  108. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.js +117 -0
  109. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.d.ts +1 -0
  110. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.js +49 -0
  111. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.d.ts +1 -0
  112. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.js +171 -0
  113. package/dist/Shared/ErkDatePicker/ErkDatePicker.js +1 -3
  114. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +2 -3
  115. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +1 -2
  116. package/dist/Shared/ErkIconButton/ErkIconButton.d.ts +17 -0
  117. package/dist/Shared/ErkIconButton/ErkIconButton.js +11 -0
  118. package/dist/Shared/ErkIconButton/ErkIconButton.module.css +41 -0
  119. package/dist/Shared/ErkLocationField/ErkLocationField.d.ts +24 -0
  120. package/dist/Shared/ErkLocationField/ErkLocationField.js +128 -0
  121. package/dist/Shared/ErkLocationField/ErkLocationField.module.css +164 -0
  122. package/dist/Shared/ErkLocationField/ErkLocationField.test.d.ts +1 -0
  123. package/dist/Shared/ErkLocationField/ErkLocationField.test.js +82 -0
  124. package/dist/Shared/ErkLocationField/addressFields.d.ts +12 -0
  125. package/dist/Shared/ErkLocationField/addressFields.js +34 -0
  126. package/dist/Shared/ErkLocationField/locationRestrictions.d.ts +6 -0
  127. package/dist/Shared/ErkLocationField/locationRestrictions.js +51 -0
  128. package/dist/Shared/ErkLocationInput/ErkLocationInput.d.ts +15 -0
  129. package/dist/Shared/ErkLocationInput/ErkLocationInput.js +502 -0
  130. package/dist/Shared/ErkLocationInput/ErkLocationInput.module.css +128 -0
  131. package/dist/Shared/ErkNumberField/ErkNumberField.d.ts +42 -0
  132. package/dist/Shared/ErkNumberField/ErkNumberField.js +169 -0
  133. package/dist/Utils/AxiosWidget.js +9 -1
  134. package/dist/constants/FormStepTypes.d.ts +5 -1
  135. package/dist/constants/FormStepTypes.js +4 -0
  136. package/dist/index.lib.d.ts +4 -2
  137. package/dist/index.lib.js +3 -1
  138. package/package.json +2 -1
@@ -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]?.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);
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,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,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;
@@ -0,0 +1,3 @@
1
+ import { LocationStepProps } from '../LocationStep';
2
+ declare function MaterialLocationStep({ step, editable }: LocationStepProps): JSX.Element;
3
+ export default MaterialLocationStep;
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext } from 'react';
3
+ import { AddressFieldMode, LocationInputMode } from '../../../@Types/LocationFormStep';
4
+ import { useFormStep } from '../../StepHooks';
5
+ import FormContext from '../../../Contexts/FormContext';
6
+ import { selectBreakPoint, useAppSelector } from '../../../hooks';
7
+ import { calcStepWidth } from '../../StepFunctions';
8
+ import ErkLocationField from '../../../Shared/ErkLocationField/ErkLocationField';
9
+ import { fieldConfig } from '../../../Shared/ErkLocationField/addressFields';
10
+ import { validateRestrictions } from '../../../Shared/ErkLocationField/locationRestrictions';
11
+ import styles from './MaterialLocationStep.module.css';
12
+ function MaterialLocationStep({ step, editable }) {
13
+ const currentBreakPoint = useAppSelector(selectBreakPoint);
14
+ const { postview, formStyle } = useAppSelector((state) => state.global);
15
+ const form = useContext(FormContext);
16
+ const isReadOnly = !editable || postview;
17
+ const widthStyle = currentBreakPoint <= step.size ? '100%' : calcStepWidth(step.size, form.size);
18
+ const { ref, value, onChange, error } = useFormStep(step, {
19
+ defaultValue: step.defaultValue ?? null,
20
+ rules: {
21
+ required: step.required ? 'La ubicación es obligatoria' : undefined,
22
+ validate: (val) => {
23
+ if (!val)
24
+ return step.required ? 'La ubicación es obligatoria' : true;
25
+ if (val.source === LocationInputMode.MANUAL) {
26
+ // Un campo es obligatorio en manual solo si no está omitido (FIXED lo llena solo).
27
+ const detail = val.addressDetail;
28
+ const isRequired = (key) => fieldConfig(step.addressFields, key).mode !== AddressFieldMode.OMIT;
29
+ if (step.required && isRequired('street') && !detail?.street)
30
+ return 'Por favor completa la calle en el formulario manual.';
31
+ if (step.required && isRequired('city') && !detail?.city)
32
+ return 'Por favor completa la ciudad en el formulario manual.';
33
+ if (step.required && isRequired('country') && !detail?.country)
34
+ return 'Por favor completa el país en el formulario manual.';
35
+ return true;
36
+ }
37
+ if (val.latitude === undefined || val.longitude === undefined) {
38
+ return step.required ? 'Coordenadas geográficas no capturadas.' : true;
39
+ }
40
+ // Restricciones geográficas (radio / geofence).
41
+ return validateRestrictions(val.latitude, val.longitude, step.restrictions) ?? true;
42
+ },
43
+ },
44
+ });
45
+ return (_jsxs("div", { className: styles.container, style: {
46
+ width: widthStyle,
47
+ '--eureka-outline': formStyle.outlineColor,
48
+ '--eureka-primary': formStyle.primaryColor,
49
+ '--eureka-text': formStyle.textColor,
50
+ '--eureka-error': formStyle.errorColor,
51
+ '--eureka-bg': formStyle.standAloneBackgroundColor ?? '#fff',
52
+ }, children: [step.label && (_jsxs("div", { className: styles.label, children: [step.label, step.required && _jsx("span", { className: styles.required, children: " *" })] })), _jsx(ErkLocationField, { value: value, onChange: onChange, allowedModes: step.allowedModes, defaultMode: step.defaultMode, addressFields: step.addressFields, helperText: error?.message ?? step.description, required: step.required, error: !!error, readOnly: isReadOnly, inputRef: ref })] }));
53
+ }
54
+ export default MaterialLocationStep;
@@ -0,0 +1,18 @@
1
+ .container {
2
+ max-width: 100%;
3
+ display: flex;
4
+ flex-direction: column;
5
+ gap: 6px;
6
+ padding: 5px 10px 0;
7
+ box-sizing: border-box;
8
+ }
9
+
10
+ .label {
11
+ font-size: 14px;
12
+ font-weight: 500;
13
+ color: var(--eureka-text, #333);
14
+ }
15
+
16
+ .required {
17
+ color: var(--eureka-error, #e53935);
18
+ }
@@ -0,0 +1,3 @@
1
+ import { NumberStepProps } from '../NumberStep';
2
+ declare function MaterialNumberStep({ step, editable }: NumberStepProps): JSX.Element;
3
+ export default MaterialNumberStep;
@@ -0,0 +1,170 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext, useState, useEffect } from 'react';
3
+ import { NumberStepType, } from '../../../@Types/NumericFormSteps';
4
+ import { useFormStep } from '../../StepHooks';
5
+ import FormContext from '../../../Contexts/FormContext';
6
+ import { selectBreakPoint, useAppSelector } from '../../../hooks';
7
+ import { calcStepWidth } from '../../StepFunctions';
8
+ import ErkNumberField from '../../../Shared/ErkNumberField/ErkNumberField';
9
+ import ErkSelect from '../../../Shared/ErkSelect/ErkSelect';
10
+ import ErkMenuItem from '../../../Shared/ErkMenuItem';
11
+ import styles from './MaterialNumberStep.module.css';
12
+ const DEFAULT_CURRENCIES = ['COP', 'USD', 'EUR', 'MXN', 'CLP', 'BRL'];
13
+ const DEFAULT_UNITS = ['unidades', 'kg', 'g', 'm', 'cm', 'l', 'ml', 'hrs', 'mes', 'año'];
14
+ // ---------------------------------------------------------------------------
15
+ // Helpers
16
+ // ---------------------------------------------------------------------------
17
+ function getNumericValue(value) {
18
+ if (value === null || value === undefined)
19
+ return null;
20
+ if (typeof value === 'number')
21
+ return value;
22
+ return value.value;
23
+ }
24
+ // ---------------------------------------------------------------------------
25
+ // Component
26
+ // ---------------------------------------------------------------------------
27
+ function MaterialNumberStep({ step, editable }) {
28
+ const currentBreakPoint = useAppSelector(selectBreakPoint);
29
+ const { postview, formStyle } = useAppSelector((state) => state.global);
30
+ const form = useContext(FormContext);
31
+ const isReadOnly = !editable || postview;
32
+ const widthStyle = currentBreakPoint <= step.size ? '100%' : calcStepWidth(step.size, form.size);
33
+ const isComposite = step.numberType === NumberStepType.MONEY ||
34
+ step.numberType === NumberStepType.MEASURE ||
35
+ step.numberType === NumberStepType.UNIT_PRICE;
36
+ // Narrowed views — only used after the corresponding numberType check
37
+ const asMoney = step;
38
+ const asMeasure = step;
39
+ const asUnitPrice = step;
40
+ const { ref, value, onChange, error } = useFormStep(step, {
41
+ defaultValue: step.defaultValue ?? null,
42
+ rules: {
43
+ required: step.required ? 'Este campo es obligatorio' : undefined,
44
+ validate: (val) => {
45
+ if (!step.required && (val === null || val === undefined || val === ''))
46
+ return true;
47
+ if (step.required && (val === null || val === undefined || val === ''))
48
+ return 'Este campo es obligatorio';
49
+ const numVal = getNumericValue(val);
50
+ if (numVal === null)
51
+ return 'Formato numérico inválido';
52
+ if (step.min !== undefined && numVal < step.min)
53
+ return `El valor mínimo es ${step.min}`;
54
+ if (step.max !== undefined && numVal > step.max)
55
+ return `El valor máximo es ${step.max}`;
56
+ return true;
57
+ },
58
+ },
59
+ });
60
+ // Currency/unit selectors
61
+ const [selectedCurrency, setSelectedCurrency] = useState(() => {
62
+ const v = value;
63
+ return v?.currency ?? asMoney.currency ?? asUnitPrice.currency ?? 'COP';
64
+ });
65
+ const [selectedUnit, setSelectedUnit] = useState(() => {
66
+ const v = value;
67
+ return v?.unit ?? asMeasure.unit ?? asUnitPrice.unit ?? 'unidades';
68
+ });
69
+ // Sync when value changes externally
70
+ useEffect(() => {
71
+ if (value && typeof value === 'object') {
72
+ if ('currency' in value && value.currency && value.currency !== selectedCurrency) {
73
+ void Promise.resolve().then(() => setSelectedCurrency(value.currency));
74
+ }
75
+ if ('unit' in value && value.unit && value.unit !== selectedUnit) {
76
+ void Promise.resolve().then(() => setSelectedUnit(value.unit));
77
+ }
78
+ }
79
+ }, [value, selectedCurrency, selectedUnit]);
80
+ // ---------------------------------------------------------------------------
81
+ // Handlers: wrap ErkNumberField's (number | null) into the step value shape
82
+ // ---------------------------------------------------------------------------
83
+ const handleNumberChange = (num) => {
84
+ if (num === null) {
85
+ onChange(null);
86
+ return;
87
+ }
88
+ if (step.numberType === NumberStepType.MONEY) {
89
+ onChange({ value: num, currency: selectedCurrency });
90
+ }
91
+ else if (step.numberType === NumberStepType.MEASURE) {
92
+ onChange({ value: num, unit: selectedUnit });
93
+ }
94
+ else if (step.numberType === NumberStepType.UNIT_PRICE) {
95
+ onChange({ value: num, currency: selectedCurrency, unit: selectedUnit });
96
+ }
97
+ else {
98
+ onChange(num);
99
+ }
100
+ };
101
+ const handleCurrencyChange = (curr) => {
102
+ const next = curr ?? 'USD';
103
+ setSelectedCurrency(next);
104
+ const num = getNumericValue(value);
105
+ if (num !== null) {
106
+ onChange(step.numberType === NumberStepType.UNIT_PRICE
107
+ ? { value: num, currency: next, unit: selectedUnit }
108
+ : { value: num, currency: next });
109
+ }
110
+ };
111
+ const handleUnitChange = (u) => {
112
+ const next = u ?? 'unidades';
113
+ setSelectedUnit(next);
114
+ const num = getNumericValue(value);
115
+ if (num !== null) {
116
+ onChange(step.numberType === NumberStepType.UNIT_PRICE
117
+ ? { value: num, currency: selectedCurrency, unit: next }
118
+ : { value: num, unit: next });
119
+ }
120
+ };
121
+ // ---------------------------------------------------------------------------
122
+ // Static suffix text shown inside ErkNumberField
123
+ // ---------------------------------------------------------------------------
124
+ const staticSuffix = () => {
125
+ if (step.numberType === NumberStepType.PERCENTAGE)
126
+ return '%';
127
+ if (step.numberType === NumberStepType.MONEY && !asMoney.allowCurrencyChange)
128
+ return asMoney.currency ?? 'USD';
129
+ if (step.numberType === NumberStepType.MEASURE && !asMeasure.allowUnitChange)
130
+ return asMeasure.unit ?? 'unidades';
131
+ // UNIT_PRICE renders its adornment fully inside the field only when neither part is editable.
132
+ if (step.numberType === NumberStepType.UNIT_PRICE &&
133
+ !asUnitPrice.allowCurrencyChange &&
134
+ !asUnitPrice.allowUnitChange)
135
+ return `${asUnitPrice.currency ?? 'USD'} / ${asUnitPrice.unit ?? 'unidades'}`;
136
+ if (!isComposite && step.suffix)
137
+ return step.suffix;
138
+ return undefined;
139
+ };
140
+ // ---------------------------------------------------------------------------
141
+ // Resolved selector lists
142
+ // ---------------------------------------------------------------------------
143
+ const currenciesList = step.numberType === NumberStepType.MONEY || step.numberType === NumberStepType.UNIT_PRICE
144
+ ? (step.availableCurrencies ?? DEFAULT_CURRENCIES)
145
+ : [];
146
+ const unitsList = step.numberType === NumberStepType.MEASURE || step.numberType === NumberStepType.UNIT_PRICE
147
+ ? (step.availableUnits ?? DEFAULT_UNITS)
148
+ : [];
149
+ const isMoneyDynamic = step.numberType === NumberStepType.MONEY && asMoney.allowCurrencyChange;
150
+ const isMeasureDynamic = step.numberType === NumberStepType.MEASURE && asMeasure.allowUnitChange;
151
+ // UNIT_PRICE has two independent toggles: currency and unit can each be fixed or selectable.
152
+ const isUnitPriceCurrencyDynamic = step.numberType === NumberStepType.UNIT_PRICE && !!asUnitPrice.allowCurrencyChange;
153
+ const isUnitPriceUnitDynamic = step.numberType === NumberStepType.UNIT_PRICE && !!asUnitPrice.allowUnitChange;
154
+ const isUnitPriceDynamic = isUnitPriceCurrencyDynamic || isUnitPriceUnitDynamic;
155
+ // ---------------------------------------------------------------------------
156
+ // Shared CSS vars
157
+ // ---------------------------------------------------------------------------
158
+ const cssVars = {
159
+ width: widthStyle,
160
+ '--eureka-outline': formStyle.outlineColor,
161
+ '--eureka-primary': formStyle.primaryColor,
162
+ '--eureka-text': formStyle.textColor,
163
+ '--eureka-bg': formStyle.standAloneBackgroundColor ?? '#fff',
164
+ };
165
+ // ---------------------------------------------------------------------------
166
+ // Read-only view
167
+ // ---------------------------------------------------------------------------
168
+ return (_jsx("div", { className: styles.container, style: cssVars, children: _jsxs("div", { className: styles.inputRow, children: [_jsx("div", { style: { flex: 1 }, children: _jsx(ErkNumberField, { label: step.label, value: getNumericValue(value), onChange: handleNumberChange, error: !!error, errorBorder: true, required: step.required, helperText: error?.message ?? step.description ?? undefined, inputRef: ref, min: step.min, max: step.max, decimals: step.numberType === NumberStepType.INTEGER ? 0 : (step.decimals ?? 2), suffix: staticSuffix(), readOnly: isReadOnly, spinner: step.spinner, step: step.step, placeholder: step.placeholder }) }), isMoneyDynamic && (_jsx("div", { className: styles.selectWrapper, children: _jsx(ErkSelect, { value: selectedCurrency, onChange: handleCurrencyChange, clearable: false, children: currenciesList.map((c) => (_jsx(ErkMenuItem, { value: c, children: c }, c))) }) })), isMeasureDynamic && (_jsx("div", { className: styles.selectWrapper, children: _jsx(ErkSelect, { value: selectedUnit, onChange: handleUnitChange, clearable: false, children: unitsList.map((u) => (_jsx(ErkMenuItem, { value: u, children: u }, u))) }) })), isUnitPriceDynamic && (_jsxs(_Fragment, { children: [isUnitPriceCurrencyDynamic ? (_jsx("div", { className: styles.selectWrapper, children: _jsx(ErkSelect, { value: selectedCurrency, onChange: handleCurrencyChange, clearable: false, children: currenciesList.map((c) => (_jsx(ErkMenuItem, { value: c, children: c }, c))) }) })) : (_jsx("span", { className: styles.suffixText, children: asUnitPrice.currency ?? 'USD' })), _jsx("span", { className: styles.dividerSlash, children: "/" }), isUnitPriceUnitDynamic ? (_jsx("div", { className: styles.selectWrapper, children: _jsx(ErkSelect, { value: selectedUnit, onChange: handleUnitChange, clearable: false, children: unitsList.map((u) => (_jsx(ErkMenuItem, { value: u, children: u }, u))) }) })) : (_jsx("span", { className: styles.suffixText, children: asUnitPrice.unit ?? 'unidades' }))] }))] }) }));
169
+ }
170
+ export default MaterialNumberStep;