@arquimedes.co/eureka-forms 3.0.64 → 3.0.65
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/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +10 -21
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.d.ts +12 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.js +35 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.d.ts +1 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.js +31 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.d.ts +27 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.js +57 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.d.ts +1 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.js +81 -0
- package/dist/FormSteps/StepHooks.js +15 -5
- package/package.json +1 -1
|
@@ -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();
|
|
@@ -173,12 +175,9 @@ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, id
|
|
|
173
175
|
break;
|
|
174
176
|
}
|
|
175
177
|
case EntityValueDataTypes.STEP: {
|
|
176
|
-
const currentValue = dependencyStore[filter.idStep]
|
|
177
|
-
if (currentValue) {
|
|
178
|
-
|
|
179
|
-
params.set(filter.idProperty, currentValue);
|
|
180
|
-
else
|
|
181
|
-
params.set(filter.idProperty, currentValue._id ?? currentValue.id);
|
|
178
|
+
const currentValue = entityValueDependencyValue(dependencyStore[filter.idStep]);
|
|
179
|
+
if (currentValue !== undefined) {
|
|
180
|
+
params.set(filter.idProperty, currentValue);
|
|
182
181
|
}
|
|
183
182
|
else if (filter.required) {
|
|
184
183
|
return null;
|
|
@@ -201,18 +200,8 @@ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, id
|
|
|
201
200
|
});
|
|
202
201
|
return response.data.filter((option) => step.options[option._id]?.type !== EntityValueOptionTypes.HIDE);
|
|
203
202
|
};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
};
|
|
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);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StepDependency } from '../../Form/Form';
|
|
2
|
+
/**
|
|
3
|
+
* Serializes the current value of a dependency step into the string an entity-picker STEP filter
|
|
4
|
+
* sends as `values.<idProperty>` query param.
|
|
5
|
+
*
|
|
6
|
+
* Entity values (and any id-bearing object) resolve to their id. The answer of a Selector or
|
|
7
|
+
* Classifier step is a `{ label, value }` option: a Selector keeps `value === label`, so its `value`
|
|
8
|
+
* is the text the entity property stores; a Classifier's `value` is the classifier id, which no
|
|
9
|
+
* entity property holds, so it resolves to its `label`. Returns undefined when the dependency has
|
|
10
|
+
* no usable value, so the caller treats the filter as unresolved.
|
|
11
|
+
*/
|
|
12
|
+
export declare function entityValueDependencyValue(dependency: StepDependency | undefined): string | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import FormStepTypes from '../../constants/FormStepTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Serializes the current value of a dependency step into the string an entity-picker STEP filter
|
|
4
|
+
* sends as `values.<idProperty>` query param.
|
|
5
|
+
*
|
|
6
|
+
* Entity values (and any id-bearing object) resolve to their id. The answer of a Selector or
|
|
7
|
+
* Classifier step is a `{ label, value }` option: a Selector keeps `value === label`, so its `value`
|
|
8
|
+
* is the text the entity property stores; a Classifier's `value` is the classifier id, which no
|
|
9
|
+
* entity property holds, so it resolves to its `label`. Returns undefined when the dependency has
|
|
10
|
+
* no usable value, so the caller treats the filter as unresolved.
|
|
11
|
+
*/
|
|
12
|
+
export function entityValueDependencyValue(dependency) {
|
|
13
|
+
const currentValue = dependency?.value;
|
|
14
|
+
if (currentValue === null || currentValue === undefined || currentValue === '')
|
|
15
|
+
return undefined;
|
|
16
|
+
if (typeof currentValue === 'string')
|
|
17
|
+
return currentValue;
|
|
18
|
+
if (typeof currentValue === 'number' || typeof currentValue === 'boolean')
|
|
19
|
+
return String(currentValue);
|
|
20
|
+
if (currentValue instanceof Date)
|
|
21
|
+
return currentValue.toISOString();
|
|
22
|
+
if (typeof currentValue !== 'object')
|
|
23
|
+
return undefined;
|
|
24
|
+
const record = currentValue;
|
|
25
|
+
// A Selector's `value` is the stored text; every other step's `value` may be an id, so its `label` wins.
|
|
26
|
+
const keys = dependency?.type === FormStepTypes.SELECTOR ? ['_id', 'id', 'value', 'label'] : ['_id', 'id', 'label', 'value'];
|
|
27
|
+
for (const key of keys) {
|
|
28
|
+
const candidate = record[key];
|
|
29
|
+
if (typeof candidate === 'string' && candidate !== '')
|
|
30
|
+
return candidate;
|
|
31
|
+
if (typeof candidate === 'number')
|
|
32
|
+
return String(candidate);
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import FormStepTypes from '../../constants/FormStepTypes';
|
|
3
|
+
import { entityValueDependencyValue } from './entityValueDependencyValue';
|
|
4
|
+
const dep = (type, value) => ({
|
|
5
|
+
idOriginal: 'dep',
|
|
6
|
+
dependents: [],
|
|
7
|
+
type,
|
|
8
|
+
value,
|
|
9
|
+
});
|
|
10
|
+
describe('entityValueDependencyValue', () => {
|
|
11
|
+
test('an unanswered dependency is unresolved', () => {
|
|
12
|
+
expect(entityValueDependencyValue(undefined)).toBeUndefined();
|
|
13
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, null))).toBeUndefined();
|
|
14
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, ''))).toBeUndefined();
|
|
15
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, {}))).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
test('plain answers are sent as text', () => {
|
|
18
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.TEXTINPUT, 'Torre 3'))).toBe('Torre 3');
|
|
19
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.TEXTINPUT, 7))).toBe('7');
|
|
20
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.DATEPICKER, new Date('2026-01-02T00:00:00.000Z')))).toBe('2026-01-02T00:00:00.000Z');
|
|
21
|
+
});
|
|
22
|
+
test('an entity value resolves to its id', () => {
|
|
23
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.ENTITYVALUEPICKER, { _id: 'ev-1', label: 'Morros' }))).toBe('ev-1');
|
|
24
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.API_SELECTOR, { id: 'api-1', label: 'X' }))).toBe('api-1');
|
|
25
|
+
});
|
|
26
|
+
test('a selector option resolves to its value, a classifier option to its label', () => {
|
|
27
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, { label: 'Piso 2', value: 'Piso 2' }))).toBe('Piso 2');
|
|
28
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, { label: 'Dos', value: '2' }))).toBe('2');
|
|
29
|
+
expect(entityValueDependencyValue(dep(FormStepTypes.CLASSIFIER_SELECTOR, { label: 'Piso 2', value: '65f0c1a2b3c4d5e6f7a8b9c0' }))).toBe('Piso 2');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EntityValuePicker } from '../../@Types/FormStep';
|
|
2
|
+
/**
|
|
3
|
+
* The steps an entity picker reads a value from that `step.dependencies` does not already list:
|
|
4
|
+
* the STEP hops of `step.path` and every STEP filter, required or not.
|
|
5
|
+
*
|
|
6
|
+
* `step.dependencies` is recomputed server-side only when the form is saved
|
|
7
|
+
* (`FormDependencyFunctions.calcStepDependencies`), so it describes the form as it was at the last
|
|
8
|
+
* save. In the editor's live preview of an unsaved draft — and in any form whose stored
|
|
9
|
+
* dependencies went stale — a path hop or a filter added since then is missing from it, and the
|
|
10
|
+
* renderer would never watch the step it points at. The picker refetches its options when a watched
|
|
11
|
+
* value changes, so a filter the picker does not watch never triggers the fetch that would honour
|
|
12
|
+
* it: a required one leaves the select stuck with no options at all, an optional one leaves it
|
|
13
|
+
* showing options the filter should have narrowed.
|
|
14
|
+
*
|
|
15
|
+
* The `required` flag is deliberately not consulted: required or not, the filter's value is what
|
|
16
|
+
* has to trigger the refetch. Steps the last save already registered are skipped because the
|
|
17
|
+
* renderer watches `step.dependencies` anyway.
|
|
18
|
+
*/
|
|
19
|
+
export declare function entityValuePickerWatchedSteps(step: EntityValuePicker): string[];
|
|
20
|
+
/**
|
|
21
|
+
* The subset of `entityValuePickerWatchedSteps` whose value the picker cannot do without: every
|
|
22
|
+
* STEP hop of the path, and the STEP filters flagged `required`. Those are exactly the cases where
|
|
23
|
+
* `getEntityValueOptions` gives up and answers `null` — its "dependency not met" contract — so
|
|
24
|
+
* while they hold no value the select has to read as a missing dependency rather than as a failed
|
|
25
|
+
* load.
|
|
26
|
+
*/
|
|
27
|
+
export declare function entityValuePickerBlockingSteps(step: EntityValuePicker): string[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EntityValueDataTypes } from '../../constants/FormStepTypes';
|
|
2
|
+
const push = (step, idStep, into) => {
|
|
3
|
+
if (!idStep)
|
|
4
|
+
return;
|
|
5
|
+
if (step.dependencies?.includes(idStep))
|
|
6
|
+
return;
|
|
7
|
+
if (!into.includes(idStep))
|
|
8
|
+
into.push(idStep);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The steps an entity picker reads a value from that `step.dependencies` does not already list:
|
|
12
|
+
* the STEP hops of `step.path` and every STEP filter, required or not.
|
|
13
|
+
*
|
|
14
|
+
* `step.dependencies` is recomputed server-side only when the form is saved
|
|
15
|
+
* (`FormDependencyFunctions.calcStepDependencies`), so it describes the form as it was at the last
|
|
16
|
+
* save. In the editor's live preview of an unsaved draft — and in any form whose stored
|
|
17
|
+
* dependencies went stale — a path hop or a filter added since then is missing from it, and the
|
|
18
|
+
* renderer would never watch the step it points at. The picker refetches its options when a watched
|
|
19
|
+
* value changes, so a filter the picker does not watch never triggers the fetch that would honour
|
|
20
|
+
* it: a required one leaves the select stuck with no options at all, an optional one leaves it
|
|
21
|
+
* showing options the filter should have narrowed.
|
|
22
|
+
*
|
|
23
|
+
* The `required` flag is deliberately not consulted: required or not, the filter's value is what
|
|
24
|
+
* has to trigger the refetch. Steps the last save already registered are skipped because the
|
|
25
|
+
* renderer watches `step.dependencies` anyway.
|
|
26
|
+
*/
|
|
27
|
+
export function entityValuePickerWatchedSteps(step) {
|
|
28
|
+
const watched = [];
|
|
29
|
+
for (const path of step.path) {
|
|
30
|
+
if (path.type === EntityValueDataTypes.STEP)
|
|
31
|
+
push(step, path.idStep, watched);
|
|
32
|
+
}
|
|
33
|
+
for (const filter of step.filters) {
|
|
34
|
+
if (filter.type === EntityValueDataTypes.STEP)
|
|
35
|
+
push(step, filter.idStep, watched);
|
|
36
|
+
}
|
|
37
|
+
return watched;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The subset of `entityValuePickerWatchedSteps` whose value the picker cannot do without: every
|
|
41
|
+
* STEP hop of the path, and the STEP filters flagged `required`. Those are exactly the cases where
|
|
42
|
+
* `getEntityValueOptions` gives up and answers `null` — its "dependency not met" contract — so
|
|
43
|
+
* while they hold no value the select has to read as a missing dependency rather than as a failed
|
|
44
|
+
* load.
|
|
45
|
+
*/
|
|
46
|
+
export function entityValuePickerBlockingSteps(step) {
|
|
47
|
+
const blocking = [];
|
|
48
|
+
for (const path of step.path) {
|
|
49
|
+
if (path.type === EntityValueDataTypes.STEP)
|
|
50
|
+
push(step, path.idStep, blocking);
|
|
51
|
+
}
|
|
52
|
+
for (const filter of step.filters) {
|
|
53
|
+
if (filter.type === EntityValueDataTypes.STEP && filter.required)
|
|
54
|
+
push(step, filter.idStep, blocking);
|
|
55
|
+
}
|
|
56
|
+
return blocking;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
});
|
|
65
|
+
describe('entityValuePickerBlockingSteps', () => {
|
|
66
|
+
test('only the path hops and the required filters block the fetch', () => {
|
|
67
|
+
const step = picker({
|
|
68
|
+
path: [stepPath('hop')],
|
|
69
|
+
filters: [stepFilter('required', true), stepFilter('optional', false)],
|
|
70
|
+
});
|
|
71
|
+
expect(entityValuePickerBlockingSteps(step)).toEqual(['hop', 'required']);
|
|
72
|
+
});
|
|
73
|
+
test('a saved dependency is already watched deeply, so it is not repeated', () => {
|
|
74
|
+
const step = picker({
|
|
75
|
+
dependencies: ['hop', 'required'],
|
|
76
|
+
path: [stepPath('hop')],
|
|
77
|
+
filters: [stepFilter('required', true)],
|
|
78
|
+
});
|
|
79
|
+
expect(entityValuePickerBlockingSteps(step)).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -8,6 +8,7 @@ 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';
|
|
11
12
|
const selectIsDependency = createSelector([
|
|
12
13
|
(state) => state.site.dependencies,
|
|
13
14
|
(_state, step) => step,
|
|
@@ -67,11 +68,20 @@ export const selectStepDependencies = createSelector([
|
|
|
67
68
|
});
|
|
68
69
|
const calcDeepDependencies = (idStep, form, deps = []) => {
|
|
69
70
|
const step = form.steps[idStep];
|
|
70
|
-
if (step
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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);
|
|
75
85
|
}
|
|
76
86
|
}
|
|
77
87
|
return deps;
|
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.
|
|
4
|
+
"version": "3.0.65",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"watch": "node node_modules/@typescript/native/bin/tsc --noEmit --watch --project tsconfig.app.json",
|
|
7
7
|
"start": "vite",
|