@arquimedes.co/eureka-forms 3.0.66 → 3.0.67

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.
@@ -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';
@@ -27,8 +27,23 @@ function EntityValuePickerStep({ step, editable }) {
27
27
  }))) ?? []);
28
28
  }, [subscribe, idForm]);
29
29
  const getOptions = useCallback(async (step, dependencyStore, ids) => {
30
- return await getEntityValueOptions(step, dependencyStore, ids, fetchFilterIntegration);
31
- }, [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]);
32
47
  const [dialogs, setDialogs] = useState();
33
48
  const dialogsIdStepDeps = useMemo(() => {
34
49
  const ids = [];
@@ -113,7 +128,7 @@ function EntityValuePickerStep({ step, editable }) {
113
128
  } }) })] }));
114
129
  }
115
130
  export default EntityValuePickerStep;
116
- const getEntityValueOptions = async (step, dependencyStore, { idOrganization, idCurrentAgent, }, fetchFilterIntegration) => {
131
+ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, idCurrentAgent, }, fetchFilterIntegration, form) => {
117
132
  if (!idOrganization)
118
133
  return null;
119
134
  let urlPath = '';
@@ -179,7 +194,8 @@ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, id
179
194
  if (currentValue !== undefined) {
180
195
  params.set(filter.idProperty, currentValue);
181
196
  }
182
- 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.
183
199
  return null;
184
200
  }
185
201
  break;
@@ -200,8 +216,3 @@ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, id
200
216
  });
201
217
  return response.data.filter((option) => step.options[option._id]?.type !== EntityValueOptionTypes.HIDE);
202
218
  };
203
- /**
204
- * The steps the picker must watch on top of `step.dependencies`. See
205
- * `entityValuePickerWatchedSteps` for why the saved dependencies are not enough.
206
- */
207
- const getOptionalDependencies = (step) => entityValuePickerWatchedSteps(step);
@@ -34,6 +34,13 @@ 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;
37
44
  export declare const selectStepDependencies: ((state: RootState, _step: GBaseStep, form: Form) => {
38
45
  invalids: string[];
39
46
  emptyDep: boolean;
@@ -48,6 +48,20 @@ export const useStepDependency = (step, defaultValue) => {
48
48
  originalValue: originalValue ?? defaultValue ?? calcDefaultValue(step),
49
49
  };
50
50
  };
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
+ };
51
65
  export const selectStepDependencies = createSelector([
52
66
  (state) => state.site.dependencies,
53
67
  (_state, step) => step,
@@ -57,6 +71,8 @@ export const selectStepDependencies = createSelector([
57
71
  let emptyDep = false;
58
72
  /** Show deep error changes even if not in dependencies */
59
73
  for (const idDep of calcDeepDependencies(step.id, form)) {
74
+ if (isStepHiddenByCondition(idDep, form, dependencies))
75
+ continue;
60
76
  const dependency = dependencies[idDep];
61
77
  if (dependency?.value === null && form.steps[idDep]) {
62
78
  invalids.push(idDep);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { isStepHiddenByCondition } from './StepHooks';
3
+ // A Selector shown only while the Proyecto picker holds a specific value — the shape the editor saves.
4
+ const PROYECTO = 'ENTITYVALUEPICKER-proyecto';
5
+ const condition = {
6
+ type: 'EXPRESSION',
7
+ expression: 'AND',
8
+ conditions: [
9
+ { type: 'FORM_STEP', stepType: 'ENTITYVALUEPICKER', idStep: PROYECTO, operator: 'EXISTS' },
10
+ { type: 'FORM_STEP', stepType: 'ENTITYVALUEPICKER', idStep: PROYECTO, operator: 'EQUAL', values: ['kai'] },
11
+ ],
12
+ };
13
+ const form = {
14
+ steps: {
15
+ [PROYECTO]: { id: PROYECTO, type: 'ENTITYVALUEPICKER' },
16
+ 'SELECTOR-piso': { id: 'SELECTOR-piso', type: 'SELECTOR', condition },
17
+ 'SELECTOR-libre': { id: 'SELECTOR-libre', type: 'SELECTOR' },
18
+ },
19
+ };
20
+ const dependency = (value) => ({
21
+ idOriginal: PROYECTO,
22
+ dependents: [],
23
+ value,
24
+ type: 'ENTITYVALUEPICKER',
25
+ });
26
+ describe('isStepHiddenByCondition', () => {
27
+ test('a step without condition is never hidden', () => {
28
+ expect(isStepHiddenByCondition('SELECTOR-libre', form, {})).toBe(false);
29
+ });
30
+ test('a step whose condition evaluates false is hidden', () => {
31
+ expect(isStepHiddenByCondition('SELECTOR-piso', form, { [PROYECTO]: dependency({ _id: 'otro' }) })).toBe(true);
32
+ });
33
+ test('a step whose condition evaluates true is shown', () => {
34
+ expect(isStepHiddenByCondition('SELECTOR-piso', form, { [PROYECTO]: dependency({ _id: 'kai' }) })).toBe(false);
35
+ });
36
+ test('an undecidable condition (its step is not in the store) counts as shown', () => {
37
+ expect(isStepHiddenByCondition('SELECTOR-piso', form, {})).toBe(false);
38
+ });
39
+ test('a step unknown to the form counts as shown', () => {
40
+ expect(isStepHiddenByCondition('MAPPER-x-espacio', form, {})).toBe(false);
41
+ });
42
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version": "3.0.66",
4
+ "version": "3.0.67",
5
5
  "scripts": {
6
6
  "watch": "node node_modules/@typescript/native/bin/tsc --noEmit --watch --project tsconfig.app.json",
7
7
  "start": "vite",