@fto-consult/expo-ui 5.7.9 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "5.7.9",
3
+ "version": "5.7.11",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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 { keyboardShortcuts } from "../utils";
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,isDocEditing,context:this,action,currentIndex,index:currentIndex,isUpdate:isUpdated,isUpdated,props:this.props,context:this};
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 false;
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
  }
@@ -12,4 +12,6 @@ export {FormData};
12
12
 
13
13
  export default FormData;
14
14
 
15
- FormData.DialogProvider = Provider;
15
+ FormData.DialogProvider = Provider;
16
+
17
+ export * from "./utils";
@@ -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 { keyboardShortcuts as KeyboardShorts } from "../utils";
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
+
@@ -5,4 +5,6 @@ export {Forms};
5
5
 
6
6
  export {default as keyboardEvents} from "./keyboardEvents";
7
7
 
8
- export {default as keyboardShortcuts} from "./keyboardShortcuts";
8
+ export {default as isDocEditing} from "./isDocEditing";
9
+
10
+ export * from "./isDocEditing";
@@ -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;
@@ -66,10 +66,10 @@ export default function PhoneInputComponent(props){
66
66
  contentContainerProps.style = [styles.inputContainer,contentContainerProps.style];
67
67
  const ref = React.useRef(null);
68
68
  const [state,setState] = React.useState({
69
- visible : false,
70
69
  ...prepareState({defaultValue,country})
71
- })
72
- const prevVisible = React.usePrevious(state.visible);
70
+ });
71
+ const [visible,setVisible] = React.useState(false);
72
+ const prevVisible = React.usePrevious(visible);
73
73
  label = defaultVal(label,text);
74
74
  React.useEffect(()=>{
75
75
  React.setRef(ref,ref.current,setRef);
@@ -82,8 +82,8 @@ export default function PhoneInputComponent(props){
82
82
  }
83
83
  },[defaultValue,country])
84
84
  const onPressFlag = (e)=>{
85
- if(!state.visible){
86
- setState({...state,visible:true})
85
+ if(!visible){
86
+ setVisible(true);
87
87
  }
88
88
  }
89
89
  inputProps = defaultObj(inputProps);
@@ -131,12 +131,17 @@ export default function PhoneInputComponent(props){
131
131
  return <SelectCountry
132
132
  label = {label}
133
133
  controlled = {true}
134
- visible = {state.visible}
134
+ visible = {visible}
135
135
  defaultValue = {state.country}
136
136
  testID = {testID+"_SelectCountry"}
137
137
  onDismiss = {({value},force) =>{
138
- if(force !== true && value === state.country && state.visible == prevVisible) return;
139
- setState({...state,...prepareState({country:value,defaultValue:state.country==value?state.defaultValue:""}),visible:false})
138
+ if(force !== true && value === state.country && visible == prevVisible) return;
139
+ if(visible){
140
+ setVisible(false);
141
+ }
142
+ }}
143
+ onChange = {({value})=>{
144
+ setState({...state,...prepareState({country:value,defaultValue:state.country==value?state.defaultValue:""})});
140
145
  }}
141
146
  anchor = {
142
147
  <>
@@ -16,13 +16,15 @@ import { matchOperators,getSearchTimeout,canAutoFocusSearchField} from "$ecompon
16
16
  import Dialog from "$ecomponents/Dialog";
17
17
 
18
18
  const SimpleSelect = React.forwardRef((props,ref)=>{
19
- let {style : customStyle,onMount,mode,showSearch,anchorContainerProps,renderText,contentContainerProps,withCheckedIcon,testID,selectionColor,dialogProps,onShow,anchor,onUnmont,controlled,onDismiss,visible:controlledVisible,selectedColor,inputProps,itemProps,itemContainerProps,label,listProps,editable,readOnly,text,filter,renderItem,itemValue,getItemValue,defaultValue,items:menuItems,onPress,onChange,disabled,...rest} = props;
19
+ let {style : customStyle,onMount,mode,showSearch,anchorContainerProps,renderText,contentContainerProps,withCheckedIcon,testID,selectionColor,dialogProps,onShow,anchor,onUnmont,controlled:cr,onDismiss,visible:controlledVisible,selectedColor,inputProps,itemProps,itemContainerProps,label,listProps,editable,readOnly,text,filter,renderItem,itemValue,getItemValue,defaultValue,items:menuItems,onPress,onChange,disabled,...rest} = props;
20
20
  const flattenStyle = StyleSheet.flatten(customStyle) || {};
21
+ const controlledRef = React.useRef(typeof controlledVisible ==='boolean'? true : false);
22
+ const controlled = controlledRef.current;
21
23
  const [layout,setLayout] = React.useState({
22
24
  height: 0,
23
25
  width: 0,
24
26
  });
25
- const [visible,setVisible] = React.useState(controlled?controlledVisible:false)
27
+ const [visible,setVisible] = controlled ? [controlledVisible] : React.useState(controlled?controlledVisible:false);
26
28
  const [value,setValue] = React.useState(defaultValue !== undefined? defaultValue:undefined);
27
29
  contentContainerProps = defaultObj(contentContainerProps);
28
30
  const prevLayout = React.usePrevious(layout);
@@ -94,13 +96,12 @@ const SimpleSelect = React.forwardRef((props,ref)=>{
94
96
  if(update !== true && compare(value,node.value)) return;
95
97
  selectedRef.current = node;
96
98
  if(update === true){
99
+ setValue(node.value);
97
100
  if(controlled && onDismiss){
98
101
  if(onDismiss({visible,value,items,defaultValue},defaultObj(selectedRef.current)) === false) return;
99
102
  }
100
- setValue(node.value);
101
- const vv = controlled?undefined:false;
102
- if(typeof vv =='boolean' && vv !==visible){
103
- setVisible(vv);
103
+ if(!controlled && visible){
104
+ setVisible(false);
104
105
  }
105
106
  }
106
107
  }
@@ -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 checkPrimary(data,field);
507
+ return checkPrimaryKey(data,field);
540
508
  })) return true;
541
509
  } else {
542
510
  return isDocEditingCb(data,{context:this});
@@ -276,4 +276,5 @@ export const getScreenName = (screenName)=>{
276
276
  screenName = defaultStr(screenName.table,screenName.tableName);
277
277
  }
278
278
  return getTableDataRouteName(screenName);
279
- }
279
+ }
280
+