@fto-consult/expo-ui 8.15.3 → 8.16.1
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": "8.
|
3
|
+
"version": "8.16.1",
|
4
4
|
"description": "Bibliothèque de composants UI Expo,react-native",
|
5
5
|
"scripts": {
|
6
6
|
"clear-npx-cache": "npx clear-npx-cache",
|
@@ -71,6 +71,7 @@
|
|
71
71
|
"@emotion/react": "^11.11.1",
|
72
72
|
"@faker-js/faker": "^8.0.2",
|
73
73
|
"@fto-consult/common": "^4.15.57",
|
74
|
+
"@fto-consult/expo-ui": "^8.16.0",
|
74
75
|
"@fto-consult/node-utils": "^1.4.7",
|
75
76
|
"apexcharts": "^3.45.2",
|
76
77
|
"commander": "^11.1.0",
|
@@ -235,10 +235,10 @@ export const renderSelectFieldCell= ({rowData,rowCellValue,columnDef,columnFiel
|
|
235
235
|
}
|
236
236
|
|
237
237
|
export const formatValue = (value,format,abreviateValues,formatter)=>{
|
238
|
-
if(typeof value !='number') return value;
|
239
238
|
if(typeof value =='boolean'){
|
240
239
|
return value ? "Oui" : "Non";
|
241
240
|
}
|
241
|
+
if(typeof value !='number') return value;
|
242
242
|
format = typeof format =='string'? format.toLowerCase().trim() : "";
|
243
243
|
if(typeof formatter =='function'){
|
244
244
|
return formatter({value,format,abreviateValues,abreviate:abreviateValues});
|
@@ -14,6 +14,7 @@ import useApp from "$econtext/hooks";
|
|
14
14
|
import DateLib from "$lib/date";
|
15
15
|
import {useSWR} from "$econtext/hooks";
|
16
16
|
import stableHash from "stable-hash";
|
17
|
+
import {formatValue} from "$ecomponents/Datagrid/Common/utils";
|
17
18
|
|
18
19
|
/*** la tabledataSelectField permet de faire des requêtes distantes pour rechercher les données
|
19
20
|
* Elle doit prendre en paramètre et de manière requis : les props suivante :
|
@@ -21,7 +22,7 @@ import stableHash from "stable-hash";
|
|
21
22
|
* foreignKeyTable : la tableData dans laquelle effectuer les donées de la requêtes
|
22
23
|
* foreignKeyLabel : Le libélé dans la table étrangère
|
23
24
|
*/
|
24
|
-
const TableDataSelectField = React.forwardRef(({foreignKeyColumn,swrOptions,
|
25
|
+
const TableDataSelectField = React.forwardRef(({foreignKeyColumn,swrOptions,onChange,isStructData,getForeignKeyTable:cGetForeignKeyTable,prepareFilters:cPrepareFilters,bindUpsert2RemoveEvents,onAdd,showAdd:customShowAdd,canShowAdd,foreignKeyTable,fetchItemsPath,foreignKeyLabel,foreignKeyLabelIndex,dropdownActions,fields,fetchItems:customFetchItem,parseMangoQueries,mutateFetchedItems,onFetchItems,isFilter,isUpdate,isDocEditing,items:customItems,onAddProps,fetchOptions,...props},ref)=>{
|
25
26
|
props.data = defaultObj(props.data);
|
26
27
|
const type = defaultStr(props.type)?.toLowerCase();
|
27
28
|
isStructData = isStructData || type?.replaceAll("-","").replaceAll("_","").trim().contains("structdata");
|
@@ -124,6 +125,7 @@ const TableDataSelectField = React.forwardRef(({foreignKeyColumn,swrOptions,fore
|
|
124
125
|
const onFetchItemsRef = React.useRef();
|
125
126
|
onFetchItemsRef.current = onFetchItems;
|
126
127
|
const mutateFetchedItemsRef = React.useRef();
|
128
|
+
const fkeyFields = defaultObj(fKeyTable.fields);
|
127
129
|
mutateFetchedItemsRef.current = mutateFetchedItems;
|
128
130
|
const {isLoading:cIsLoading,data:fetchedItems,isValidating,refresh} = useSWR(hasErrors?null:queryPathKey,{
|
129
131
|
fetcher : (url,opts1)=>{
|
@@ -201,39 +203,34 @@ const TableDataSelectField = React.forwardRef(({foreignKeyColumn,swrOptions,fore
|
|
201
203
|
} else {
|
202
204
|
dropdownActions.trefreshItem = refreshItem;
|
203
205
|
}
|
204
|
-
foreignKeyLabelRenderers = defaultObj(foreignKeyLabelRenderers);
|
205
206
|
const rItem = (p)=>{
|
206
207
|
if(!isObj(p) || !isObj(p.item)) return null;
|
207
208
|
let itemLabel = typeof foreignKeyLabel =='function'? foreignKeyLabel(p) : undefined;
|
208
209
|
if(Array.isArray(foreignKeyLabel)){
|
209
|
-
let
|
210
|
+
let labels = "";
|
210
211
|
foreignKeyLabel.map(fk=>{
|
211
212
|
if(!isNonNullString(fk)) return;
|
212
|
-
const
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
itv = t =='money'? itv.formatMoney() : itv.formatNumber();
|
224
|
-
}
|
225
|
-
} else {
|
226
|
-
/***
|
227
|
-
if(typeof itv =='string' && itv && DateLib.isIsoDateStr(itv)){
|
228
|
-
itv = DateLib.format(itv,DateLib.defaultDateFormat);
|
229
|
-
}
|
230
|
-
*/
|
213
|
+
const field = defaultObj(fkeyFields[fk]);
|
214
|
+
const type = defaultStr(field.type,"text").toLowerCase();
|
215
|
+
const format = defaultStr(field.format).toLowerCase();
|
216
|
+
const formatter = typeof field.formatValue =='function' && field.formatValue|| undefined;
|
217
|
+
let value = p.item[fk];
|
218
|
+
if(["date","datetime"].includes(type)){
|
219
|
+
value = DateLib.format(value,type=='date'?DateLib.defaultDateFormat:DateLib.defaultDateTimeFormat);
|
220
|
+
} else if(format && formatter) {
|
221
|
+
const v = formatValue(value,format,false,formatter);
|
222
|
+
if(isNonNullString(v)){
|
223
|
+
value = v;
|
231
224
|
}
|
232
|
-
}
|
233
|
-
|
225
|
+
} else if(typeof value =="number"){
|
226
|
+
if(format =="money"){
|
227
|
+
value = value.formatMoney();
|
228
|
+
} else value = value.formatNumber();
|
229
|
+
}
|
230
|
+
labels+= (labels?" ":"")+ (defaultStr(value))
|
234
231
|
});
|
235
|
-
if(
|
236
|
-
itemLabel =
|
232
|
+
if(labels){
|
233
|
+
itemLabel = labels;
|
237
234
|
}
|
238
235
|
}
|
239
236
|
if(!itemLabel && isNonNullString(foreignKeyLabel)){
|
@@ -310,11 +307,6 @@ const TableDataSelectField = React.forwardRef(({foreignKeyColumn,swrOptions,fore
|
|
310
307
|
TableDataSelectField.propTypes = {
|
311
308
|
...Dropdown.propTypes,
|
312
309
|
swrOptions : PropTypes.object,//les options supplémentaires à passer à la fonction swr
|
313
|
-
/*** permet de faire le mappage entre les foreignKeyLabel et les type correspondants */
|
314
|
-
foreignKeyLabelRenderers : PropTypes.objectOf(PropTypes.oneOfType([
|
315
|
-
PropTypes.string, //représente le type de données associée à la colone dont le nom la clé
|
316
|
-
PropTypes.func, //la fonction utilisée pour le rendu des colonnes de ce type
|
317
|
-
])),
|
318
310
|
prepareFilters : PropTypes.bool,//si les filtres seront customisé
|
319
311
|
bindUpsert2RemoveEvents : PropTypes.bool,//si le composant écoutera l'évènement de rafraichissement des données
|
320
312
|
onAdd : PropTypes.func, //({})=>, la fonction appelée lorsque l'on clique sur le bouton add
|
@@ -54,12 +54,16 @@ const PermLines = React.forwardRef(({user,gridProps,defaultActions:cDefaultActio
|
|
54
54
|
const content = React.useMemo(()=>{
|
55
55
|
const content = [];
|
56
56
|
Object.map(tables,(table,tableName)=>{
|
57
|
-
if(!isObj(table)
|
57
|
+
if(!isObj(table)) return null;
|
58
|
+
const tablePerms = typeof table.perms =="function"? table.perms({user,isMasterAdmin:isUserMasterAdmin,table,tables}) : table.perms;
|
59
|
+
if(!isObj(tablePerms)){
|
60
|
+
return null;
|
61
|
+
}
|
58
62
|
tableName = defaultStr(table.tableName,table.table,tableName).toLowerCase().trim();
|
59
63
|
const text = defaultStr(table.text,table.label)
|
60
64
|
const resource = getTableDataPermResourcePrefix(tableName);
|
61
65
|
const perms = {};
|
62
|
-
Object.map(
|
66
|
+
Object.map(tablePerms,(perm,i)=>{
|
63
67
|
const iLower = i.toLowerCase();
|
64
68
|
if(iLower == 'defaultactions' || iLower =='defaultaction'){
|
65
69
|
perms.defaultActions = perm;
|