@fto-consult/expo-ui 5.7.10 → 5.7.11
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/package.json +1 -1
- package/src/components/Form/FormData/FormData.js +10 -5
- package/src/components/Form/FormData/index.js +3 -1
- package/src/components/Form/FormData/utils.js +3 -2
- package/src/components/Form/utils/index.js +3 -1
- package/src/components/Form/utils/isDocEditing.js +44 -0
- package/src/layouts/Screen/TableData.js +5 -37
- package/src/layouts/Screen/utils.js +2 -1
package/package.json
CHANGED
|
@@ -8,10 +8,10 @@ import Form from "../Form";
|
|
|
8
8
|
import theme,{flattenStyle} from "$theme";
|
|
9
9
|
import PropTypes from "prop-types";
|
|
10
10
|
import {renderActions} from "$ecomponents/Dialog/utils";
|
|
11
|
-
//import {isDocUpdate} from "$database/utils";
|
|
12
11
|
import {handleBeforeSaveCallback} from "./utils";
|
|
12
|
+
import isDbDocEditing,{checkPrimaryKey} from "../utils/isDocEditing";
|
|
13
13
|
import getComponentFromType from "./componentsTypes";
|
|
14
|
-
import
|
|
14
|
+
import keyboardShortcuts from "../utils/keyboardShortcuts";
|
|
15
15
|
import appConfig from "$capp/config";
|
|
16
16
|
|
|
17
17
|
export default class FormDataComponent extends AppComponent{
|
|
@@ -84,11 +84,10 @@ export default class FormDataComponent extends AppComponent{
|
|
|
84
84
|
return "Impossible d'enregister les données à cause l'erreur suivante : "+errorText;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
const isDocEditing = this.isDocEditing(args.data);
|
|
88
87
|
const isUpdated = this.isDocEditing(args.data);
|
|
89
88
|
const currentIndex = this.getCurrentIndex();
|
|
90
89
|
const action = typeof this.clickedAction =='string' ? this.clickedAction.toLowerCase() : '';
|
|
91
|
-
const savedArgs = {...args,
|
|
90
|
+
const savedArgs = {...args,isUpdated,context:this,action,currentIndex,index:currentIndex,isUpdate:isUpdated,isUpdated,props:this.props,context:this};
|
|
92
91
|
if(beforeSaveArgumentsMutator){
|
|
93
92
|
savedArgs = beforeSaveArgumentsMutator(savedArgs);
|
|
94
93
|
if(!isObj(savedArgs)){
|
|
@@ -149,7 +148,9 @@ export default class FormDataComponent extends AppComponent{
|
|
|
149
148
|
} else if(typeof this.props.isDocUpdate =='function'){
|
|
150
149
|
return this.props.isDocUpdate(data,{context:this}) ? true : false;
|
|
151
150
|
}
|
|
152
|
-
return
|
|
151
|
+
return isObj(this.formDataPrimaryKeyFields) && Object.size(this.formDataPrimaryKeyFields,true) ? isDbDocEditing(data,this.formDataPrimaryKeyFields,({index:field,data})=>{
|
|
152
|
+
return checkPrimaryKey(data,field);
|
|
153
|
+
}) : false;
|
|
153
154
|
}
|
|
154
155
|
canBindResizeEvents(){
|
|
155
156
|
return false;
|
|
@@ -180,6 +181,7 @@ export default class FormDataComponent extends AppComponent{
|
|
|
180
181
|
formProps = defaultObj(formProps);
|
|
181
182
|
const fieldProps = defaultObj(formProps.fieldProps,this.props.fieldProps);
|
|
182
183
|
formProps.style = flattenStyle(formProps.style);
|
|
184
|
+
this.formDataPrimaryKeyFields = {};
|
|
183
185
|
const content = [];
|
|
184
186
|
const fields = defaultObj(formProps.fields,this.props.fields);
|
|
185
187
|
const data = isObj(formProps.data) ? formProps.data : typeof this.props.data =='object' && this.props.data ? this.props.data : {};
|
|
@@ -198,6 +200,9 @@ export default class FormDataComponent extends AppComponent{
|
|
|
198
200
|
rest = Object.assign({},rest);
|
|
199
201
|
delete rest.import;
|
|
200
202
|
delete rest.export;
|
|
203
|
+
if(primaryKey === true && name && !field.filter){
|
|
204
|
+
this.formDataPrimaryKeyFields[name] = field;
|
|
205
|
+
}
|
|
201
206
|
if(form === false || ignore || (isNonNullString(perm) && !Auth.isAllowedFromStr(perm))){
|
|
202
207
|
return null;
|
|
203
208
|
}
|
|
@@ -2,7 +2,7 @@ import {isNonNullString,isObj,defaultObj,isPromise,isFunction,defaultStr,isObjOr
|
|
|
2
2
|
import notify from "$notify";
|
|
3
3
|
import { getFormData } from "../utils/FormsManager";
|
|
4
4
|
import {isMobileBrowser,isMobileNative} from "$cplatform";
|
|
5
|
-
import
|
|
5
|
+
import KeyboardShorts from "../utils/keyboardShortcuts";
|
|
6
6
|
|
|
7
7
|
export const keyboardShortcuts = {};
|
|
8
8
|
Object.map(KeyboardShorts,(st,i)=>{
|
|
@@ -100,4 +100,5 @@ export const handleBeforeSaveCallback = (beforeSaveCallback,successCb,arg)=>{
|
|
|
100
100
|
}
|
|
101
101
|
successCb(arg);
|
|
102
102
|
return bF;
|
|
103
|
-
}
|
|
103
|
+
}
|
|
104
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {isObj,defaultStr} from "$cutils";
|
|
2
|
+
export const checkPrimaryKey = (data,f)=>{
|
|
3
|
+
return !(!(f in data) || (data[f] == null) || (!data[f] && typeof data !=='number'));
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/*** vérifie si le document passé en paramètre est éditable
|
|
7
|
+
* @param {object} data la données à vérifier
|
|
8
|
+
* @param {object| array} les champs sur lesquels se baser pour vérifier si la donénes est une mise à jour
|
|
9
|
+
* @param {func} checkPrimaryKey la foncition permettant de vérifier s'il s'agit d'une clé primaire pour la données courante
|
|
10
|
+
*/
|
|
11
|
+
const isDocEditing = (data,fields,checkPrimaryKey)=>{
|
|
12
|
+
if(!isObj(data) || !isObjOrArray(fields)) return false;
|
|
13
|
+
let hasPrimaryFields = false;
|
|
14
|
+
let hasValidated = true;
|
|
15
|
+
for(let i in fields){
|
|
16
|
+
const field = fields[i];
|
|
17
|
+
if(typeof checkPrimaryKey =='function') {
|
|
18
|
+
hasPrimaryFields = true;
|
|
19
|
+
if(checkPrimaryKey({field,i,index:i,data}) === false){
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if(!isObj(field)) continue;
|
|
25
|
+
hasPrimaryFields = true;
|
|
26
|
+
const f = defaultStr(field.field,i);
|
|
27
|
+
if(field.primaryKey === true){
|
|
28
|
+
if(!checkPrimaryKey(data,f)){
|
|
29
|
+
if(hasPrimaryFields){
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
hasValidated = false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if(hasPrimaryFields){
|
|
37
|
+
return hasValidated;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default isDocEditing;
|
|
43
|
+
|
|
44
|
+
export const isDocUpdate = isDocEditing;
|
|
@@ -21,6 +21,7 @@ import theme from "$theme";
|
|
|
21
21
|
import cActions from "$cactions";
|
|
22
22
|
import APP from "$capp/instance";
|
|
23
23
|
import { generatedColumnsProperties } from "./utils";
|
|
24
|
+
import {isDocEditing,checkPrimaryKey} from "$ecomponents/Form";
|
|
24
25
|
import i18n from "$i18n";
|
|
25
26
|
import fetch from "$capi/fetch";
|
|
26
27
|
|
|
@@ -31,42 +32,6 @@ const DEFAULT_TABS_KEYS = "main-tabs";
|
|
|
31
32
|
|
|
32
33
|
const TIMEOUT = 50;
|
|
33
34
|
|
|
34
|
-
const checkPrimary = (data,f)=>{
|
|
35
|
-
return !(!(f in data) || (data[f] == null) || (!data[f] && typeof data !=='number'));
|
|
36
|
-
}
|
|
37
|
-
/*** vérifie si le document passé en paramètre est éditable
|
|
38
|
-
* @param {object} data la données à vérifier
|
|
39
|
-
* @param {object| array} les champs sur lesquels se baser pour vérifier si la donénes est une mise à jour
|
|
40
|
-
* @param {func} checkPrimaryKey la foncition permettant de vérifier s'il s'agit d'une clé primaire pour la données courante
|
|
41
|
-
*/
|
|
42
|
-
export const isDocEditing = (data,fields,checkPrimaryKey)=>{
|
|
43
|
-
if(!isObj(data) || !isObjOrArray(fields)) return false;
|
|
44
|
-
|
|
45
|
-
let hasPrimaryFields = false;
|
|
46
|
-
let hasValidated = true;
|
|
47
|
-
for(let i in fields){
|
|
48
|
-
const field = fields[i];
|
|
49
|
-
if(typeof checkPrimaryKey =='function') {
|
|
50
|
-
hasPrimaryFields = true;
|
|
51
|
-
if(checkPrimaryKey({field,i,index:i,data}) === false){
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if(!isObj(field)) continue;
|
|
57
|
-
hasPrimaryFields = true;
|
|
58
|
-
const f = defaultStr(field.field,i);
|
|
59
|
-
if(field.primaryKey === true){
|
|
60
|
-
if(!checkPrimary(data,f)){
|
|
61
|
-
hasValidated = false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if(hasPrimaryFields){
|
|
66
|
-
return hasValidated;
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
35
|
|
|
71
36
|
export default class TableDataScreenComponent extends FormDataScreen{
|
|
72
37
|
constructor(props){
|
|
@@ -280,6 +245,9 @@ export default class TableDataScreenComponent extends FormDataScreen{
|
|
|
280
245
|
currentField.disabled = true;
|
|
281
246
|
}
|
|
282
247
|
}
|
|
248
|
+
if(field.primaryKey ===true){
|
|
249
|
+
this.primaryKeyFields[columnField] = true;
|
|
250
|
+
}
|
|
283
251
|
const isPrimary = this.primaryKeyFields[columnField] && true || false;
|
|
284
252
|
const f = prepareCb(cArgs);
|
|
285
253
|
if(f === false) {
|
|
@@ -536,7 +504,7 @@ export default class TableDataScreenComponent extends FormDataScreen{
|
|
|
536
504
|
const isDocEditingCb = typeof this.props.isDocEditing =='function'? this.props.isDocEditing : typeof this.props.isDocUpdate =='function'? this.props.isDocUpdate : undefined;
|
|
537
505
|
if(!isDocEditingCb){
|
|
538
506
|
if(isDocEditing(data,this.primaryKeyFields,({index:field,data})=>{
|
|
539
|
-
return
|
|
507
|
+
return checkPrimaryKey(data,field);
|
|
540
508
|
})) return true;
|
|
541
509
|
} else {
|
|
542
510
|
return isDocEditingCb(data,{context:this});
|