@fto-consult/expo-ui 2.35.2 → 2.36.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "2.35.2",
3
+ "version": "2.36.0",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -61,7 +61,7 @@
61
61
  "@emotion/native": "^11.10.0",
62
62
  "@expo/html-elements": "^0.2.0",
63
63
  "@expo/vector-icons": "^13.0.0",
64
- "@fto-consult/common": "^2.1.2",
64
+ "@fto-consult/common": "^2.1.3",
65
65
  "@gorhom/portal": "^1.0.14",
66
66
  "@react-native-async-storage/async-storage": "~1.17.3",
67
67
  "@react-native-community/datetimepicker": "6.5.2",
@@ -86,7 +86,12 @@ const DatagridFactory = (Factory)=>{
86
86
  }
87
87
  getItemCallArgs({item,index}){
88
88
  const rowIndexCount = index+1;
89
- return {...this.getActionsArgs(),row:item,items:this.state.data,item,rowData:item,index,rowIndex:index,rowCounterIndex:rowIndexCount,rowIndexCount};
89
+ const formatValue = this.formatValue.bind(this);
90
+ return {...this.getActionsArgs(),valueFormatter:formatValue,formatValue,abreviateValues:this.state.abreviateValues,row:item,items:this.state.data,item,rowData:item,index,rowIndex:index,rowCounterIndex:rowIndexCount,rowIndexCount};
91
+ }
92
+ toggleAbreviateValues(){
93
+ this.renderingItemsProps = {};
94
+ return super.toggleAbreviateValues(true);
90
95
  }
91
96
  getRenderingItemProps ({item,rowKey,numColumns,index}){
92
97
  const rKey = rowKey;
@@ -575,6 +580,7 @@ const DatagridFactory = (Factory)=>{
575
580
  key = {field}
576
581
  testID={testID+"_FooterItem_"+field}
577
582
  {...footer}
583
+ abreviate = {this.state.abreviateValues}
578
584
  aggregatorFunction = {this.getActiveAggregatorFunction().code}
579
585
  aggregatorFunctions = {this.aggregatorFunctions}
580
586
  anchorProps = {{style:[theme.styles.ph1,theme.styles.mh05]}}
@@ -43,6 +43,8 @@ import notify from "$cnotify";
43
43
  import FileSystem from "$file-system";
44
44
  import sprintf from "$cutils/sprintf";
45
45
 
46
+ export const TIMEOUT = 200;
47
+
46
48
  export const donutChart = {
47
49
  isChart : true,
48
50
  code : 'donutChart',
@@ -266,6 +268,7 @@ export default class CommonDatagridComponent extends AppComponent {
266
268
  chartRef : {value : {current:null}},
267
269
  chartSeriesNamesColumnsMapping : {value : {}},//le mappage entre les index des series et les colonnes coorespondantes
268
270
  })
271
+ this.state.abreviateValues = "abreviateValues" in this.props? !!this.props.abreviateValues : !!this.getSessionData("abreviateValues");
269
272
  const sessionAggregator = defaultStr(this.getSessionData("aggregatorFunction")).trim();
270
273
  const aggregatorProps = defaultStr(this.props.aggregatorFunction).trim();
271
274
  let aggregatorFunction = null;
@@ -1087,7 +1090,7 @@ export default class CommonDatagridComponent extends AppComponent {
1087
1090
  this.isUpdating = false;
1088
1091
  this.setSessionData({showFilters});
1089
1092
  })
1090
- },100);
1093
+ },TIMEOUT);
1091
1094
  }
1092
1095
  showFilters(){
1093
1096
  return this.toggleFilters(true);
@@ -1120,7 +1123,7 @@ export default class CommonDatagridComponent extends AppComponent {
1120
1123
  this.isUpdating = false;
1121
1124
  this.setSessionData({showFooters:showOrHide})
1122
1125
  })
1123
- },0)
1126
+ },TIMEOUT)
1124
1127
  }
1125
1128
  showFooters(){
1126
1129
  return this.toggleFooters(true);
@@ -1134,11 +1137,16 @@ export default class CommonDatagridComponent extends AppComponent {
1134
1137
 
1135
1138
 
1136
1139
  toggleFixedTableState(){
1137
- const fixedTable = !this.state.fixedTable;
1138
- this.setState({fixedTable},()=>{
1139
- this.updateLayout();
1140
- this.setSessionData("fixedTable",fixedTable);
1141
- })
1140
+ setTimeout(()=>{
1141
+ this.setIsLoading(true,()=>{
1142
+ const fixedTable = !this.state.fixedTable;
1143
+ this.setState({fixedTable},()=>{
1144
+ this.updateLayout();
1145
+ this.setSessionData("fixedTable",fixedTable);
1146
+ this.setIsLoading(false,false);
1147
+ })
1148
+ },true)
1149
+ },TIMEOUT)
1142
1150
  }
1143
1151
  getSessionNameKey (){
1144
1152
  return defaultStr(this.props.table,this.props.tableName,this.props.sessionName);
@@ -1146,32 +1154,39 @@ export default class CommonDatagridComponent extends AppComponent {
1146
1154
  /*** affiche ou masque une colonne filtrée */
1147
1155
  toggleFilterColumnVisibility(field){
1148
1156
  if(!isNonNullString(field)) return;
1149
- let filteredColumns = {...this.state.filteredColumns};
1150
- filteredColumns[field] = defaultBool(filteredColumns[field],false) == false ? true : false;
1151
- this.prepareColumns({filteredColumns});
1152
- this.setState({filteredColumns},()=>{
1153
- this.setSessionData("filteredColumns"+this.getSessionNameKey(),filteredColumns);
1154
- if(!filteredColumns[field]){
1155
- this.filters[field] = defaultObj(this.filters[field]);
1156
- this.filters[field].value = this.filters[field].defaultValue = undefined;
1157
- this.doFilter({value:undefined,field})
1158
- }
1159
- });
1157
+ setTimeout(()=>{
1158
+ this.setIsLoading(true,()=>{
1159
+ let filteredColumns = {...this.state.filteredColumns};
1160
+ filteredColumns[field] = defaultBool(filteredColumns[field],false) == false ? true : false;
1161
+ this.prepareColumns({filteredColumns});
1162
+ this.setState({filteredColumns},()=>{
1163
+ this.setSessionData("filteredColumns"+this.getSessionNameKey(),filteredColumns);
1164
+ if(!filteredColumns[field]){
1165
+ this.filters[field] = defaultObj(this.filters[field]);
1166
+ this.filters[field].value = this.filters[field].defaultValue = undefined;
1167
+ this.doFilter({value:undefined,field})
1168
+ }
1169
+ this.setIsLoading(false,false);
1170
+ });
1171
+ },true)
1172
+ },TIMEOUT)
1160
1173
  }
1161
1174
  /*** affiche ou masque une colonne */
1162
1175
  toggleColumnVisibility(field,removeFocus){
1163
1176
  if(!isNonNullString(field)) return;
1164
- let columns = {...this.state.columns};
1165
- columns[field].visible = !columns[field].visible;
1166
- const footers = this.getFootersFields();
1167
- if(isObj(footers[field])){
1168
- footers[field].visible = columns[field].visible;
1169
- }
1170
- this.setIsLoading(true,()=>{
1171
- this.prepareColumns({columns});
1172
- this.setState({columns});
1173
- this.setIsLoading(false,false);
1174
- })
1177
+ setTimeout(()=>{
1178
+ let columns = {...this.state.columns};
1179
+ columns[field].visible = !columns[field].visible;
1180
+ const footers = this.getFootersFields();
1181
+ if(isObj(footers[field])){
1182
+ footers[field].visible = columns[field].visible;
1183
+ }
1184
+ this.setIsLoading(true,()=>{
1185
+ this.prepareColumns({columns});
1186
+ this.setState({columns});
1187
+ this.setIsLoading(false,false);
1188
+ })
1189
+ },TIMEOUT)
1175
1190
  }
1176
1191
  /****le nombre maximum de courbes supportées */
1177
1192
  getMaxSeriesSize(){
@@ -1263,15 +1278,17 @@ export default class CommonDatagridComponent extends AppComponent {
1263
1278
  } else {
1264
1279
  sectionListColumns[columnName] = {field:columnName};
1265
1280
  }
1266
- const {sectionListColumns:pSListColumns} = this.prepareColumns({sectionListColumns});
1267
- this.setIsLoading(true,()=>{
1268
- this.prepareData({data:this.INITIAL_STATE.data,sectionListColumns:pSListColumns},(state)=>{
1269
- this.setState({...state,sectionListColumns:pSListColumns},()=>{
1270
- this.setIsLoading(false,false);
1271
- this.setSessionData("sectionListColumns",Object.keys(pSListColumns));
1281
+ setTimeout(()=>{
1282
+ const {sectionListColumns:pSListColumns} = this.prepareColumns({sectionListColumns});
1283
+ this.setIsLoading(true,()=>{
1284
+ this.prepareData({data:this.INITIAL_STATE.data,sectionListColumns:pSListColumns},(state)=>{
1285
+ this.setState({...state,sectionListColumns:pSListColumns},()=>{
1286
+ this.setIsLoading(false,false);
1287
+ this.setSessionData("sectionListColumns",Object.keys(pSListColumns));
1288
+ });
1272
1289
  });
1273
- });
1274
- },true);
1290
+ },true);
1291
+ },TIMEOUT);
1275
1292
  }
1276
1293
  removeAllColumnsInSectionList(){
1277
1294
  const {sectionListColumns} = this.prepareColumns({sectionListColumns:{}});
@@ -1340,6 +1357,18 @@ export default class CommonDatagridComponent extends AppComponent {
1340
1357
  }
1341
1358
  return this.aggregatorFunctions[Object.keys(this.aggregatorFunctions)[0]];
1342
1359
  }
1360
+ toggleAbreviateValues(resetData){
1361
+ setTimeout(()=>{
1362
+ this.setIsLoading(true,()=>{
1363
+ const abreviateValues = !this.state.abreviateValues;
1364
+ const state = resetData ===true ? {data : [...this.state.data]} : {};
1365
+ this.setState({abreviateValues,...state},()=>{
1366
+ this.setIsLoading(false,false);
1367
+ this.setSessionData("abreviateValues",abreviateValues);
1368
+ })
1369
+ },true);
1370
+ },TIMEOUT);
1371
+ }
1343
1372
  /**** récupère l'item de menu permettant lié à la sélection de la fonction d'aggggrégation */
1344
1373
  getAggregatorFunctionsMenuItems(withDivider){
1345
1374
  if(!this.hasFootersFields()) return [];
@@ -1355,6 +1384,8 @@ export default class CommonDatagridComponent extends AppComponent {
1355
1384
  }
1356
1385
  })
1357
1386
  });
1387
+ m.push({divider:true});
1388
+ m.push({text:"Abréger les valeurs numériques",textBold:!!this.state.abreviateValues,icon:this.state.abreviateValues?'check':null,onPress:this.toggleAbreviateValues.bind(this)})
1358
1389
  if(m.length){
1359
1390
  m.unshift({
1360
1391
  text : "Fonctions d'aggrégation",
@@ -1373,15 +1404,24 @@ export default class CommonDatagridComponent extends AppComponent {
1373
1404
  }
1374
1405
  toggleActiveAggregatorFunction(ag){
1375
1406
  if(!isValidAggregator(ag) || ag.code == this.state.aggregatorFunction) return null;
1376
- this.setIsLoading(true,()=>{
1377
- this.prepareData({data:this.INITIAL_STATE.data,aggregatorFunction:ag.code},(state)=>{
1378
- this.setState(state,()=>{
1379
- this.setSessionData("aggregatorFunction",ag.code);
1380
- this.setIsLoading(false,false);
1407
+ setTimeout(()=>{
1408
+ this.setIsLoading(true,()=>{
1409
+ this.prepareData({data:this.INITIAL_STATE.data,aggregatorFunction:ag.code},(state)=>{
1410
+ this.setState(state,()=>{
1411
+ this.setSessionData("aggregatorFunction",ag.code);
1412
+ this.setIsLoading(false,false);
1413
+ })
1381
1414
  })
1382
- })
1383
- },true);
1415
+ },true);
1416
+ },TIMEOUT);
1384
1417
  }
1418
+ formatValue(value,format){
1419
+ if(typeof value !='number') return value;
1420
+ if(format && typeof format =='string' && format.toLowerCase() =='money'){
1421
+ return this.state.abreviateValues? value.abreviate2FormatMoney() : value.formatMoney();
1422
+ }
1423
+ return this.state.abreviateValues ? value.abreviate() : value.formatNumber();
1424
+ }
1385
1425
  renderAggregatorFunctionsMenu(){
1386
1426
  const m = this.getAggregatorFunctionsMenuItems(false,false);
1387
1427
  if(!m.length) return null;
@@ -1894,7 +1934,7 @@ export default class CommonDatagridComponent extends AppComponent {
1894
1934
  chartProps[settingKey][key] = config[key];
1895
1935
  });
1896
1936
  const mappedColumns = {};
1897
- const abreviateValues = defaultVal(config.abreviateValues,true);
1937
+ const abreviateValues = defaultVal(config.abreviateValues,true) || this.state.abreviateValues;
1898
1938
  const dataLabelFormatter = typeof chartProps.dataLabels?.formatter =="function"? chartProps.dataLabels.formatter : undefined;
1899
1939
  const chartOptions = {
1900
1940
  ...chartProps,
@@ -1906,18 +1946,11 @@ export default class CommonDatagridComponent extends AppComponent {
1906
1946
  if((column) && column.field){
1907
1947
  mappedColumns[seriesIndex] = column;
1908
1948
  }
1909
- /*if(value>=660 && value < 661){
1910
- console.log(value," will format ",column,seriesIndex,serieName)
1911
- }*/
1912
1949
  const columnField = defaultStr(column.field, isDonut? config.y : undefined);
1913
1950
  if(dataLabelFormatter){
1914
1951
  return dataLabelFormatter({value,column,columnDef:column,columnField,serie,serieName,seriesIndex})
1915
1952
  }
1916
- if(typeof value !=='number') return value;
1917
- if(defaultStr(column.format).toLowerCase() ==='money'){
1918
- return abreviateValues ? value.abreviate2FormatMoney() : value.formatMoney();
1919
- }
1920
- return abreviateValues ? value.abreviate() : value.formatNumber();
1953
+ return this.formatValue(value,column.format);
1921
1954
  }
1922
1955
  }),
1923
1956
  title :extendObj(true,{}, {
@@ -1976,11 +2009,8 @@ export default class CommonDatagridComponent extends AppComponent {
1976
2009
  }
1977
2010
  }
1978
2011
  yLabels.formatter = (value)=>{
1979
- if(typeof value !='number') return value;
1980
- if((yLabelFormat =='money' || (isDonut && yAxisColumn.format =="money")) || (yLabelsColumn && yLabelsColumn.format =='money')){
1981
- return abreviateValues ? value.abreviate2FormatMoney() : value.formatMoney();
1982
- }
1983
- return abreviateValues? value.abreviate() : value.formatNumber();
2012
+ const format = (yLabelFormat =='money' || (isDonut && yAxisColumn.format =="money")) || (yLabelsColumn && yLabelsColumn.format =='money') ? 'money' : '';
2013
+ return this.formatValue(value,format);
1984
2014
  }
1985
2015
  chartOptions.chart.id = this.chartIdPrefix+"-"+defaultStr(chartType.key,"no-key");
1986
2016
  if(!chartType.isDonut){
@@ -2563,6 +2593,7 @@ export default class CommonDatagridComponent extends AppComponent {
2563
2593
  key = {key2}
2564
2594
  testID={testID+"_FooterItem_"+key2}
2565
2595
  {...footer}
2596
+ abreviate = {this.state.abreviateValues}
2566
2597
  aggregatorFunction = {this.getActiveAggregatorFunction().code}
2567
2598
  aggregatorFunctions = {this.aggregatorFunctions}
2568
2599
  displayLabel = {false}
@@ -2573,7 +2604,7 @@ export default class CommonDatagridComponent extends AppComponent {
2573
2604
  });
2574
2605
  }
2575
2606
  }
2576
- return <View testID={testID+"_ContentContainer"} style={[theme.styles.w100,isA && this.state.displayOnlySectionListHeaders && {borderTopColor:theme.colors.divider,borderTopWidth:1},isA ? [theme.styles.ph2,theme.styles.pt1] : theme.styles.pt1,theme.styles.justifyContentCenter,theme.styles.alignItemsCenter,theme.styles.pb1,!cells && theme.styles.ml1,theme.styles.mr1,cStyle]}>
2607
+ return <View testID={testID+"_ContentContainer"} style={[theme.styles.w100,isA && this.state.displayOnlySectionListHeaders && {borderTopColor:theme.colors.divider,borderTopWidth:1},isA ? [theme.styles.ph2,theme.styles.pt1] : [theme.styles.pt1,theme.styles.ph1],theme.styles.justifyContentCenter,theme.styles.alignItemsCenter,theme.styles.pb1,!cells && theme.styles.ml1,theme.styles.mr1,cStyle]}>
2577
2608
  <Label testID={testID+"_Label"} splitText numberOfLines={3} textBold style={[theme.styles.w100,{color:theme.colors.primaryOnSurface,fontSize:isA?15 :16},lStyle]}>{label}</Label>
2578
2609
  {cells ? <View testID={testID+"_TableRow"} style = {[theme.styles.w100,theme.styles.row,isA && theme.styles.pt1,theme.styles.alignItemsFlexStart]}
2579
2610
  >{cells}</View> : null}
@@ -3189,6 +3220,7 @@ export default class CommonDatagridComponent extends AppComponent {
3189
3220
  const renderText = isSectionListHeader === true || customRenderRowCell === false ? true : false;
3190
3221
  rowIndex = isDecimal(rowIndex)? rowIndex : isDecimal(index)? index : undefined;
3191
3222
  rowCounterIndex = isDecimal(rowCounterIndex) ? rowCounterIndex : isDecimal(rowIndex)? rowIndex+1 : defaultDecimal(rowCounterIndex);
3223
+ const abreviate = this.state.abreviateValues;
3192
3224
  if(!isObj(rowData)) return renderText ? null : {render:null,extra:{}};
3193
3225
  let _render = null;
3194
3226
  columnDef = defaultObj(columnDef);
@@ -3317,14 +3349,7 @@ export default class CommonDatagridComponent extends AppComponent {
3317
3349
  if(isFunction(renderProps)){
3318
3350
  renderProps = renderProps.call(this,renderArgs);
3319
3351
  }
3320
- if(isDecimal(_render)){
3321
- let fmat = defaultStr(columnDef.format).toLowerCase();
3322
- if(fmat == "money"){
3323
- _render = _render.formatMoney();
3324
- } else //if(fmat =="number") {
3325
- _render = _render.formatNumber();
3326
- //}
3327
- }
3352
+ _render = this.formatValue(_render,columnDef.format);
3328
3353
  if(!renderText && _render && isObj(renderProps)){
3329
3354
  let Component = defaultVal(renderProps.Component,Label);
3330
3355
  delete renderProps.Component;
@@ -3572,6 +3597,7 @@ CommonDatagridComponent.propTypes = {
3572
3597
  /*** permet de faire une mutation sur les options de la recherche, immédiatement avant le lancement de la recherche */
3573
3598
  fetchOptionsMutator : PropTypes.func,
3574
3599
  useLinesProgressBar : PropTypes.bool,//si le progress bar lignes horizontale seront utilisés
3600
+ abreviateValues : PropTypes.bool, //si les valeurs numériques seront abregées
3575
3601
  }
3576
3602
 
3577
3603
  const styles = StyleSheet.create({
@@ -79,11 +79,17 @@ const loopForAggregator = (aggregatorFunctions,result)=>{
79
79
  result[aggregatorObj.code] = aggregatorObj;
80
80
  });
81
81
  }
82
- const formatValue = ({value,format,aggregatorFunction})=>{
83
- return (format === 'money' && aggregatorFunction != 'count')? value.formatMoney():value.formatNumber();
82
+ const formatValue = ({value,format,abreviate,aggregatorFunction})=>{
83
+ if((format === 'money' && aggregatorFunction != 'count')){
84
+ if(abreviate){
85
+ return value.abreviate2FormatMoney();
86
+ }
87
+ return value.formatMoney();
88
+ }
89
+ return abreviate? value.abreviate():value.formatNumber();
84
90
  }
85
91
  export default function DGGridFooterValue (props){
86
- let {label,text,displayLabel,withLabel,style,aggregatorFunctions,aggregatorFunction,format,testID,anchorProps} = props;
92
+ let {label,text,displayLabel,withLabel,abreviate,style,aggregatorFunctions,aggregatorFunction,format,testID,anchorProps} = props;
87
93
  aggregatorFunctions = defaultObj(aggregatorFunctions);
88
94
  anchorProps = defaultObj(anchorProps);
89
95
  testID = defaultStr(testID,"RN_DatagridFooterComponent");
@@ -104,7 +110,7 @@ export default function DGGridFooterValue (props){
104
110
  for(let aggregatorFunction in aggregatorFunctions){
105
111
  let val = defaultDecimal(props[aggregatorFunction]);
106
112
  if(isDecimal(val)){
107
- let fText = formatValue({value:val,format,aggregatorFunction});
113
+ let fText = formatValue({value:val,format,abreviate,aggregatorFunction});
108
114
  const mText = defaultStr(aggregatorFunctions[aggregatorFunction].label,aggregatorFunctions[aggregatorFunction].code,aggregatorFunction);
109
115
  title +=(title? ", ":"")+mText +" : "+fText
110
116
  menuItems.push({
@@ -132,7 +138,7 @@ export default function DGGridFooterValue (props){
132
138
  </>
133
139
  : null}
134
140
  <Label testID={testID+"_LabelContent"} primary style={[styles.value]}>
135
- {formatValue({value:defaultDecimal(props[active]),aggregatorFunction:active,format})}
141
+ {formatValue({value:defaultDecimal(props[active]),abreviate,aggregatorFunction:active,format})}
136
142
  </Label>
137
143
  </Pressable>
138
144
  }}
@@ -57,6 +57,7 @@ const DatagridFactory = (Factory)=>{
57
57
  if(isObj(footerFields[columnField])){
58
58
  return <Footer
59
59
  {...defaultObj(footersValues[columnField])}
60
+ abreviate = {this.state.abreviateValues}
60
61
  displayLabel = {false}
61
62
  style = {[style]}
62
63
  aggregatorFunction = {this.getActiveAggregatorFunction().code}
@@ -142,6 +142,7 @@ export default function DatabaseStatisticContainer ({dashboardProps,onRefreshAll
142
142
  if(typeof value !=='number'){
143
143
  value = isObj(footerValue) && typeof footerValue.sum =='number'? footerValue.sum : 0;
144
144
  }
145
+ const formattedValue = typeof context.formatValue =="function"? context.formatValue(value,format) : (format =='money'?value.formatMoney():value.formatNumber());
145
146
  return <Pressable onPress={onPress} testID={testID+"_TitleContainer"} style={[theme.styles.w100]}>
146
147
  <View testID={testID+"_TitleCountUp"} style={[theme.styles.w100]}>
147
148
  <View style={[theme.styles.w100,theme.styles.row,theme.styles.alignItemsCenter]}>
@@ -158,7 +159,7 @@ export default function DatabaseStatisticContainer ({dashboardProps,onRefreshAll
158
159
  <Label
159
160
  textCenter
160
161
  style = {counUpStyle}
161
- >{format =='money'?value.formatMoney():value.formatNumber()}</Label>
162
+ >{formattedValue}</Label>
162
163
  </Pressable>}
163
164
  />
164
165
  </View>