@fto-consult/expo-ui 8.74.0 → 8.75.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.
@@ -46,6 +46,7 @@ import ActivityIndicator from "$ecomponents/ActivityIndicator";
46
46
  import {createTableHeader,fields as pdfFields,pageHeaderMargin,sprintf as pdfSprintf} from "$cpdf";
47
47
  import {isWeb,isMobileNative} from "$cplatform";
48
48
  import { createPDF,getFields as getPdfFields } from '$expo-ui/pdf';
49
+ import actions from '$cactions';
49
50
 
50
51
  export const TIMEOUT = 100;
51
52
 
@@ -178,13 +179,11 @@ export default class CommonDatagridComponent extends AppComponent {
178
179
  exportToExcelIsAllowed,
179
180
  renderSectionListIsAllowed,
180
181
  checkPerms : customCheckPerms,
182
+ tableName,
183
+ table,
184
+ dataSource,
181
185
  ...rest
182
186
  } = props;
183
- if(this.bindResizeEvents()){
184
- extendObj(this._events,{
185
- SET_DATAGRID_QUERY_LIMIT : this.onSetQueryLimit.bind(this),
186
- });
187
- }
188
187
  if(this.props.resetSessionData === true){
189
188
  this.resetSessionData();
190
189
  }
@@ -230,8 +229,11 @@ export default class CommonDatagridComponent extends AppComponent {
230
229
  Object.map(displayTypes,(t,i)=>{
231
230
  if(t.isChart && !perm) return;
232
231
  allowedDisplayTypes[i] = Object.clone(t);
233
- })
232
+ });
233
+ dataSource = CommonDatagridComponent.getDataSource({...props,dataSource,context:this});
234
+ tableName = defaultStr(tableName,table).toUpperCase();
234
235
  Object.defineProperties(this,{
236
+ tableName : {value:tableName,override:false,writable:false},
235
237
  layoutRef : {
236
238
  value : React.createRef(null),
237
239
  },
@@ -347,6 +349,10 @@ export default class CommonDatagridComponent extends AppComponent {
347
349
  this.setSessionData({selectedDataSources:this.currentDataSources});
348
350
  this.persistDisplayType(this.state.displayType);
349
351
  }
352
+ /*** lorsque la données est modifiée */
353
+ onUpsertData =(arg) =>{
354
+ return this.refresh({force:true,renderProgressBar:false});
355
+ }
350
356
  /*** si l'on peut récuperer à distance, les colonnes seulement visibles */
351
357
  canFetchOnlyVisibleColumns(){
352
358
  return this.isTableData() && this.props.canFetchOnlyVisibleColumns && this.isFilterable() && true || false;
@@ -3595,12 +3601,38 @@ export default class CommonDatagridComponent extends AppComponent {
3595
3601
  }
3596
3602
  componentDidMount(){
3597
3603
  super.componentDidMount();
3604
+ extendObj(this._events,{
3605
+ SET_DATAGRID_QUERY_LIMIT : this.onSetQueryLimit.bind(this),
3606
+ });
3598
3607
  APP.on(APP.EVENTS.SET_DATAGRID_QUERY_LIMIT,this._events.SET_DATAGRID_QUERY_LIMIT);
3608
+ if(isNonNullString(this.tableName)){
3609
+ extendObj(this._events,{
3610
+ onUpsertData : this.onUpsertData.bind(this),
3611
+ });
3612
+ this.onUpsertDataSubscription = APP.on(actions.upsert(this.tableName),this._events.onUpsertData);
3613
+ this.onRemoteDataSubscription = APP.on(actions.remove(this.tableName),this._events.onUpsertData);
3614
+ }
3615
+ if(isNonNullString(this.tableName)){
3616
+ this.fetchData({force:true});
3617
+ }
3599
3618
  }
3600
3619
  componentWillUnmount(){
3601
3620
  super.componentWillUnmount();
3621
+ if(isNonNullString(this.tableName)){
3622
+ if(typeof this.onUpsertDataSubscription?.remove =="function"){
3623
+ this.onUpsertDataSubscription.remove();
3624
+ }
3625
+ if(this._events.onUpsertData){
3626
+ APP.off(actions.upsert(this.tableName),this._events.onUpsertData);
3627
+ APP.off(actions.remove(this.tableName),this._events.onUpsertData);
3628
+ }
3629
+ if(typeof this.onRemoteDataSubscription?.remove =="function"){
3630
+ this.onRemoteDataSubscription.remove();
3631
+ }
3632
+ }
3602
3633
  APP.off(APP.EVENTS.SET_DATAGRID_QUERY_LIMIT,this._events.SET_DATAGRID_QUERY_LIMIT);
3603
3634
  this.clearEvents();
3635
+ this.setSelectedRows();
3604
3636
  }
3605
3637
 
3606
3638
  /*** s'il s'agit d'un datagrid virtualisé, ie à utiliser le composant react-base-table */
@@ -3731,7 +3763,7 @@ export default class CommonDatagridComponent extends AppComponent {
3731
3763
  return "auto";
3732
3764
  }
3733
3765
  isTableData(){
3734
- return false;
3766
+ return isNonNullString(this.tableName);
3735
3767
  }
3736
3768
  UNSAFE_componentWillReceiveProps(nextProps){
3737
3769
  if(false && !React.areEquals(this.props.columns,nextProps.columns)){
@@ -4033,7 +4065,12 @@ CommonDatagridComponent.propTypes = {
4033
4065
  /*** si le pied de page sera affiché */
4034
4066
  showFooters : PropTypes.bool,
4035
4067
  /*** les donnnées peuvent être soient retournées par une fonction, soit par un tableau soit une promesse */
4036
- data : PropTypes.oneOfType([PropTypes.array, PropTypes.func,PropTypes.object]),//.isRequired,
4068
+ data : PropTypes.oneOfType([
4069
+ PropTypes.func,
4070
+ PropTypes.string,
4071
+ PropTypes.object,
4072
+ PropTypes.array,
4073
+ ]),
4037
4074
  /****
4038
4075
  la prop column def contient dans la propriété datagrid, la prop maxItemsToRender, le nombre d'items maximal à rendre pour le composant de type select table data multiple
4039
4076
  la prop column def de la colonne de type number, qui contient dans la prop datagrid, la fonction render doit retourner un nombre pour otenir les valeur léie à ladite colonne
@@ -1,8 +1,4 @@
1
1
  export {default} from "./Common";
2
2
 
3
- export {default as TableData} from "./TableData";
4
-
5
- export {default as factory} from "./factory";
6
-
7
3
  export {default as session} from "./session";
8
4
  export * from "./utils";
@@ -1,4 +1,4 @@
1
- import {TableData} from "../Common";
1
+ import Datagrid from "../Common";
2
2
  import {defaultObj,defaultArray,defaultStr,defaultNumber} from "$cutils";
3
3
  import View from "$ecomponents/View";
4
4
  import { StyleSheet,Dimensions,Pressable } from "react-native";
@@ -9,7 +9,7 @@ import { chartTypes } from "../Common/Common";
9
9
  import theme from "$theme";
10
10
  import FiltersAccordionComponent from "../Accordion/Filters";
11
11
 
12
- export default class DatagridDashboard extends TableData {
12
+ export default class DatagridDashboard extends Datagrid {
13
13
  constructor(props){
14
14
  super(props);
15
15
  Object.map(this.displayTypes,(t,i)=>{
@@ -121,10 +121,9 @@ export default class DatagridDashboard extends TableData {
121
121
  DatagridDashboard.displayName = "DatagridDashboardComponent";
122
122
 
123
123
  DatagridDashboard.propTypes = {
124
- ...defaultObj(TableData.propTypes),
124
+ ...defaultObj(Datagrid.propTypes),
125
125
  }
126
126
 
127
-
128
127
  const styles = StyleSheet.create({
129
128
  paginationContainer : {
130
129
  flexDirection : 'row',
@@ -2,8 +2,8 @@
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
- import Accordion,{ TableData as TableDataAccordion} from "./Accordion";
6
- import Table,{TableData as DatagridTableData} from "./Table";
5
+ import Accordion from "./Accordion";
6
+ import Table from "./Table";
7
7
  import {isDesktopMedia,isMobileMedia} from "$cplatform/dimensions";
8
8
  import {isFunction,defaultVal,defaultStr} from "$cutils";
9
9
  import React from "$react";
@@ -13,18 +13,17 @@ import useExpoUI from "$econtext/hooks";
13
13
 
14
14
  const DatagridMainComponent = React.forwardRef((props,ref)=>{
15
15
  const isDesk = isDesktopMedia();
16
- const isMob = defaultStr(isMobileMedia());
16
+ const isMob = isMobileMedia();
17
17
  const {components:{datagrid}} = useExpoUI();
18
- const isTableData = typeof props.isTableData =='boolean'? props.isTableData : defaultStr(props.tableName,props.table).trim() || typeof props.fetchData ==='function'?true : false;
19
18
  const rType = defaultStr(getRenderType()).toLowerCase().trim();
20
19
  const renderType = defaultStr(rType && ['table','accordion'].includes(rType) ? rType : "",isDesk? "table":'accordion').trim().toLowerCase();
21
20
  const canRenderAccordion = (isFunction(props.accordion) || (isObj(props.accordionProps) && isFunction(props.accordionProps.accordion)) || props.accordion === true);
22
21
  const Component = React.useMemo(()=>{
23
22
  if((renderType == 'accordion' || (renderType !=='table' && isMob)) && canRenderAccordion){
24
- return isTableData ? TableDataAccordion : Accordion;
23
+ return Accordion;
25
24
  }
26
- return isTableData ? DatagridTableData : Table;
27
- },[isTableData,renderType,canRenderAccordion,isMob])
25
+ return Table;
26
+ },[renderType,canRenderAccordion,isMob]);
28
27
  return <Component
29
28
  {...datagrid}
30
29
  {...props}
@@ -37,6 +36,6 @@ export default DatagridMainComponent;
37
36
  DatagridMainComponent.displayName = "DatagridMainComponent";
38
37
 
39
38
  DatagridMainComponent.propTypes = {
40
- ...DatagridTableData.propTypes
39
+ ...Table.propTypes
41
40
  }
42
- DatagridMainComponent.LinesProgressBar = DatagridMainComponent.LineProgressBar = DatagridTableData.LineProgressBar;
41
+ DatagridMainComponent.LinesProgressBar = DatagridMainComponent.LineProgressBar = Table.LineProgressBar;