@fto-consult/expo-ui 2.18.2 → 2.18.4

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.18.2",
3
+ "version": "2.18.4",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -317,7 +317,7 @@ const DatagridFactory = (Factory)=>{
317
317
  }
318
318
  render (){
319
319
  let {
320
- filters,
320
+ filters:customFilters,
321
321
  filter,
322
322
  actions,
323
323
  sortable,
@@ -396,10 +396,6 @@ const DatagridFactory = (Factory)=>{
396
396
  let exportTableProps = this.getExportableProps();
397
397
 
398
398
  filter = defaultFunc(filter,x=>true);
399
- filters = defaultVal(filters,true);
400
- if(toggleFilters === false){
401
- filters = false;
402
- }
403
399
  let {showFilters,showFooters} = this.state;
404
400
  let max = this.getMaxSelectableRows();
405
401
  let restItems = [];
@@ -429,8 +425,7 @@ const DatagridFactory = (Factory)=>{
429
425
  this.renderedListHeight = Math.max(300,containerHeight - (this.hasScrollViewParent() ? 50:0));
430
426
  const isLoading = this.isLoading();
431
427
  const _progressBar = this.getProgressBar();
432
- const pointerEvents = isLoading || _progressBar ? "none":"auto";
433
-
428
+ const pointerEvents = this.getPointerEvents();
434
429
  const {
435
430
  sortedColumns:sortColumns,
436
431
  sortedColumnsLength,
@@ -486,7 +481,7 @@ const DatagridFactory = (Factory)=>{
486
481
  }}
487
482
  />
488
483
  </View> : null}
489
- {filters !== false ? <View>
484
+ {this.isFilterable() && showFilters ? <View>
490
485
  <FiltersAccordionComponent
491
486
  testID={testID+"_HeaderFilters"}
492
487
  isLoading = {isLoading}
@@ -516,7 +511,7 @@ const DatagridFactory = (Factory)=>{
516
511
  closeOnPress : false,
517
512
  } : null,
518
513
  hasFooterFields ? {
519
- onPress : ()=>{showFooters?this.hideFooter():this.showFooters()}
514
+ onPress : ()=>{this.toggleFooters(!showFooters)}
520
515
  ,icon : showFooters?'view-column':'view-module'
521
516
  ,text : (showFooters?'Masquer/Ligne des totaux':'Afficher/Ligne des totaux')
522
517
  }:null,
@@ -76,11 +76,11 @@ export default class CommonDatagridComponent extends AppComponent {
76
76
  });
77
77
  selectedRows = sRows;
78
78
  let sData = this.getSessionData()
79
- sData.showFooters = defaultVal(sData.showFooters,true);
79
+ sData.showFooters = defaultVal(sData.showFooters,this.isTableData());
80
80
  sData.fixedTable = defaultBool(sData.fixedTable,false);
81
81
  extendObj(this.state, {
82
82
  data,
83
- showFilters : defaultBool(props.showFilters,(sData.showFilter? true : this.isPivotDatagrid())),
83
+ showFilters : this.isFilterable() && defaultBool(props.showFilters,(sData.showFilter? true : this.isPivotDatagrid())) || false,
84
84
  showFooters : defaultBool(props.showFooters,(sData.showFooters? true : false)),
85
85
  fixedTable : sData.fixedTable
86
86
  });
@@ -116,6 +116,7 @@ export default class CommonDatagridComponent extends AppComponent {
116
116
  hasFoundSectionData : {value : {current: false}},
117
117
  sectionListHeaderFooters : {value : {}},
118
118
  sectionListDataSize : {value : {current : 0}},
119
+ enablePointerEventsRef : {value : {current:false}},
119
120
  sectionListColumnsSize : {value : {current:0}}, //la taille du nombre d'éléments de section dans les colonnes
120
121
  })
121
122
  this.isLoading = this.isLoading.bind(this);
@@ -874,9 +875,11 @@ export default class CommonDatagridComponent extends AppComponent {
874
875
  value = defaultDecimal(value);
875
876
  this.handlePagination(0, value, 1);
876
877
  };
877
-
878
+ isFilterable(){
879
+ return this.props.filterable !== false && this.props.filters !== false ? true : false;
880
+ }
878
881
  showFilters(){
879
- if(!this._isMounted()) {
882
+ if(!this._isMounted() || !this.isFilterable()) {
880
883
  this.isUpdating = false;
881
884
  return;
882
885
  }
@@ -888,7 +891,7 @@ export default class CommonDatagridComponent extends AppComponent {
888
891
  })
889
892
  }
890
893
  hideFilters (){
891
- if(!this._isMounted()) {
894
+ if(!this._isMounted() || !this.isFilterable()) {
892
895
  this.isUpdating = false;
893
896
  return;
894
897
  }
@@ -899,33 +902,42 @@ export default class CommonDatagridComponent extends AppComponent {
899
902
  })
900
903
  }
901
904
 
902
-
903
- showFooters(){
905
+ toggleFooters(showOrHide){
906
+ if(typeof showOrHide !=='boolean' || this.state.showFooters === showOrHide) return;
904
907
  if(!this._isMounted()) {
905
908
  this.isUpdating = false;
906
909
  return;
907
910
  }
908
911
  if(this.isUpdating) return false;
909
912
  this.isUpdating = true;
910
- this.setState( {showFooters:true},()=>{
911
- this.isUpdating = false;
912
- this.setSessionData({showFooters:true})
913
- })
913
+ setTimeout(()=>{
914
+ if(this.hasSectionListData() && this.getSectionListDataSize()){
915
+ return this.setIsLoading(true,()=>{
916
+ this.prepareData({data:this.INITIAL_STATE.data},(state)=>{
917
+ this.setState({...state,showFooters:showOrHide},()=>{
918
+ this.setIsLoading(false,false);
919
+ this.isUpdating = false;
920
+ this.setSessionData({showFooters:showOrHide});
921
+ })
922
+ })
923
+ },true)
924
+ }
925
+ this.setState( {showFooters:showOrHide},()=>{
926
+ this.isUpdating = false;
927
+ this.setSessionData({showFooters:showOrHide})
928
+ })
929
+ },200)
930
+ }
931
+ showFooters(){
932
+ return this.toggleFooters(true);
933
+ }
934
+ hideFooters (){
935
+ return this.toggleFooters(false);
914
936
  }
915
937
  setState(a,b){
916
938
  super.setState(a,b);
917
939
  }
918
- hideFooter (){
919
- if(!this._isMounted()) {
920
- this.isUpdating = false;
921
- return;
922
- }
923
- if(this.isUpdating) return false;
924
- this.setState({showFooters:false},()=>{
925
- this.isUpdating = false;
926
- this.setSessionData({showFooters:false});
927
- })
928
- }
940
+
929
941
 
930
942
  toggleFixedTableState(){
931
943
  const fixedTable = !this.state.fixedTable;
@@ -993,19 +1005,23 @@ export default class CommonDatagridComponent extends AppComponent {
993
1005
  sectionListColumns[columnName] = {};
994
1006
  }
995
1007
  const {sectionListColumns:pSListColumns} = this.prepareColumns({sectionListColumns});
996
- this.prepareData({data:this.INITIAL_STATE.data,sectionListColumns:pSListColumns},(state)=>{
997
- this.setState({...state,sectionListColumns:pSListColumns},()=>{
998
- this.setIsLoading(false);
1008
+ this.setIsLoading(true,()=>{
1009
+ this.prepareData({data:this.INITIAL_STATE.data,sectionListColumns:pSListColumns},(state)=>{
1010
+ this.setState({...state,sectionListColumns:pSListColumns},()=>{
1011
+ this.setIsLoading(false,false);
1012
+ });
999
1013
  });
1000
- });
1014
+ },true);
1001
1015
  }
1002
1016
  removeAllColumnsInSectionList(){
1003
1017
  const {sectionListColumns} = this.prepareColumns({sectionListColumns:{}});
1004
- this.prepareData({data:this.INITIAL_STATE.data,sectionListColumns},(state)=>{
1005
- this.setState({...state,sectionListColumns},()=>{
1006
- this.setIsLoading(false);
1018
+ this.setIsLoading(true,()=>{
1019
+ this.prepareData({data:this.INITIAL_STATE.data,sectionListColumns},(state)=>{
1020
+ this.setState({...state,sectionListColumns},()=>{
1021
+ this.setIsLoading(false,false);
1022
+ });
1007
1023
  });
1008
- });
1024
+ },true);
1009
1025
  }
1010
1026
  /*** permet d'effectuer le rendu des colonnes groupable dans le menu item */
1011
1027
  renderSectionListMenu(){
@@ -1470,7 +1486,7 @@ export default class CommonDatagridComponent extends AppComponent {
1470
1486
  }
1471
1487
  }
1472
1488
  return <View testID={testID+"_ContentContainer"} style={[theme.styles.w100,theme.styles,theme.styles.justifyContentCenter,theme.styles.pt1,theme.styles.pb1,theme.styles.alignItemsCenter,!cells && theme.styles.ml1,theme.styles.mr1,cStyle]}>
1473
- <Label testID={testID+"_Label"} splitText numberOfLines={3} textBold style={[theme.styles.w100,lStyle]}>{label}</Label>
1489
+ <Label testID={testID+"_Label"} splitText numberOfLines={3} textBold style={[theme.styles.w100,{color:theme.colors.primaryOnSurface,fontSize:16},lStyle]}>{label}</Label>
1474
1490
  {cells ? <View style = {[theme.styles.w100,theme.styles.row,theme.styles.alignItemsFlexStart]}
1475
1491
  >{cells}</View> : null}
1476
1492
  </View>
@@ -1627,6 +1643,22 @@ export default class CommonDatagridComponent extends AppComponent {
1627
1643
  }
1628
1644
  beforeFetchData(){}
1629
1645
  fetchData({fetchOptions}){
1646
+ if(typeof this.props.fetchData =='function'){
1647
+ const r = this.props.fetchData(fetchOptions);
1648
+ if(isPromise(r)){
1649
+ return r.then((data)=>{
1650
+ if(isObjOrArray(data)){
1651
+ this.setIsLoading(true,()=>{
1652
+ this.prepareData({data},(state)=>{
1653
+ this.setState(state,()=>{
1654
+ this.setIsLoading(false,false);
1655
+ })
1656
+ })
1657
+ },true)
1658
+ }
1659
+ })
1660
+ }
1661
+ }
1630
1662
  return Promise.resolve(this.state.data);
1631
1663
  }
1632
1664
  /**** Filtre le tableau */
@@ -1728,6 +1760,9 @@ export default class CommonDatagridComponent extends AppComponent {
1728
1760
  if(isFunction(cb)){
1729
1761
  cb(data);
1730
1762
  }
1763
+ if(typeof this.props.onRefreshDatagrid ==='function'){
1764
+ this.props.onRefreshDatagrid({context:this,force});
1765
+ }
1731
1766
  })
1732
1767
  }
1733
1768
  onResizePage(){}
@@ -1782,7 +1817,20 @@ export default class CommonDatagridComponent extends AppComponent {
1782
1817
  canSetIsLoading(){
1783
1818
  return isObj(this.progressBarRef.current) && typeof this.progressBarRef.current.setIsLoading =='function' ? true : false;
1784
1819
  }
1785
- setIsLoading(loading,cb){
1820
+ /***
1821
+ * @param {boolean} loading
1822
+ * @param {function | boolean} cb | enablePointerEvents
1823
+ * @param {boolean|function} enablePointerEvents
1824
+ */
1825
+ setIsLoading(loading,cb,enablePointerEvents){
1826
+ if(typeof cb =='boolean'){
1827
+ const t = enablePointerEvents;
1828
+ enablePointerEvents = cb;
1829
+ cb = t;
1830
+ }
1831
+ if(typeof enablePointerEvents =='boolean'){
1832
+ this.enablePointerEventsRef.current = enablePointerEvents;
1833
+ }
1786
1834
  if(this.canSetIsLoading() && typeof loading =='boolean'){
1787
1835
  return this.progressBarRef.current.setIsLoading(loading,()=>{
1788
1836
  if(typeof cb =='function'){
@@ -1839,6 +1887,13 @@ export default class CommonDatagridComponent extends AppComponent {
1839
1887
  layout,
1840
1888
  }
1841
1889
  }
1890
+ getPointerEvents(){
1891
+ if(this.props.isLoading){
1892
+ return "none";
1893
+ }
1894
+ if(this.enablePointerEventsRef.current) return true;
1895
+ return this.isLoading()? "none":"auto";
1896
+ }
1842
1897
  updateLayout(p){
1843
1898
  this.measureLayout(state=>{
1844
1899
  if(isObj(state)){
@@ -1859,9 +1914,13 @@ export default class CommonDatagridComponent extends AppComponent {
1859
1914
  }
1860
1915
  return false;
1861
1916
  }
1862
- this.prepareData({...nextProps,force:true},(state)=>{
1863
- this.setState(state)
1864
- });
1917
+ this.setIsLoading(true,()=>{
1918
+ this.prepareData({...nextProps,force:true},(state)=>{
1919
+ this.setState(state,()=>{
1920
+ this.setIsLoading(false,false);
1921
+ })
1922
+ });
1923
+ },true);
1865
1924
  }
1866
1925
  getDefaultPreloader(props){
1867
1926
  return CommonDatagridComponent.getDefaultPreloader();
@@ -2174,6 +2233,7 @@ CommonDatagridComponent.propTypes = {
2174
2233
  PropTypes.object,
2175
2234
  PropTypes.func,
2176
2235
  ]),
2236
+ filterable : PropTypes.bool, //si le composant peut être filtrable
2177
2237
  /*** si les filtres de données seront convertis au format SQL avant d'effectuer la requête distante */
2178
2238
  convertFiltersToSQL : PropTypes.bool,
2179
2239
  isLoading : PropTypes.bool,///si les données sont en train d'être chargées
@@ -2297,6 +2357,7 @@ CommonDatagridComponent.propTypes = {
2297
2357
  ///pour l'affichage où non des filtres
2298
2358
  toggleFilters : PropTypes.bool,
2299
2359
  desktop: PropTypes.bool,
2360
+ onRefreshDatagrid : PropTypes.func,//lorsque le datagrid est actualisé, rafraichir
2300
2361
  ///les props à apppliquer à l'accordion
2301
2362
  /**** l'accordion peut rendre un objet ou un objet react ou null
2302
2363
  * si c'est un objet, alors il peut être de la forme :
@@ -18,7 +18,7 @@ const DatagridRenderTypeComponent = (props)=>{
18
18
  let type = defaultStr(get(typeKey),isDesk? "fixed":'accordion').toLowerCase().trim();
19
19
  const rTypes = [
20
20
  {...getActiveProps(type,'accordion'),tooltip:"Les éléments de liste s'affichent de manière optimisé pour téléphone mobile",code:'accordion',icon:accordionIcon,label:'Mobile',labelText:'environnement optimisé pour téléphone mobile'},
21
- {...getActiveProps(type,'table'),tooltip:"Les éléments de listes s'affichent dans un tableau rééel",code:'table',icon:tableIcon,label:'Tableau réel avec pagination'}
21
+ //{...getActiveProps(type,'table'),tooltip:"Les éléments de listes s'affichent dans un tableau rééel",code:'table',icon:tableIcon,label:'Tableau réel avec pagination'}
22
22
  ]
23
23
  Object.map(rendersTypes,(t,i)=>{
24
24
  if(isObj(t)){
@@ -1,6 +1,6 @@
1
1
  import { fixedIcon,virtualIcon } from "./utils"
2
2
  export default {
3
- fixed : {
3
+ fixed : false && {
4
4
  code:'fixed',icon:fixedIcon,
5
5
  label:'Tableau virtuel optimisé',
6
6
  desktop:true,
@@ -84,6 +84,7 @@ const SWRDatagridComponent = React.forwardRef((props,ref)=>{
84
84
  testID,
85
85
  autoSort,
86
86
  handleQueryLimit,
87
+ onFetchData,
87
88
  ...rest
88
89
  } = props;
89
90
  rest = defaultObj(rest);
@@ -166,6 +167,9 @@ const SWRDatagridComponent = React.forwardRef((props,ref)=>{
166
167
  */
167
168
  dataRef.current = data;
168
169
  hasResultRef.current = true;
170
+ if(onFetchData && typeof onFetchData =='function'){
171
+ onFetchData({allData:data,total,data,context:innerRef.current})
172
+ }
169
173
  return data;
170
174
  };
171
175
  hasResultRef.current = false;
@@ -82,10 +82,6 @@ const DatagridFactory = (Factory)=>{
82
82
  }
83
83
  return null;
84
84
  }
85
- updateLayout(e){
86
- if(this.state.fixedTable === false) return;
87
- return super.updateLayout(e);
88
- }
89
85
  scrollToEnd(){
90
86
  if(!this.canScrollTo()) return;
91
87
  if(this.listRef.current && this.listRef.current.scrollToEnd){
@@ -163,17 +159,15 @@ const DatagridFactory = (Factory)=>{
163
159
  const {visibleColumns} = this.preparedColumns;
164
160
  const hasFooterFields = this.hasFooterFields();
165
161
  const {columnsWidths:widths,showFilters,showFooters} = this.state;
166
- let isAllRowsSelected = this.isAllRowsSelected();
167
162
  const isLoading = this.isLoading();
168
163
  let _progressBar = this.getProgressBar();
169
- const pointerEvents = isLoading? "none":"auto";
164
+ const pointerEvents = this.getPointerEvents();
170
165
 
171
- let restItems = [];
166
+ let restItems = [...this.renderCustomMenu()];
172
167
  let max = this.getMaxSelectableRows();
173
168
  if(selectableMultiple && max){
174
169
  max = max.formatNumber();
175
170
  restItems = [
176
- ...this.renderCustomMenu(),
177
171
  ...(selectableMultiple ? [{
178
172
  label : "Sélectionner "+max.formatNumber(),
179
173
  icon : "select-all",
@@ -190,7 +184,17 @@ const DatagridFactory = (Factory)=>{
190
184
  }] : [])
191
185
  ]
192
186
  }
193
- const {width,height} = Dimensions.get("window");
187
+ const {width,height:winheight} = Dimensions.get("window");
188
+ const {layout} = this.state;
189
+ let maxHeight = winheight-100;
190
+ if(layout && typeof layout.windowHeight =='number' && layout.windowHeight){
191
+ const diff = winheight - Math.max(defaultNumber(layout.y,layout.top),150);
192
+ if(winheight<=300){
193
+ maxHeight = 300;
194
+ } else {
195
+ maxHeight = diff;
196
+ }
197
+ }
194
198
  const rPagination = showPagination ? <View style={[styles.paginationContainer]}>
195
199
  <ScrollView horizontal showsHorizontalScrollIndicator={!isLoading} style={styles.paginationContainerStyle} contentContainerStyle={styles.minW100}>
196
200
  <View style={[styles.paginationContent]}>
@@ -202,7 +206,7 @@ const DatagridFactory = (Factory)=>{
202
206
  <Button normal style={[styles.paginationItem]} icon = {"refresh"} onPress = {this.refresh.bind(this)}>
203
207
  Rafraichir
204
208
  </Button>
205
- {filters !== false && (
209
+ {this.isFilterable() && (
206
210
  <Button
207
211
  normal
208
212
  style={styles.paginationItem}
@@ -215,7 +219,7 @@ const DatagridFactory = (Factory)=>{
215
219
  {hasFooterFields ? <Button
216
220
  normal
217
221
  style={styles.paginationItem}
218
- onPress = {()=>{showFooters?this.hideFooter():this.showFooters()} }
222
+ onPress = {()=>{this.toggleFooters(!showFooters)} }
219
223
  icon = {showFooters?'view-column':'view-module'}
220
224
  >
221
225
  {showFooters?'Masquer/Ligne des totaux':'Afficher/Ligne des totaux'}
@@ -265,13 +269,13 @@ const DatagridFactory = (Factory)=>{
265
269
  closeOnPress : false,
266
270
  items : visibleColumns
267
271
  },
268
- isMobile && filters !== false?{
272
+ isMobile && this.isFilterable() ?{
269
273
  onPress : ()=>{showFilters?this.hideFilters():this.showFilters()}
270
274
  ,icon : showFilters?'eye-off':'eye'
271
275
  ,text : (showFilters?'Masquer/Filtres':'Afficher/Filtres')
272
276
  } : null,
273
277
  isMobile && hasFooterFields?{
274
- onPress : ()=>{showFooters?this.hideFooter():this.showFooters()}
278
+ onPress : ()=>{this.toggleFooters(!showFooters)}
275
279
  ,icon : showFooters?'view-column':'view-module'
276
280
  ,text : (showFooters?'Masquer/Ligne des totaux':'Afficher/Ligne des totaux')
277
281
  } : null,
@@ -308,7 +312,7 @@ const DatagridFactory = (Factory)=>{
308
312
  </View>
309
313
  </ScrollView>
310
314
  </View> : null;
311
- return <View style={[styles.container,{maxHeight:height-100}]} pointerEvents={pointerEvents}>
315
+ return <View style={[styles.container,{maxHeight}]} pointerEvents={pointerEvents}>
312
316
  <View ref={this.layoutRef}>
313
317
  {this.props.showActions !== false ? <DatagridActions
314
318
  pointerEvents = {pointerEvents}
@@ -324,6 +328,12 @@ const DatagridFactory = (Factory)=>{
324
328
  <Table
325
329
  ref = {this.listRef}
326
330
  {...rest}
331
+ onLayout = {(args)=>{
332
+ if(rest.onLayout){
333
+ rest.onLayout(args);
334
+ }
335
+ this.updateLayout(args);
336
+ }}
327
337
  getItemType = {this.getFlashListItemType.bind(this)}
328
338
  renderItem = {this.renderFlashListItem.bind(this)}
329
339
  hasFooters = {hasFooterFields}
@@ -12,8 +12,8 @@ const FlashListComponent = React.forwardRef((props,ref)=>{
12
12
  ListHeaderComponent={() => (
13
13
  <View testID={(testID||'RN_FlashListComponent')+"_Header"}>{props.children}</View>
14
14
  )}
15
- disableAutoLayout
16
- disableHorizontalListHeightMeasurement = {props.horizontal?undefined : true}
15
+ //disableAutoLayout
16
+ //disableHorizontalListHeightMeasurement = {props.horizontal?undefined : true}
17
17
  {...props}
18
18
  contentContainerStyle = {undefined}
19
19
  style = {undefined}
@@ -250,9 +250,13 @@ const TableComponent = React.forwardRef(({containerProps,renderEmpty,renderItem,
250
250
  absoluteScrollViewRef.current.checkVisibility(nativeEvent);
251
251
  }
252
252
  })}
253
- onLayout={({nativeEvent:{layout}}) => {
253
+ onLayout={(args) => {
254
+ const {nativeEvent:{layout}} = args;
254
255
  scrollViewLayoutRef.current.layout = layout;
255
256
  toggleAbsoluteScrollVisible();
257
+ if(typeof props.onContainerLayout =='function'){
258
+ props.onContainerLayout(args);
259
+ }
256
260
  }}
257
261
  ref={scrollViewRef}
258
262
  testID={testID+"_ScrollView"}