@fto-consult/expo-ui 6.86.0 → 6.87.0
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
@@ -166,6 +166,7 @@ const SWRDatagridComponent = React.forwardRef((props,ref)=>{
|
|
166
166
|
const canHandleLimit = handleQueryLimit !== false && canHandlePagination ? true : false;
|
167
167
|
const limitRef = React.useRef(!canHandleLimit ?0 : defaultNumber(getSessionData("limit"),500));
|
168
168
|
const isInitializedRef = React.useRef(false);
|
169
|
+
const hasFetchedRef = React.useRef(false);
|
169
170
|
testID = defaultStr(testID,"RNSWRDatagridComponent");
|
170
171
|
const {error, isValidating,isLoading,data:result,refresh} = useSWR(fetchPath,{
|
171
172
|
fetcher : (url,opts)=>{
|
@@ -193,10 +194,14 @@ const SWRDatagridComponent = React.forwardRef((props,ref)=>{
|
|
193
194
|
if(showProgressRef.current ===false){
|
194
195
|
opts.showError = false;
|
195
196
|
}
|
197
|
+
const end = (a)=> {
|
198
|
+
hasFetchedRef.current = true;
|
199
|
+
return a;
|
200
|
+
};
|
196
201
|
if(typeof fetcher =='function'){
|
197
|
-
return fetcher(url,opts);
|
202
|
+
return Promise.resolve(fetcher(url,opts)).then(end);
|
198
203
|
}
|
199
|
-
return apiFetch(url,opts);
|
204
|
+
return apiFetch(url,opts).then(end);
|
200
205
|
},
|
201
206
|
swrOptions : getSWROptions(swrConfig.refreshTimeout)
|
202
207
|
});
|
@@ -290,7 +295,9 @@ const SWRDatagridComponent = React.forwardRef((props,ref)=>{
|
|
290
295
|
});
|
291
296
|
});
|
292
297
|
React.useEffect(()=>{
|
293
|
-
|
298
|
+
if(hasFetchedRef.current){
|
299
|
+
showProgressRef.current = false;
|
300
|
+
}
|
294
301
|
},[showProgressRef.current]);
|
295
302
|
return (
|
296
303
|
<Datagrid
|
@@ -401,10 +408,10 @@ const SWRDatagridComponent = React.forwardRef((props,ref)=>{
|
|
401
408
|
beforeFetchData = {(args)=>{
|
402
409
|
let {fetchOptions:opts,force,renderProgressBar} = args;
|
403
410
|
opts = getFetchOptions({showError:showProgressRef.current,...opts});
|
404
|
-
isInitializedRef.current = true;
|
405
411
|
fetchOptionsRef.current = opts.fetchOptions;
|
406
412
|
opts.fetchOptions.withTotal = true;
|
407
413
|
sortRef.current = opts.fetchOptions.sort;
|
414
|
+
isInitializedRef.current = true;
|
408
415
|
if(force){
|
409
416
|
pageRef.current = firstPage;
|
410
417
|
}
|
package/src/context/hooks.js
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
import Dimensions from "$cplatform/dimensions";
|
4
2
|
import useStableMemo from "$react/useStableMemo";
|
5
3
|
import { useWindowDimensions } from "$cdimensions";
|
6
|
-
import {isObj,isNonNullString} from "$cutils";
|
4
|
+
import {isObj,isNonNullString,extendObj} from "$cutils";
|
7
5
|
import { StyleSheet } from "react-native";
|
8
6
|
import { createContext,useContext as useReactContext } from "react";
|
7
|
+
import _useSWR from "$swr";
|
9
8
|
|
10
9
|
export const ExpoUIContext = createContext(null);
|
11
10
|
|
@@ -17,6 +16,30 @@ export const useContext = useExpoUI;
|
|
17
16
|
|
18
17
|
export const useApp = useContext;
|
19
18
|
|
19
|
+
export const useSWR = (path,options)=>{
|
20
|
+
const {swrConfig} = useExpoUI();
|
21
|
+
const host = `${defaultStr(process.env.API_HOST).trim().rtrim("/")}/${path}`;
|
22
|
+
const isLocalHost = host.includes("127.0.0.1") || host.includes("localhost");
|
23
|
+
return _useSWR(path,{
|
24
|
+
checkOnline : !isLocalHost,
|
25
|
+
...Object.assign({},options),
|
26
|
+
swrOptions : {
|
27
|
+
provider: () => new Map(),
|
28
|
+
...swrConfig,
|
29
|
+
isOnline() {
|
30
|
+
if(isLocalHost) return true;
|
31
|
+
return swrConfig.isOnline();
|
32
|
+
},
|
33
|
+
initReconnect(cb) {
|
34
|
+
if(isLocalHost) return cb();
|
35
|
+
return swrConfig.initReconnect(cb);
|
36
|
+
},
|
37
|
+
...extendObj({},options,options?.swrOptions)
|
38
|
+
}
|
39
|
+
})
|
40
|
+
}
|
41
|
+
|
42
|
+
|
20
43
|
/**** retourne un composant définit dans la props
|
21
44
|
components de la fonction registerApp appelée pour l'initialisation de l'application
|
22
45
|
@param {string} componentName : le nom du composant que l'on veut recupérer
|