awing-library 2.1.2-dev.542 → 2.1.2-dev.543
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../../src/AWING/DataForm/container.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../../src/AWING/DataForm/container.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,2CA4RzE"}
|
|
@@ -6,6 +6,9 @@ import { calculateFormValid, handleFields, updateFieldsWithFormulas } from "./ut
|
|
|
6
6
|
function DataForm(props) {
|
|
7
7
|
const { caption, actions, fields, onUpdate, onValues, padding = 'normal', onValidateForm, onFormValid, autoValidateFieldText = false, oldValue: propsOldValue, fieldPermissions } = props;
|
|
8
8
|
const [oldValue, setOldValue] = useState(propsOldValue);
|
|
9
|
+
const oldValueRef = useRef(propsOldValue);
|
|
10
|
+
const lastPropsOldValueStr = useRef(JSON.stringify(propsOldValue));
|
|
11
|
+
const isSyncingFromParent = useRef(false);
|
|
9
12
|
const [keyUpdate, setKey] = useState('');
|
|
10
13
|
const isFirstRender = useRef(true);
|
|
11
14
|
const [dataFormState, setDataFormState] = useState(()=>{
|
|
@@ -26,44 +29,51 @@ function DataForm(props) {
|
|
|
26
29
|
});
|
|
27
30
|
useEffect(()=>{
|
|
28
31
|
if (propsOldValue) {
|
|
29
|
-
const
|
|
32
|
+
const currentPropsStr = JSON.stringify(propsOldValue);
|
|
33
|
+
const isFirstLoad = !oldValueRef.current || 0 === Object.keys(oldValueRef.current).length;
|
|
30
34
|
const newId = propsOldValue?.id;
|
|
31
|
-
const currentId =
|
|
35
|
+
const currentId = oldValueRef.current?.id;
|
|
32
36
|
const isNewId = newId !== currentId;
|
|
33
|
-
const isNewVersion = propsOldValue?.versionId !==
|
|
34
|
-
const isContentDifferent =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
const isNewVersion = propsOldValue?.versionId !== oldValueRef.current?.versionId;
|
|
38
|
+
const isContentDifferent = currentPropsStr !== lastPropsOldValueStr.current;
|
|
39
|
+
if (isFirstLoad || isNewId || isNewVersion || isContentDifferent) {
|
|
40
|
+
lastPropsOldValueStr.current = currentPropsStr;
|
|
41
|
+
oldValueRef.current = propsOldValue;
|
|
42
|
+
setOldValue(propsOldValue);
|
|
43
|
+
isSyncingFromParent.current = true;
|
|
44
|
+
setDataFormState((pre)=>{
|
|
45
|
+
if (isFirstLoad || isNewId) {
|
|
46
|
+
const resetFields = {};
|
|
47
|
+
const newValidation = {};
|
|
48
|
+
fields.forEach((field)=>{
|
|
49
|
+
const fieldName = field.fieldName;
|
|
50
|
+
resetFields[fieldName] = propsOldValue[fieldName];
|
|
51
|
+
newValidation[fieldName] = true;
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
fieldsToUpdate: resetFields,
|
|
55
|
+
validation: newValidation
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const newFieldsToUpdate = {
|
|
59
|
+
...pre.fieldsToUpdate
|
|
60
|
+
};
|
|
61
|
+
Object.keys(propsOldValue).forEach((key)=>{
|
|
62
|
+
const fieldKey = key;
|
|
63
|
+
newFieldsToUpdate[fieldKey] = propsOldValue[fieldKey];
|
|
47
64
|
});
|
|
48
65
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
...pre,
|
|
67
|
+
fieldsToUpdate: newFieldsToUpdate
|
|
51
68
|
};
|
|
52
|
-
}
|
|
53
|
-
Object.keys(propsOldValue).forEach((key)=>{
|
|
54
|
-
const fieldKey = key;
|
|
55
|
-
newFieldsToUpdate[fieldKey] = propsOldValue[fieldKey];
|
|
56
69
|
});
|
|
57
|
-
|
|
58
|
-
...pre,
|
|
59
|
-
fieldsToUpdate: newFieldsToUpdate
|
|
60
|
-
};
|
|
61
|
-
});
|
|
70
|
+
}
|
|
62
71
|
}
|
|
63
72
|
}, [
|
|
64
73
|
JSON.stringify(propsOldValue)
|
|
65
74
|
]);
|
|
66
75
|
const handleChange = (fieldName, newValue, valid)=>{
|
|
76
|
+
isSyncingFromParent.current = false;
|
|
67
77
|
setDataFormState((pre)=>{
|
|
68
78
|
let newFieldsToUpdate = {
|
|
69
79
|
...pre.fieldsToUpdate
|
|
@@ -95,7 +105,7 @@ function DataForm(props) {
|
|
|
95
105
|
}
|
|
96
106
|
const convertFields = fields.map((field)=>({
|
|
97
107
|
fieldName: String(field.fieldName),
|
|
98
|
-
value: String(newFieldsToUpdate[field.fieldName] ??
|
|
108
|
+
value: String(newFieldsToUpdate[field.fieldName] ?? oldValueRef.current?.[field.fieldName] ?? '')
|
|
99
109
|
}));
|
|
100
110
|
const convertFormulas = fields.filter((field)=>field.autoFormula).map((field)=>({
|
|
101
111
|
fieldName: String(field.fieldName ?? ''),
|
|
@@ -115,21 +125,26 @@ function DataForm(props) {
|
|
|
115
125
|
setKey(String(fieldName));
|
|
116
126
|
};
|
|
117
127
|
useEffect(()=>{
|
|
118
|
-
if (
|
|
119
|
-
|
|
128
|
+
if (isSyncingFromParent.current) {
|
|
129
|
+
isSyncingFromParent.current = false;
|
|
120
130
|
return;
|
|
121
131
|
}
|
|
132
|
+
const currentOldValue = oldValueRef.current;
|
|
122
133
|
const completeValues = {
|
|
123
|
-
...
|
|
134
|
+
...currentOldValue,
|
|
124
135
|
...dataFormState.fieldsToUpdate
|
|
125
136
|
};
|
|
126
|
-
const formValid = calculateFormValid(dataFormState, fields,
|
|
137
|
+
const formValid = calculateFormValid(dataFormState, fields, currentOldValue, onValidateForm, onFormValid);
|
|
138
|
+
if (isFirstRender.current) {
|
|
139
|
+
isFirstRender.current = false;
|
|
140
|
+
if (onValues) onValues(completeValues, formValid, keyUpdate);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
127
143
|
if (onUpdate) onUpdate(dataFormState.fieldsToUpdate, formValid, keyUpdate);
|
|
128
144
|
if (onValues) onValues(completeValues, formValid, keyUpdate);
|
|
129
145
|
}, [
|
|
130
146
|
dataFormState,
|
|
131
|
-
keyUpdate
|
|
132
|
-
oldValue
|
|
147
|
+
keyUpdate
|
|
133
148
|
]);
|
|
134
149
|
const renderField = (fieldDef)=>{
|
|
135
150
|
const { fieldName } = fieldDef;
|
|
@@ -6,7 +6,7 @@ import { fireEvent, render, screen } from "@testing-library/react";
|
|
|
6
6
|
import { Constants } from "../../Commons/Constant.js";
|
|
7
7
|
import container from "./container.js";
|
|
8
8
|
var __webpack_modules__ = {
|
|
9
|
-
"
|
|
9
|
+
"../DataInput": function(module) {
|
|
10
10
|
module.exports = __WEBPACK_EXTERNAL_MODULE__DataInput_index_js_c7933a4f__;
|
|
11
11
|
},
|
|
12
12
|
"../helper": function(module) {
|
|
@@ -23,7 +23,7 @@ function __webpack_require__(moduleId) {
|
|
|
23
23
|
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
24
24
|
return module.exports;
|
|
25
25
|
}
|
|
26
|
-
var index_js_ = __webpack_require__("
|
|
26
|
+
var index_js_ = __webpack_require__("../DataInput");
|
|
27
27
|
jest.mock('../DataInput', ()=>({
|
|
28
28
|
__esModule: true,
|
|
29
29
|
default: jest.fn(),
|
|
@@ -91,7 +91,7 @@ jest.mock('@mui/material', ()=>({
|
|
|
91
91
|
children: children
|
|
92
92
|
})
|
|
93
93
|
}));
|
|
94
|
-
const mockInputFactory = __webpack_require__("
|
|
94
|
+
const mockInputFactory = __webpack_require__("../DataInput")["default"];
|
|
95
95
|
const mockCalculateValue = __webpack_require__("../helper").calculateValue;
|
|
96
96
|
const mockConvertFormulaToBinaryTree = __webpack_require__("../helper").convertFormulaToBinaryTree;
|
|
97
97
|
const mockReplaceFieldsValue = __webpack_require__("../helper").replaceFieldsValue;
|
|
@@ -5,7 +5,7 @@ import { act, fireEvent, render, screen, waitFor } from "@testing-library/react"
|
|
|
5
5
|
import containerOptimized from "./containerOptimized.js";
|
|
6
6
|
import { createFormStateManager } from "./formStateManager.js";
|
|
7
7
|
var __webpack_modules__ = {
|
|
8
|
-
"
|
|
8
|
+
"../DataInput": function(module) {
|
|
9
9
|
module.exports = __WEBPACK_EXTERNAL_MODULE__DataInput_index_js_c7933a4f__;
|
|
10
10
|
}
|
|
11
11
|
};
|
|
@@ -98,7 +98,7 @@ jest.mock('@mui/material', ()=>({
|
|
|
98
98
|
children: children
|
|
99
99
|
})
|
|
100
100
|
}));
|
|
101
|
-
const mockInputFactory = __webpack_require__("
|
|
101
|
+
const mockInputFactory = __webpack_require__("../DataInput")["default"];
|
|
102
102
|
describe('DataForm Optimized - Performance Tests', ()=>{
|
|
103
103
|
let inputRenderCounts = {};
|
|
104
104
|
const mockFields = [
|