@arquimedes.co/eureka-forms 3.0.65 → 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);
@@ -2,6 +2,13 @@ import { EntityValueDataTypes } from '../../constants/FormStepTypes';
2
2
  const push = (step, idStep, into) => {
3
3
  if (!idStep)
4
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;
5
12
  if (step.dependencies?.includes(idStep))
6
13
  return;
7
14
  if (!into.includes(idStep))
@@ -61,6 +61,13 @@ describe('entityValuePickerWatchedSteps', () => {
61
61
  });
62
62
  expect(entityValuePickerWatchedSteps(step)).toEqual(['shared']);
63
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
+ });
64
71
  });
65
72
  describe('entityValuePickerBlockingSteps', () => {
66
73
  test('only the path hops and the required filters block the fetch', () => {
@@ -78,4 +85,11 @@ describe('entityValuePickerBlockingSteps', () => {
78
85
  });
79
86
  expect(entityValuePickerBlockingSteps(step)).toEqual([]);
80
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
+ });
81
95
  });
@@ -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;
@@ -67,6 +74,20 @@ export declare const selectStepDependencies: ((state: RootState, _step: GBaseSte
67
74
  memoize: typeof import("reselect").weakMapMemoize;
68
75
  argsMemoize: typeof import("reselect").weakMapMemoize;
69
76
  };
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[];
70
91
  export interface UseFormStepOptions<ValueType> {
71
92
  defaultValue: ValueType;
72
93
  /** If true, will not trigger onChange until the user has finished typing */
@@ -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);
@@ -66,24 +82,45 @@ export const selectStepDependencies = createSelector([
66
82
  }
67
83
  return { invalids, emptyDep };
68
84
  });
69
- const calcDeepDependencies = (idStep, form, deps = []) => {
70
- const step = form.steps[idStep];
71
- if (!step)
72
- return deps;
73
- /**
74
- * An entity picker also gives up (its options resolve to null) while a path hop or a required
75
- * STEP filter holds no value. Those are in `step.dependencies` once the form has been saved,
76
- * but not in an unsaved draft, so they are added here to read as a missing dependency instead
77
- * of as a failed load.
78
- */
79
- const idDeps = step.type === FormStepTypes.ENTITYVALUEPICKER
80
- ? [...(step.dependencies ?? []), ...entityValuePickerBlockingSteps(step)]
81
- : step.dependencies;
82
- for (const dep of idDeps ?? []) {
83
- if (!deps.includes(dep)) {
84
- deps.push(...calcDeepDependencies(dep, form, deps), dep);
85
+ /**
86
+ * The steps `idStep` depends on, transitively: every dependency's own dependencies come before it,
87
+ * and every id is answered exactly once. `idStep` itself is never listed — a step is not a
88
+ * dependency of itself, even when a draft points it back at itself.
89
+ *
90
+ * A saved form is a DAG: the backend recomputes and validates `step.dependencies` on save. The
91
+ * editor's live preview renders unsaved drafts though, where a filter or a path hop can still point
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);
85
121
  }
86
- }
122
+ };
123
+ walk(idStep);
87
124
  return deps;
88
125
  };
89
126
  export const useFormStep = (step, { rules, debounce, sizeChange, defaultValue }) => {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,92 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import FormStepTypes, { EntityValueDataTypes } from '../constants/FormStepTypes';
3
+ import { calcDeepDependencies } from './StepHooks';
4
+ const form = (steps) => ({
5
+ steps: Object.entries(steps).reduce((acc, [id, step]) => ({
6
+ ...acc,
7
+ [id]: { id, idSection: 'section', type: FormStepTypes.TEXTINPUT, ...step },
8
+ }), {}),
9
+ });
10
+ const picker = (step) => ({
11
+ type: FormStepTypes.ENTITYVALUEPICKER,
12
+ idEntity: 'entity',
13
+ path: [],
14
+ filters: [],
15
+ options: {},
16
+ ...step,
17
+ });
18
+ const stepFilter = (idStep, required) => ({
19
+ idProperty: 'prop-' + idStep,
20
+ type: EntityValueDataTypes.STEP,
21
+ idStep,
22
+ any: false,
23
+ required,
24
+ });
25
+ describe('calcDeepDependencies', () => {
26
+ test('walks a linear chain deepest first, listing each id once', () => {
27
+ const deps = calcDeepDependencies('a', form({
28
+ a: { dependencies: ['b'] },
29
+ b: { dependencies: ['c'] },
30
+ c: {},
31
+ }));
32
+ expect(deps).toEqual(['c', 'b']);
33
+ });
34
+ test('lists a dependency shared by two branches once', () => {
35
+ const deps = calcDeepDependencies('a', form({
36
+ a: { dependencies: ['b', 'c'] },
37
+ b: { dependencies: ['d'] },
38
+ c: { dependencies: ['d'] },
39
+ d: {},
40
+ }));
41
+ expect(deps).toEqual(['d', 'b', 'c']);
42
+ });
43
+ test('terminates on an A -> B -> A cycle without listing the step itself', () => {
44
+ const deps = calcDeepDependencies('a', form({
45
+ a: { dependencies: ['b'] },
46
+ b: { dependencies: ['a'] },
47
+ }));
48
+ expect(deps).toEqual(['b']);
49
+ });
50
+ test('terminates on a cycle reached deeper in the walk', () => {
51
+ const deps = calcDeepDependencies('a', form({
52
+ a: { dependencies: ['b'] },
53
+ b: { dependencies: ['c'] },
54
+ c: { dependencies: ['b'] },
55
+ }));
56
+ expect(deps).toEqual(['c', 'b']);
57
+ });
58
+ test('terminates on a step that depends on itself', () => {
59
+ const deps = calcDeepDependencies('a', form({
60
+ a: { dependencies: ['b'] },
61
+ b: { dependencies: ['b'] },
62
+ }));
63
+ expect(deps).toEqual(['b']);
64
+ });
65
+ /**
66
+ * A draft an entity picker points back at itself with a required STEP filter: the filter is not
67
+ * in the saved `dependencies` yet, so it only reaches the walk through
68
+ * `entityValuePickerBlockingSteps`.
69
+ */
70
+ test('terminates on a self reference through a required STEP filter of an entity picker', () => {
71
+ const deps = calcDeepDependencies('a', form({
72
+ a: { dependencies: ['picker'] },
73
+ picker: picker({ filters: [stepFilter('picker', true)] }),
74
+ }));
75
+ expect(deps).toEqual(['picker']);
76
+ });
77
+ test('terminates on a cycle closed by a required STEP filter of an entity picker', () => {
78
+ const deps = calcDeepDependencies('a', form({
79
+ a: { dependencies: ['picker'] },
80
+ picker: picker({ filters: [stepFilter('other', true)] }),
81
+ other: { dependencies: ['picker'] },
82
+ }));
83
+ expect(deps).toEqual(['other', 'picker']);
84
+ });
85
+ test('keeps a dependency whose step the draft has already deleted', () => {
86
+ const deps = calcDeepDependencies('a', form({ a: { dependencies: ['gone'] } }));
87
+ expect(deps).toEqual(['gone']);
88
+ });
89
+ test('answers nothing for a step the form does not hold', () => {
90
+ expect(calcDeepDependencies('missing', form({}))).toEqual([]);
91
+ });
92
+ });
@@ -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.65",
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",