@fto-consult/expo-ui 2.12.8 → 2.13.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.
@@ -0,0 +1,96 @@
1
+ import {defaultStr,isNonNullString} from "$utils";
2
+ import React from "$react";
3
+ import CountUp from "$ecomponents/CountUp";
4
+ import Avatar from "$ecomponents/Avatar";
5
+ import { ActivityIndicator } from "react-native-paper";
6
+ import Item from "$ecomponents/Expandable/Item";
7
+ import {navigateToTableDataList} from "$enavigation/utils";
8
+ import theme from "$theme";
9
+ import Label from "$ecomponents/Label";
10
+ import PropTypes from "prop-types";
11
+ import APP from "$capp/instance"
12
+ import cActions from "$cactions";
13
+ import {View} from "react-native";
14
+
15
+ export default function DatabaseStatisticContainer (props){
16
+ const [state,setState] = React.useState({
17
+ isLoading : true,
18
+ count : 0,
19
+ });
20
+ let {table,fetchCount,index,testID,title,icon,onPress} = props;
21
+ title = defaultStr(title)
22
+ table = defaultObj(table);
23
+ const tableName = defaultStr(table.tableName,table.table).toUpperCase();
24
+ fetchCount = typeof table.fetchCount =='function'? table.fetchCount : typeof fetchCount =='function'? fetchCount : undefined;
25
+ if(!fetchCount || !tableName) return null;
26
+ const refreshingRef = React.useRef(null);
27
+ const isMounted = React.useIsMounted();
28
+ const refresh = ()=>{
29
+ if(refreshingRef.current || !isMounted()) return;
30
+ refreshingRef.current = true;
31
+ setTimeout(()=>{
32
+ fetchCount().then((count)=>{
33
+ setState({...state,isLoading:false,count});
34
+ refreshingRef.current = false;
35
+ }).catch((e)=>{
36
+ setState({
37
+ isLoading : false, count : 0,
38
+ });
39
+ refreshingRef.current = false;
40
+ });
41
+ },100);
42
+ }
43
+
44
+ React.useEffect(()=>{
45
+ APP.on(cActions.upsert(tableName),refresh);
46
+ APP.on(cActions.remove(tableName),refresh);
47
+ refresh();
48
+ return ()=>{
49
+ APP.off(cActions.upsert(tableName),refresh);
50
+ APP.off(cActions.remove(tableName),refresh);
51
+ }
52
+ },[]);
53
+ React.useEffect(()=>{
54
+ refresh();
55
+ },[props])
56
+ const {isLoading,count} = state;
57
+ return <Item
58
+ testID = {defaultStr(testID,"RN_DatabaseStatistic_"+table)}
59
+ onPress = {(args)=>{
60
+ if(onPress && onPress(args) === false) return;
61
+ navigateToTableDataList(tableName,{
62
+ tableName
63
+ })
64
+ }}
65
+ left = {(aProps)=>{
66
+ return <Avatar suffix={index} {...aProps} icon= {icon} size={40} label={title}/>
67
+ }}
68
+ //right = {(rP)=><Icon {...rP} name='refresh' onPress={refresh}/>}
69
+ title = {<Label splitText numberOfLines={1} primary style={[{fontSize:15}]}>{title}</Label>}
70
+ titleProps = {{primary : true}}
71
+ description = {isLoading?<View style={[theme.styles.justifyContentFlexStart,theme.styles.alignItemsFlexStart]}>
72
+ <ActivityIndicator color={theme.colors.primary}/>
73
+ </View>:<CountUp
74
+ from={0}
75
+ to={count}
76
+ style = {{fontSize:20,color:theme.colors.secondaryOnSurface}}
77
+ />}
78
+ >
79
+
80
+ </Item>
81
+ }
82
+
83
+ /*** DBSTAT, prend en paramètre le nom de la bd ainsi que celui de la table et affiche en statistic,:
84
+ * Le nombre d'éléments crées en bases ainsi que ceux actifs
85
+ */
86
+ DatabaseStatisticContainer.propTypes = {
87
+ ...Item.propTypes,
88
+ /*** La méthode fetchCount doit retourner une promèsse qui lorsqu'elle est résolue, résoue le nombre d'éléments de la table de données en bd */
89
+ fetchCount : PropTypes.func,//la fonction permettant de counter les éléments de la table data
90
+ table : PropTypes.shape({
91
+ table : PropTypes.string,
92
+ tableName : PropTypes.string,
93
+ fetchCount : PropTypes.func,//la fonction permettant de counter les éléments de la table data
94
+ }).isRequired,
95
+ title : PropTypes.string, //le titre à afficher
96
+ }
@@ -0,0 +1,54 @@
1
+ import Screen from "$screen";
2
+ import Grid,{Cell} from "$components/Grid";
3
+ import {defaultStr,defaultNumber,defaultVal} from "$utils";
4
+ import React from "$react";
5
+ import DatabaseStatistic from "./DatabaseStatistic";
6
+ import theme from "$theme";
7
+ import PropTypes from "prop-types";
8
+
9
+ export const title = 'Statistiques en BD';
10
+ export default function DatabaseStatisticScreen ({withScreen,title:customTitle,contentProps,containerProps,tables,Component,...props}){
11
+ Component = React.isComponent(Component)? Component : Grid;
12
+ containerProps = defaultObj(containerProps);
13
+ const title = containerProps.title = defaultStr(containerProps.title,DatabaseStatisticScreen.title);
14
+ contentProps = defaultObj(contentProps);
15
+ if(Component == Cell){
16
+ containerProps.desktopSize = defaultNumber(containerProps.desktopSize,12);
17
+ containerProps.tabletSize = defaultNumber(containerProps.tabletSize,8);
18
+ containerProps.phoneSize = defaultNumber(containerProps.phoneSize,4);
19
+ }
20
+ let content = [];
21
+ Object.map(tables,(table,index,suffix)=>{
22
+ if(isObj(table)){
23
+ content.push(
24
+ <Cell elevation = {5} withSurface mobileSize={12} desktopSize={3} tabletSize={4} {...contentProps} key = {index} >
25
+ <DatabaseStatistic
26
+ icon = {table.icon}
27
+ key = {index}
28
+ table = {table}
29
+ index = {suffix}
30
+ title = {table.text|| table.title}
31
+ ></DatabaseStatistic>
32
+ </Cell>
33
+ )
34
+ }
35
+ });
36
+ if(!content.length) {
37
+ Auth.showError();
38
+ return null;
39
+ }
40
+ content = <Component {...containerProps} style={[containerProps.style,theme.styles.mr1,theme.styles.ml1]}>
41
+ {content}
42
+ </Component>;
43
+ return withScreen !== false ? <Screen withScrollView title={defaultVal(customTitle,title)} {...props}>{content}</Screen> : content;
44
+ }
45
+
46
+ export const screenName = DatabaseStatisticScreen.screenName = "DatabaseStatistics";
47
+ DatabaseStatisticScreen.title = title;
48
+
49
+ DatabaseStatisticScreen.propTypes = {
50
+ tables : PropTypes.oneOfType([
51
+ PropTypes.arrayOf(PropTypes.object),
52
+ PropTypes.objectOf(PropTypes.object)
53
+ ]).isRequired
54
+ }