awing-library 2.1.2-dev.541 → 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.
- package/dist/AWING/AsyncAutocomplete/Container.d.ts.map +1 -1
- package/dist/AWING/AsyncAutocomplete/Container.js +2 -2
- package/dist/AWING/DataForm/container.d.ts.map +1 -1
- package/dist/AWING/DataForm/container.js +58 -22
- package/dist/AWING/DataForm/utils.d.ts.map +1 -1
- package/dist/AWING/DataForm/utils.js +3 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Container.d.ts","sourceRoot":"","sources":["../../../src/AWING/AsyncAutocomplete/Container.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"Container.d.ts","sourceRoot":"","sources":["../../../src/AWING/AsyncAutocomplete/Container.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,2CA+N5E"}
|
|
@@ -21,9 +21,9 @@ function AsyncAutocomplete(props) {
|
|
|
21
21
|
const [isOpen, setIsOpen] = useState(open ?? false);
|
|
22
22
|
const [fetched, setFetched] = useState(false);
|
|
23
23
|
useEffect(()=>{
|
|
24
|
-
|
|
24
|
+
value && Object.keys(value).length > 0 ? setInputValue(getOptionLabel(value)) : setInputValue('');
|
|
25
25
|
}, [
|
|
26
|
-
value
|
|
26
|
+
JSON.stringify(value)
|
|
27
27
|
]);
|
|
28
28
|
const fetchRef = useRef(null);
|
|
29
29
|
useEffect(()=>{
|
|
@@ -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(()=>{
|
|
@@ -14,7 +17,9 @@ function DataForm(props) {
|
|
|
14
17
|
const isEditMode = !!(propsOldValue && Object.keys(propsOldValue).length > 0);
|
|
15
18
|
fields.forEach((fieldDef)=>{
|
|
16
19
|
const fieldName = fieldDef.fieldName;
|
|
17
|
-
if (
|
|
20
|
+
if (isEditMode || void 0 === fieldDef.defaultValue) {
|
|
21
|
+
if (isEditMode && propsOldValue) fieldsToUpdate[fieldName] = propsOldValue[fieldName];
|
|
22
|
+
} else fieldsToUpdate[fieldName] = fieldDef.defaultValue;
|
|
18
23
|
validation[fieldName] = true;
|
|
19
24
|
});
|
|
20
25
|
return {
|
|
@@ -24,25 +29,51 @@ function DataForm(props) {
|
|
|
24
29
|
});
|
|
25
30
|
useEffect(()=>{
|
|
26
31
|
if (propsOldValue) {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const currentPropsStr = JSON.stringify(propsOldValue);
|
|
33
|
+
const isFirstLoad = !oldValueRef.current || 0 === Object.keys(oldValueRef.current).length;
|
|
34
|
+
const newId = propsOldValue?.id;
|
|
35
|
+
const currentId = oldValueRef.current?.id;
|
|
36
|
+
const isNewId = newId !== currentId;
|
|
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];
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
...pre,
|
|
67
|
+
fieldsToUpdate: newFieldsToUpdate
|
|
68
|
+
};
|
|
35
69
|
});
|
|
36
|
-
|
|
37
|
-
fieldsToUpdate: {},
|
|
38
|
-
validation: newValidation
|
|
39
|
-
};
|
|
40
|
-
});
|
|
70
|
+
}
|
|
41
71
|
}
|
|
42
72
|
}, [
|
|
43
73
|
JSON.stringify(propsOldValue)
|
|
44
74
|
]);
|
|
45
75
|
const handleChange = (fieldName, newValue, valid)=>{
|
|
76
|
+
isSyncingFromParent.current = false;
|
|
46
77
|
setDataFormState((pre)=>{
|
|
47
78
|
let newFieldsToUpdate = {
|
|
48
79
|
...pre.fieldsToUpdate
|
|
@@ -50,13 +81,12 @@ function DataForm(props) {
|
|
|
50
81
|
let newValidation = {
|
|
51
82
|
...pre.validation
|
|
52
83
|
};
|
|
53
|
-
|
|
54
|
-
else if (newFieldsToUpdate[fieldName] !== newValue) newFieldsToUpdate[fieldName] = newValue;
|
|
84
|
+
newFieldsToUpdate[fieldName] = newValue;
|
|
55
85
|
newValidation[fieldName] = valid;
|
|
56
86
|
if (props.fieldDependencies && props.fieldDependencies[fieldName]) {
|
|
57
87
|
const dependentFields = props.fieldDependencies[fieldName];
|
|
58
88
|
dependentFields.forEach((depField)=>{
|
|
59
|
-
|
|
89
|
+
newFieldsToUpdate[depField] = void 0;
|
|
60
90
|
newValidation[depField] = void 0;
|
|
61
91
|
});
|
|
62
92
|
}
|
|
@@ -75,7 +105,7 @@ function DataForm(props) {
|
|
|
75
105
|
}
|
|
76
106
|
const convertFields = fields.map((field)=>({
|
|
77
107
|
fieldName: String(field.fieldName),
|
|
78
|
-
value: String(newFieldsToUpdate[field.fieldName] ??
|
|
108
|
+
value: String(newFieldsToUpdate[field.fieldName] ?? oldValueRef.current?.[field.fieldName] ?? '')
|
|
79
109
|
}));
|
|
80
110
|
const convertFormulas = fields.filter((field)=>field.autoFormula).map((field)=>({
|
|
81
111
|
fieldName: String(field.fieldName ?? ''),
|
|
@@ -95,15 +125,21 @@ function DataForm(props) {
|
|
|
95
125
|
setKey(String(fieldName));
|
|
96
126
|
};
|
|
97
127
|
useEffect(()=>{
|
|
98
|
-
if (
|
|
99
|
-
|
|
128
|
+
if (isSyncingFromParent.current) {
|
|
129
|
+
isSyncingFromParent.current = false;
|
|
100
130
|
return;
|
|
101
131
|
}
|
|
132
|
+
const currentOldValue = oldValueRef.current;
|
|
102
133
|
const completeValues = {
|
|
103
|
-
...
|
|
134
|
+
...currentOldValue,
|
|
104
135
|
...dataFormState.fieldsToUpdate
|
|
105
136
|
};
|
|
106
|
-
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
|
+
}
|
|
107
143
|
if (onUpdate) onUpdate(dataFormState.fieldsToUpdate, formValid, keyUpdate);
|
|
108
144
|
if (onValues) onValues(completeValues, formValid, keyUpdate);
|
|
109
145
|
}, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/AWING/DataForm/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGnE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,iBAC1B,aAAa,CAAC,CAAC,CAAC,YACrB,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,YACtB,oBAAoB,CAAC,CAAC,CAAC,yBACV,O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C,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAGlE;AAGD,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAGrF"}
|
|
@@ -3,7 +3,9 @@ import { calculateValue, convertFormulaToBinaryTree, replaceFieldsValue } from "
|
|
|
3
3
|
import { patternFieldText } from "../../Features/constants.js";
|
|
4
4
|
const handleFields = (dataFormState, oldValue, fieldDef, autoValidateFieldText)=>{
|
|
5
5
|
const { fieldName, value } = fieldDef;
|
|
6
|
-
const
|
|
6
|
+
const fieldKey = fieldName;
|
|
7
|
+
const isFieldDirty = fieldKey in dataFormState.fieldsToUpdate;
|
|
8
|
+
const fieldValue = isFieldDirty ? dataFormState.fieldsToUpdate[fieldKey] : oldValue?.[fieldKey] ?? value;
|
|
7
9
|
const showError = void 0 !== dataFormState.validation[fieldName] ? !dataFormState.validation[fieldName] : void 0;
|
|
8
10
|
if (autoValidateFieldText) {
|
|
9
11
|
if (fieldDef.type === FIELD_TYPE.TEXT || fieldDef.type === FIELD_TYPE.TEXT_AREA) fieldDef.pattern = fieldDef.pattern ? fieldDef.pattern : patternFieldText;
|