@fto-consult/expo-ui 2.12.6 → 2.12.7

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": "2.12.6",
3
+ "version": "2.12.7",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -58,13 +58,9 @@
58
58
  },
59
59
  "homepage": "https://github.com/borispipo/expo-ui#readme",
60
60
  "dependencies": {
61
- "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
62
- "@babel/preset-react": "^7.18.6",
63
61
  "@emotion/native": "^11.10.0",
64
62
  "@expo/html-elements": "^0.2.0",
65
- "@expo/metro-config": "^0.4.0",
66
63
  "@expo/vector-icons": "^13.0.0",
67
- "@expo/webpack-config": "^0.17.2",
68
64
  "@fto-consult/common": "^1.20.2",
69
65
  "@gorhom/portal": "^1.0.14",
70
66
  "@react-native-async-storage/async-storage": "~1.17.3",
@@ -73,9 +69,6 @@
73
69
  "@react-navigation/native": "^6.0.13",
74
70
  "@react-navigation/native-stack": "^6.9.1",
75
71
  "@shopify/flash-list": "1.3.1",
76
- "babel-plugin-inline-dotenv": "^1.7.0",
77
- "babel-plugin-module-resolver": "^4.1.0",
78
- "babel-plugin-transform-inline-environment-variables": "^0.4.4",
79
72
  "expo": "^47.0.8",
80
73
  "expo-camera": "~13.1.0",
81
74
  "expo-clipboard": "~4.0.1",
@@ -110,5 +103,14 @@
110
103
  "react-native-webview": "11.23.1",
111
104
  "sharp-cli": "^2.1.0",
112
105
  "tippy.js": "^6.3.7"
106
+ },
107
+ "devDependencies": {
108
+ "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
109
+ "@babel/preset-react": "^7.18.6",
110
+ "@expo/metro-config": "^0.5.1",
111
+ "@expo/webpack-config": "^0.17.3",
112
+ "babel-plugin-inline-dotenv": "^1.7.0",
113
+ "babel-plugin-module-resolver": "^4.1.0",
114
+ "babel-plugin-transform-inline-environment-variables": "^0.4.4"
113
115
  }
114
116
  }
package/readMe.md ADDED
@@ -0,0 +1,8 @@
1
+ <!--
2
+ Copyright 2022 @fto-consult/Boris Fouomene. All rights reserved.
3
+ Use of this source code is governed by a BSD-style
4
+ license that can be found in the LICENSE file.
5
+ -->
6
+
7
+ ## Installation des dépendences, packages de dévéloppement
8
+ npm i --D @babel/plugin-proposal-export-namespace-from @babel/preset-react babel-plugin-inline-dotenv babel-plugin-module-resolver babel-plugin-transform-inline-environment-variables @expo/metro-config @expo/webpack-config
@@ -839,6 +839,9 @@ export default class CommonDatagridComponent extends AppComponent {
839
839
  this.setSessionData({showFooters:true})
840
840
  })
841
841
  }
842
+ setState(a,b){
843
+ super.setState(a,b);
844
+ }
842
845
  hideFooter (){
843
846
  if(!this._isMounted()) {
844
847
  this.isUpdating = false;
@@ -1513,7 +1516,7 @@ export default class CommonDatagridComponent extends AppComponent {
1513
1516
  if( typeof this.props.isLoading=='boolean' && nextProps.isLoading !== this.props.isLoading && typeof nextProps.isLoading =='boolean'){
1514
1517
  this.setIsLoading(nextProps.isLoading)
1515
1518
  }
1516
- return;
1519
+ return false;
1517
1520
  }
1518
1521
  this.prepareData({...nextProps,force:true},(state)=>{
1519
1522
  this.setState(state)
@@ -76,9 +76,6 @@ export default class CommonTableDatagrid extends CommonDatagrid{
76
76
  force = cb;
77
77
  cb = undefined;
78
78
  }
79
- if(force !== true && isArray(this.INITIAL_STATE.data)) {
80
- return this.resolveFetchedDataPromise({cb,data:this.INITIAL_STATE.data}).then(resolve).catch(reject)
81
- }
82
79
  const fetchFilters = this.getFilters();
83
80
  fetchOptions = isObj(fetchOptions)?Object.clone(fetchOptions):{};
84
81
  fetchOptions.selector = defaultObj(fetchOptions.selector);
@@ -99,6 +96,9 @@ export default class CommonTableDatagrid extends CommonDatagrid{
99
96
  this.isFetchingData = false;
100
97
  return resolve(this.state.data);
101
98
  }
99
+ if(force !== true && isArray(this.INITIAL_STATE.data)) {
100
+ return this.resolveFetchedDataPromise({cb,data:this.INITIAL_STATE.data}).then(resolve).catch(reject)
101
+ }
102
102
  let fetchData = this.INITIAL_STATE.fetchData;
103
103
  if(isFunction(this.props.fetchData)){
104
104
  /**** l'on peut définir la props fetchData, qui est la fonction appelée pour la recherche des données */
@@ -1,9 +1,12 @@
1
1
  // Copyright 2022 @fto-consult/Boris Fouomene. All rights reserved.
2
2
  // Use of this source code is governed by a BSD-style
3
3
  // license that can be found in the LICENSE file.
4
-
4
+ /****
5
+ * @see : https://swr.vercel.app/examples/infinite-loading
6
+ * @see :
7
+ */
5
8
  import Datagrid from "./IndexComponent";
6
- import {defaultStr,defaultObj,defaultVal,extendObj} from "$utils";
9
+ import {defaultStr,defaultObj,defaultVal,isObjOrArray,isObj,extendObj} from "$utils";
7
10
  import React from "$react";
8
11
  import Auth from "$cauth";
9
12
  import DateLib from "$lib/date";
@@ -28,10 +31,14 @@ export const swrOptions = {
28
31
  errorRetryCount : 5,
29
32
  }
30
33
 
34
+ /****la fonction fetcher doit toujours retourner :
35
+ * 1. la liste des éléments fetchés dans la props data
36
+ * 2. le nombre total d'éléments de la liste obtenue en escluant les clause limit et offset correspondant à la même requête
37
+ */
31
38
  const SWRDatagridComponent = React.forwardRef((props,ref)=>{
32
39
  let {
33
40
  table,
34
- data,
41
+ data:customData,
35
42
  saveButton,
36
43
  title,
37
44
  fab,
@@ -82,9 +89,11 @@ const SWRDatagridComponent = React.forwardRef((props,ref)=>{
82
89
  title
83
90
  },rest.exportTableProps.pdf);
84
91
  const fetchOptionsRef = React.useRef({});
92
+ const refreshCBRef = React.useRef(null);
85
93
  fetchPath = defaultStr(fetchPath,table.queryPath,tableName.toLowerCase()).trim();
86
94
  const innerRef = React.useRef(null);
87
- let {data:fetchedData, error, isValidating,size, setSize,isLoading,refresh} = useSWR(fetchPath,{
95
+ const showProgressRef = React.useRef(true);
96
+ const {data:fetchedData, error, isValidating,size, setSize,isLoading,refresh} = useSWR(fetchPath,{
88
97
  fetchOptionsMutator : (opts)=>{
89
98
  const {url} = opts;
90
99
  const fo = fetchOptionsRef.current;
@@ -99,32 +108,59 @@ const SWRDatagridComponent = React.forwardRef((props,ref)=>{
99
108
  ...defaultObj(appConfig.swr),
100
109
  },
101
110
  });
111
+ const fetchedRef = React.useRef(fetchedData);
112
+ const hasResult = !isLoading && !isValidating && isObj(fetchedData) && 'data' in fetchedData;
113
+ if(hasResult){
114
+ fetchedRef.current = fetchedData;
115
+ }
116
+ const data = fetchedRef.current?.data;
117
+ const total = fetchedRef.current?.total;
102
118
  React.useEffect(()=>{
103
119
  innerRef.current && innerRef.current.setIsLoading && innerRef.current.setIsLoading(isLoading);
104
120
  },[isLoading])
121
+ React.useEffect(()=>{
122
+ const cb = refreshCBRef.current;
123
+ refreshCBRef.current = null;
124
+ if(!isValidating && !isLoading && typeof cb =='function'){
125
+ cb();
126
+ }
127
+ },[isValidating,isLoading])
128
+ const doRefresh = (showProgress)=>{
129
+ showProgressRef.current = showProgress ? typeof showProgress ==='boolean' : false;
130
+ refreshCBRef.current = ()=>{
131
+ showProgressRef.current = true;
132
+ };
133
+ refresh();
134
+ }
105
135
  React.useEffect(()=>{
106
136
  const upsert = cAction.upsert(tableName);
107
137
  const remove = cAction.remove(tableName);
108
- APP.on(remove,refresh);
109
- APP.on(upsert,refresh);
138
+ const onUpsert = ()=>{
139
+ doRefresh(false);
140
+ }
141
+ APP.on(remove,onUpsert);
142
+ APP.on(upsert,onUpsert);
110
143
  return ()=>{
111
- APP.off(upsert,refresh);
112
- APP.off(remove,refresh);
144
+ APP.off(upsert,onUpsert);
145
+ APP.off(remove,onUpsert);
113
146
  }
114
- },[])
147
+ },[]);
115
148
  return (
116
149
  <Datagrid
117
150
  {...rest}
118
151
  {...defaultObj(table.datagrid)}
119
- isLoading = {isLoading|| isValidating}
152
+ isLoading = {isLoading|| isValidating && !error && showProgressRef.current && true || false}
120
153
  beforeFetchData = {({fetchOptions:opts})=>{
121
154
  opts.fields = fetchFields;
122
- opts = getFetchOptions({fetcher,...opts});
155
+ opts = getFetchOptions({fetcher,showError:showProgressRef.current,...opts});
156
+ opts.queryParams.withTotal = true;
123
157
  fetchOptionsRef.current = opts;
124
- refresh();
158
+ doRefresh(true);
159
+ return false;
125
160
  }}
161
+ isTableData
126
162
  fetchData = {undefined}
127
- data = {error ? data : defaultObj(fetchedData).data}
163
+ data = {data}
128
164
  canMakePhoneCall={canMakePhoneCall}
129
165
  key={tableName}
130
166
  sessionName={defaultStr(sessionName,'list-data')}
@@ -20,22 +20,42 @@ export const defaultDesktopSize = 4;
20
20
 
21
21
  const isV = x=> typeof x =='number' && x && x <= totalSize ? true : false;
22
22
  export const getSizeStyle = (props)=>{
23
- let {size,smallPhoneSize,paddingMultiplicator,phoneSize,marginMultiplicator,mobileSize,tabletSize,gutter,desktopSize} = defaultObj(props);
23
+ let {size,smallPhoneSize,paddingMultiplicator,phoneSize,marginMultiplicator,mobileSize,tabletSize,gutter,desktopSize
24
+ ,smallPhoneGutter,phoneGutter,mobileGutter,tabletGutter,desktopGutter,
25
+ } = defaultObj(props);
24
26
  gutter = gutter === false ? 0 : typeof gutter =='number'? gutter : undefined;
25
- if(Dimensions.isSmallPhoneMedia()){
26
- size = isV(smallPhoneSize) ? smallPhoneSize : size || defaultMobileSize;
27
+ let hasFound = false;
28
+ const isValidSmallSize = isV(smallPhoneSize),
29
+ isValidPhoneSize = isV(phoneSize),
30
+ isValidMobileSize = isV(mobileSize),
31
+ isValidTabletSize = isV(tabletSize),
32
+ isValidDesktopSize = isV(desktopSize);
33
+ if(Dimensions.isSmallPhoneMedia() && isValidSmallSize){
34
+ size = smallPhoneSize;
35
+ if(smallPhoneGutter !== undefined){gutter = smallPhoneGutter;}
27
36
  gutter = gutter !== undefined ? gutter : medias.sp;
28
- } else if(Dimensions.isPhoneMedia()){
29
- size = isV(phoneSize) ? phoneSize : size || defaultMobileSize;
37
+ hasFound = true;
38
+ }
39
+ if(!hasFound && Dimensions.isPhoneMedia() && isValidPhoneSize){
40
+ size = phoneSize;
41
+ if(phoneGutter !== undefined){gutter = phoneGutter;}
30
42
  gutter = gutter !== undefined ? gutter : medias.mp;
31
- } else if(Dimensions.isMobileMedia()){
32
- size = isV(mobileSize) ? mobileSize : size || defaultMobileSize;
43
+ hasFound = true;
44
+ }
45
+ if(!hasFound && Dimensions.isMobileMedia()){
46
+ size = isValidMobileSize? mobileSize : size || defaultMobileSize;
47
+ if(mobileGutter !== undefined) gutter = mobileGutter;
33
48
  gutter = gutter !== undefined ? gutter : medias.xs;
34
- } else if(Dimensions.isTabletMedia()){
35
- size = isV(tabletSize) ? tabletSize : size || defaultTabletSize;
49
+ hasFound = true;
50
+ }
51
+ if(!hasFound && Dimensions.isTabletMedia()){
52
+ size = isValidTabletSize ? tabletSize : size || defaultTabletSize;
53
+ if(tabletGutter !== undefined) gutter = tabletGutter;
36
54
  gutter = gutter !== undefined ? gutter : medias.sm;
37
- } else {
38
- size = isV(desktopSize)? desktopSize : size || defaultDesktopSize;
55
+ hasFound = true;
56
+ } else if(!hasFound){
57
+ size = isValidDesktopSize ? desktopSize : size || defaultDesktopSize;
58
+ if(desktopGutter !== undefined) gutter = desktopGutter;
39
59
  gutter = gutter !== undefined ? gutter : medias.md;
40
60
  }
41
61
  if(!isV(size)){
@@ -1,7 +1,7 @@
1
1
  import {defaultStr,isNumber,isPromise,defaultVal,extendObj,defaultObj,uniqid,isObj,isObjOrArray} from "$utils";
2
2
  import {FormData} from "$ecomponents/Form";
3
3
  import FormDataScreen from "./FormData";
4
- import ScreenContainer from "$screen";
4
+ import ScreenContainer from "./Screen";
5
5
  import React from "$react";
6
6
  import { StyleSheet} from "react-native";
7
7
  import ScrollView from "$ecomponents/ScrollView";
@@ -8,5 +8,5 @@ Screen.FormData = FormData;
8
8
  Screen.List = List;
9
9
 
10
10
  export default Screen;
11
-
11
+ export {default as TableData} from "./TableData";
12
12
  export {FormData,List,ScreenWithoutAuthContainer};