@arquimedes.co/eureka-forms 2.0.20-test → 2.0.22

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,5 +5,5 @@ import { CBRFormStep } from '../@Types/CBRFormStep';
5
5
  import { MapperElement } from '../@Types/MapperElement';
6
6
  import { ValuesStore } from '../States/SiteSlice';
7
7
  export declare const calcValue: (idStep: string, steps: Record<string, FormStep>, values: Record<string, any>, customSteps: Record<string, CustomStep> | undefined, deleteIds: string[], value?: any) => any;
8
- export declare function calcDependencies(steps: Record<string, FormStep | CBRFormStep>, customSteps?: Record<string, CustomStep>, allSteps?: Record<string, FormStep | CBRFormStep>, dependencies?: DependencyStore, values?: ValuesStore): DependencyStore;
8
+ export declare function calcDependencies(steps: Record<string, FormStep | CBRFormStep>, customSteps?: Record<string, CustomStep>, allSteps?: Record<string, FormStep | CBRFormStep>, dependencies?: DependencyStore, values?: ValuesStore, addDependents?: boolean): DependencyStore;
9
9
  export declare const calcMapperSubSteps: (step: Mapper, elements: MapperElement<any>[] | undefined, customSteps: Record<string, CustomStep>) => Record<string, FormStep>;
@@ -115,7 +115,7 @@ function stringToDraft(text) {
115
115
  });
116
116
  return draftStructure;
117
117
  }
118
- export function calcDependencies(steps, customSteps, allSteps, dependencies, values) {
118
+ export function calcDependencies(steps, customSteps, allSteps, dependencies, values, addDependents) {
119
119
  var _a, _b;
120
120
  if (customSteps === void 0) { customSteps = {}; }
121
121
  if (allSteps === void 0) { allSteps = steps; }
@@ -124,34 +124,39 @@ export function calcDependencies(steps, customSteps, allSteps, dependencies, val
124
124
  global: {},
125
125
  sections: {},
126
126
  }; }
127
+ if (addDependents === void 0) { addDependents = true; }
127
128
  for (var _i = 0, _c = Object.values(steps); _i < _c.length; _i++) {
128
129
  var step = _c[_i];
129
130
  var originalValue = (_a = values.sections[step.idSection]) === null || _a === void 0 ? void 0 : _a[step.id];
130
131
  if (step.dependencies) {
131
132
  for (var _d = 0, _e = step.dependencies; _d < _e.length; _d++) {
132
133
  var idDep = _e[_d];
133
- if (dependencies[idDep] === undefined)
134
+ if (dependencies[idDep] === undefined &&
135
+ (addDependents || allSteps[idDep]))
134
136
  dependencies[idDep] = calcStepDependency(idDep, allSteps, values, customSteps);
135
- dependencies[idDep].dependents.push(step);
137
+ if (addDependents)
138
+ dependencies[idDep].dependents.push(step);
136
139
  }
137
140
  }
138
141
  if (step.type === StepTypes.ENTITYVALUEPICKER) {
139
142
  for (var _f = 0, _g = __spreadArray(__spreadArray([], step.path, true), step.filters, true); _f < _g.length; _f++) {
140
- var path = _g[_f];
141
- if (path.type !== EntityValueDataTypes.STEP)
143
+ var dep = _g[_f];
144
+ if (dep.type !== EntityValueDataTypes.STEP)
142
145
  continue;
143
- if ((_b = step.dependencies) === null || _b === void 0 ? void 0 : _b.includes(path.idStep))
146
+ if ((_b = step.dependencies) === null || _b === void 0 ? void 0 : _b.includes(dep.idStep))
144
147
  continue;
145
- if (dependencies[path.idStep] === undefined) {
146
- dependencies[path.idStep] = calcStepDependency(path.idStep, allSteps, values, customSteps);
148
+ if (dependencies[dep.idStep] === undefined &&
149
+ (addDependents || allSteps[dep.idStep])) {
150
+ dependencies[dep.idStep] = calcStepDependency(dep.idStep, allSteps, values, customSteps);
147
151
  }
148
- dependencies[path.idStep].dependents.push(step);
152
+ if (addDependents)
153
+ dependencies[dep.idStep].dependents.push(step);
149
154
  }
150
155
  }
151
156
  if (step.type === StepTypes.MAPPER) {
152
157
  var subSteps = calcMapperSubSteps(step, originalValue, customSteps);
153
- if (Object.keys(subSteps).length > 0)
154
- calcDependencies(subSteps, customSteps, __assign(__assign({}, allSteps), subSteps), dependencies, values);
158
+ var hasSubSteps = Object.keys(subSteps).length > 0;
159
+ calcDependencies(hasSubSteps ? subSteps : step.steps, customSteps, __assign(__assign({}, allSteps), subSteps), dependencies, values, hasSubSteps);
155
160
  }
156
161
  }
157
162
  return dependencies;
@@ -7,5 +7,5 @@ export interface Incident {
7
7
  deleted?: boolean;
8
8
  num: number;
9
9
  }
10
- declare function CBRIncidentsStep(props: CBRIncidentsStepProps): JSX.Element;
10
+ declare function CBRIncidentsStep({ step, editable, ...others }: CBRIncidentsStepProps): JSX.Element;
11
11
  export default CBRIncidentsStep;
@@ -41,27 +41,36 @@ import FormContext from '../../../../Contexts/FormContext';
41
41
  import { addStepsDependencies } from '../../../../States/SiteSlice';
42
42
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
43
43
  import CustomContext from '../../../../Contexts/CustomContext';
44
- import { Controller } from 'react-hook-form';
45
- function Incidents(_a) {
46
- var step = _a.step, btnRef = _a.btnRef, editable = _a.editable, onChange = _a.onChange, incidents = _a.incidents, others = __rest(_a, ["step", "btnRef", "editable", "onChange", "incidents"]);
44
+ import { useFormStep } from '../../../StepHooks';
45
+ function CBRIncidentsStep(_a) {
46
+ var step = _a.step, editable = _a.editable, others = __rest(_a, ["step", "editable"]);
47
+ var _b = useFormStep(step, {
48
+ rules: {
49
+ validate: function (array) {
50
+ return !step.required ||
51
+ (step.required &&
52
+ array.filter(function (elem) { return !elem.deleted; }).length > 0);
53
+ },
54
+ },
55
+ }), ref = _b.ref, value = _b.value, onChange = _b.onChange, error = _b.error;
47
56
  var customSteps = useContext(CustomContext).customSteps;
48
- var _b = useAppSelector(function (state) { return state.global; }), formStyle = _b.formStyle, postview = _b.postview;
57
+ var _c = useAppSelector(function (state) { return state.global; }), formStyle = _c.formStyle, postview = _c.postview;
49
58
  var dispatch = useAppDispatch();
50
59
  var form = useContext(FormContext);
51
60
  /** Form to pass down with aditional steps */
52
- var _c = useState(__assign(__assign({}, form), { steps: __assign({}, form.steps) })), localForm = _c[0], setLocalForm = _c[1];
53
- var _d = useState(false), firstRender = _d[0], setFirstRender = _d[1];
61
+ var _d = useState(__assign(__assign({}, form), { steps: __assign({}, form.steps) })), localForm = _d[0], setLocalForm = _d[1];
62
+ var _e = useState(false), firstRender = _e[0], setFirstRender = _e[1];
54
63
  useEffect(function () {
55
64
  setFirstRender(true);
56
65
  }, []);
57
66
  useEffect(function () {
58
- if (firstRender && incidents.length === 0 && !postview && editable) {
67
+ if (firstRender && value.length === 0 && !postview && editable) {
59
68
  handleAddIncident();
60
69
  }
61
70
  }, [firstRender]);
62
71
  var handleAddIncident = function () {
63
72
  var _a, _b;
64
- var current = incidents.filter(function (incident) { return !incident.deleted; });
73
+ var current = value.filter(function (incident) { return !incident.deleted; });
65
74
  var newIncident = {
66
75
  idSpaceStep: CBRFormStepTypes.CBR_TIPO_ESPACIO + '-' + nanoid(),
67
76
  idCommentStep: CBRFormStepTypes.CBR_COMENTARIO + '-' + nanoid(),
@@ -72,7 +81,7 @@ function Incidents(_a) {
72
81
  newSteps[newIncident.idSpaceStep] = __assign(__assign({}, step.spaceStep), { id: newIncident.idSpaceStep, type: CBRFormStepTypes.CBR_TIPO_ESPACIO, dependencies: step.dependencies });
73
82
  newSteps[newIncident.idCommentStep] = __assign(__assign({}, step.commentStep), { id: newIncident.idCommentStep, type: CBRFormStepTypes.CBR_COMENTARIO });
74
83
  addRecursiveElementStep(newIncident.idElementStep, step.elementStep, null, newSteps, (_b = (_a = step.dependencies) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '');
75
- onChange(__spreadArray(__spreadArray([], incidents, true), [newIncident], false));
84
+ onChange(__spreadArray(__spreadArray([], value, true), [newIncident], false));
76
85
  setLocalForm(__assign(__assign({}, localForm), { steps: newSteps }));
77
86
  dispatch(addStepsDependencies({
78
87
  steps: newSteps,
@@ -98,8 +107,8 @@ function Incidents(_a) {
98
107
  margin: step.description
99
108
  ? '10px 0px'
100
109
  : '0px 0px 5px 0px',
101
- } }, { children: step.description }))), _jsx(FormContext.Provider, __assign({ value: localForm }, { children: incidents.map(function (incident, index) { return (_jsx(IncidentComponent, __assign({ incident: incident, step: step, editable: editable, handleDelete: function () {
102
- var tempIncidents = __spreadArray([], incidents, true);
110
+ } }, { children: step.description }))), _jsx(FormContext.Provider, __assign({ value: localForm }, { children: value.map(function (incident, index) { return (_jsx(IncidentComponent, __assign({ incident: incident, step: step, editable: editable, handleDelete: function () {
111
+ var tempIncidents = __spreadArray([], value, true);
103
112
  tempIncidents[index].deleted = true;
104
113
  var n = 1;
105
114
  for (var _i = 0, tempIncidents_1 = tempIncidents; _i < tempIncidents_1.length; _i++) {
@@ -110,20 +119,10 @@ function Incidents(_a) {
110
119
  }
111
120
  }
112
121
  onChange(tempIncidents);
113
- } }, others), index)); }) })), _jsxs("div", __assign({ className: styles.btnContainer }, { children: [_jsx("input", { ref: btnRef, className: 'hidden-input' }), _jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel, color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
122
+ } }, others), index)); }) })), _jsxs("div", __assign({ className: styles.btnContainer }, { children: [_jsx("input", { ref: ref, className: 'hidden-input' }), _jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel + (step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
114
123
  if (editable && !postview) {
115
124
  handleAddIncident();
116
125
  }
117
- } })] }))] })));
118
- }
119
- function CBRIncidentsStep(props) {
120
- return (_jsx(Controller, { name: props.step.id, defaultValue: [], rules: {
121
- required: props.step.required
122
- ? 'Este campo es obligatorio'
123
- : undefined,
124
- }, shouldUnregister: true, render: function (_a) {
125
- var _b = _a.field, ref = _b.ref, value = _b.value, field = __rest(_b, ["ref", "value"]);
126
- return (_jsx(Incidents, __assign({}, props, field, { incidents: value, onChange: field.onChange, btnRef: ref })));
127
- } }));
126
+ } })] })), !!error && value.filter(function (elem) { return !elem.deleted; }).length === 0 && (_jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: "Este campo es obligatorio" })))] })));
128
127
  }
129
128
  export default CBRIncidentsStep;
@@ -26,3 +26,9 @@
26
26
  margin-bottom: 3px;
27
27
  width: fit-content;
28
28
  }
29
+
30
+ .errorMsg {
31
+ font-size: 0.75rem;
32
+ margin-top: 5px;
33
+ margin-left: 15px;
34
+ }
@@ -127,6 +127,7 @@ export var calcDefaultValue = function (step) {
127
127
  return null;
128
128
  case StepTypes.MAPPER:
129
129
  case StepTypes.FILEUPLOAD:
130
+ case CBRFormStepTypes.CBR_INCIDENCIAS:
130
131
  return [];
131
132
  case StepTypes.COLLAPSIBLE:
132
133
  return false;
@@ -126,9 +126,9 @@ function TextAreaStep(_a) {
126
126
  if (canEdit) {
127
127
  setFocus(true);
128
128
  }
129
- } }, { children: _jsx(Editor, __assign({}, field, { editorRef: ref, onFocus: function () {
129
+ }, "data-testid": step.id }, { children: _jsx(Editor, __assign({}, field, { editorRef: ref, onFocus: function () {
130
130
  setFocus(true);
131
- }, readOnly: !canEdit, stripPastedStyles: true, onEditorStateChange: handleChange, toolbarClassName: !canEdit ? ' postview-editor-toolbar' : '', "data-testid": step.id, editorClassName: editorClassName, wrapperClassName: styles.wrapper, placeholder: (_b = step.description) !== null && _b !== void 0 ? _b : '', toolbar: {
131
+ }, readOnly: !canEdit, stripPastedStyles: true, onEditorStateChange: handleChange, toolbarClassName: !canEdit ? ' postview-editor-toolbar' : '', editorClassName: editorClassName, wrapperClassName: styles.wrapper, placeholder: (_b = step.description) !== null && _b !== void 0 ? _b : '', toolbar: {
132
132
  options: ['inline', 'list', 'history'],
133
133
  inline: {
134
134
  options: [
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":"2.0.20-test",
4
+ "version": "2.0.22",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",
@@ -9,7 +9,7 @@
9
9
  "test": "react-scripts test",
10
10
  "test-ci": "react-scripts test --reporters=default --reporters=jest-junit --coverage --coverageReporters cobertura html",
11
11
  "tsc-build": "tsc --noEmit false --outDir ./dist --incremental false",
12
- "watch": "tsc -w --preserveWatchOutput",
12
+ "watch": "tsc -w --noEmit false --outDir ./dist --preserveWatchOutput",
13
13
  "storybook": "storybook dev -p 6006",
14
14
  "build-storybook": "storybook build",
15
15
  "cypress": "DISPLAY=:0 cypress open"